blob: 581971f71f03fefef98974bf17ff42a21ca2d46a [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300159 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
160
161 return min(source_max, sink_max);
162}
163
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400164/*
165 * The units on the numbers in the next two are... bizarre. Examples will
166 * make it clearer; this one parallels an example in the eDP spec.
167 *
168 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
169 *
170 * 270000 * 1 * 8 / 10 == 216000
171 *
172 * The actual data capacity of that configuration is 2.16Gbit/s, so the
173 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
174 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
175 * 119000. At 18bpp that's 2142000 kilobits per second.
176 *
177 * Thus the strange-looking division by 10 in intel_dp_link_required, to
178 * get the result in decakilobits instead of kilobits.
179 */
180
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181static int
Keith Packardc8982612012-01-25 08:16:25 -0800182intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700183{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400184 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185}
186
187static int
Dave Airliefe27d532010-06-30 11:46:17 +1000188intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189{
190 return (max_link_clock * max_lanes * 8) / 10;
191}
192
Mika Kahola70ec0642016-09-09 14:10:55 +0300193static int
194intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
195{
196 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
197 struct intel_encoder *encoder = &intel_dig_port->base;
198 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
199 int max_dotclk = dev_priv->max_dotclk_freq;
200 int ds_max_dotclk;
201
202 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
203
204 if (type != DP_DS_PORT_TYPE_VGA)
205 return max_dotclk;
206
207 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
208 intel_dp->downstream_ports);
209
210 if (ds_max_dotclk != 0)
211 max_dotclk = min(max_dotclk, ds_max_dotclk);
212
213 return max_dotclk;
214}
215
Navare, Manasi D40dba342016-10-26 16:25:55 -0700216static int
217intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
218{
219 if (intel_dp->num_sink_rates) {
220 *sink_rates = intel_dp->sink_rates;
221 return intel_dp->num_sink_rates;
222 }
223
224 *sink_rates = default_rates;
225
226 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
227}
228
229static int
230intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
231{
232 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
233 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
234 int size;
235
236 if (IS_BROXTON(dev_priv)) {
237 *source_rates = bxt_rates;
238 size = ARRAY_SIZE(bxt_rates);
239 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
240 *source_rates = skl_rates;
241 size = ARRAY_SIZE(skl_rates);
242 } else {
243 *source_rates = default_rates;
244 size = ARRAY_SIZE(default_rates);
245 }
246
247 /* This depends on the fact that 5.4 is last value in the array */
248 if (!intel_dp_source_supports_hbr2(intel_dp))
249 size--;
250
251 return size;
252}
253
254static int intersect_rates(const int *source_rates, int source_len,
255 const int *sink_rates, int sink_len,
256 int *common_rates)
257{
258 int i = 0, j = 0, k = 0;
259
260 while (i < source_len && j < sink_len) {
261 if (source_rates[i] == sink_rates[j]) {
262 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
263 return k;
264 common_rates[k] = source_rates[i];
265 ++k;
266 ++i;
267 ++j;
268 } else if (source_rates[i] < sink_rates[j]) {
269 ++i;
270 } else {
271 ++j;
272 }
273 }
274 return k;
275}
276
277static int intel_dp_common_rates(struct intel_dp *intel_dp,
278 int *common_rates)
279{
280 const int *source_rates, *sink_rates;
281 int source_len, sink_len;
282
283 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
284 source_len = intel_dp_source_rates(intel_dp, &source_rates);
285
286 return intersect_rates(source_rates, source_len,
287 sink_rates, sink_len,
288 common_rates);
289}
290
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000291static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700292intel_dp_mode_valid(struct drm_connector *connector,
293 struct drm_display_mode *mode)
294{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100295 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300296 struct intel_connector *intel_connector = to_intel_connector(connector);
297 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100298 int target_clock = mode->clock;
299 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300300 int max_dotclk;
301
302 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700303
Jani Nikuladd06f902012-10-19 14:51:50 +0300304 if (is_edp(intel_dp) && fixed_mode) {
305 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100306 return MODE_PANEL;
307
Jani Nikuladd06f902012-10-19 14:51:50 +0300308 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100309 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200310
311 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100312 }
313
Ville Syrjälä50fec212015-03-12 17:10:34 +0200314 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300315 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100316
317 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
318 mode_rate = intel_dp_link_required(target_clock, 18);
319
Mika Kahola799487f2016-02-02 15:16:38 +0200320 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200321 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700322
323 if (mode->clock < 10000)
324 return MODE_CLOCK_LOW;
325
Daniel Vetter0af78a22012-05-23 11:30:55 +0200326 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
327 return MODE_H_ILLEGAL;
328
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700329 return MODE_OK;
330}
331
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800332uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700333{
334 int i;
335 uint32_t v = 0;
336
337 if (src_bytes > 4)
338 src_bytes = 4;
339 for (i = 0; i < src_bytes; i++)
340 v |= ((uint32_t) src[i]) << ((3-i) * 8);
341 return v;
342}
343
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000344static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700345{
346 int i;
347 if (dst_bytes > 4)
348 dst_bytes = 4;
349 for (i = 0; i < dst_bytes; i++)
350 dst[i] = src >> ((3-i) * 8);
351}
352
Jani Nikulabf13e812013-09-06 07:40:05 +0300353static void
354intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300355 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300356static void
357intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300358 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300359static void
360intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300361
Ville Syrjälä773538e82014-09-04 14:54:56 +0300362static void pps_lock(struct intel_dp *intel_dp)
363{
364 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
365 struct intel_encoder *encoder = &intel_dig_port->base;
366 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100367 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300368 enum intel_display_power_domain power_domain;
369
370 /*
371 * See vlv_power_sequencer_reset() why we need
372 * a power domain reference here.
373 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100374 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300375 intel_display_power_get(dev_priv, power_domain);
376
377 mutex_lock(&dev_priv->pps_mutex);
378}
379
380static void pps_unlock(struct intel_dp *intel_dp)
381{
382 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
383 struct intel_encoder *encoder = &intel_dig_port->base;
384 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100385 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300386 enum intel_display_power_domain power_domain;
387
388 mutex_unlock(&dev_priv->pps_mutex);
389
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100390 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300391 intel_display_power_put(dev_priv, power_domain);
392}
393
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300394static void
395vlv_power_sequencer_kick(struct intel_dp *intel_dp)
396{
397 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200398 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300399 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300400 bool pll_enabled, release_cl_override = false;
401 enum dpio_phy phy = DPIO_PHY(pipe);
402 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300403 uint32_t DP;
404
405 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
406 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
407 pipe_name(pipe), port_name(intel_dig_port->port)))
408 return;
409
410 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
411 pipe_name(pipe), port_name(intel_dig_port->port));
412
413 /* Preserve the BIOS-computed detected bit. This is
414 * supposed to be read-only.
415 */
416 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
417 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
418 DP |= DP_PORT_WIDTH(1);
419 DP |= DP_LINK_TRAIN_PAT_1;
420
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100421 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300422 DP |= DP_PIPE_SELECT_CHV(pipe);
423 else if (pipe == PIPE_B)
424 DP |= DP_PIPEB_SELECT;
425
Ville Syrjäläd288f652014-10-28 13:20:22 +0200426 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
427
428 /*
429 * The DPLL for the pipe must be enabled for this to work.
430 * So enable temporarily it if it's not already enabled.
431 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300432 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100433 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300434 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
435
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200436 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000437 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
438 DRM_ERROR("Failed to force on pll for pipe %c!\n",
439 pipe_name(pipe));
440 return;
441 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300442 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200443
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300444 /*
445 * Similar magic as in intel_dp_enable_port().
446 * We _must_ do this port enable + disable trick
447 * to make this power seqeuencer lock onto the port.
448 * Otherwise even VDD force bit won't work.
449 */
450 I915_WRITE(intel_dp->output_reg, DP);
451 POSTING_READ(intel_dp->output_reg);
452
453 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
454 POSTING_READ(intel_dp->output_reg);
455
456 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
457 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200458
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300459 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200460 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300461
462 if (release_cl_override)
463 chv_phy_powergate_ch(dev_priv, phy, ch, false);
464 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300465}
466
Jani Nikulabf13e812013-09-06 07:40:05 +0300467static enum pipe
468vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
469{
470 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300471 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100472 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300473 struct intel_encoder *encoder;
474 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300475 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300476
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300477 lockdep_assert_held(&dev_priv->pps_mutex);
478
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300479 /* We should never land here with regular DP ports */
480 WARN_ON(!is_edp(intel_dp));
481
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300482 if (intel_dp->pps_pipe != INVALID_PIPE)
483 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300484
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300485 /*
486 * We don't have power sequencer currently.
487 * Pick one that's not used by other ports.
488 */
Jani Nikula19c80542015-12-16 12:48:16 +0200489 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300490 struct intel_dp *tmp;
491
492 if (encoder->type != INTEL_OUTPUT_EDP)
493 continue;
494
495 tmp = enc_to_intel_dp(&encoder->base);
496
497 if (tmp->pps_pipe != INVALID_PIPE)
498 pipes &= ~(1 << tmp->pps_pipe);
499 }
500
501 /*
502 * Didn't find one. This should not happen since there
503 * are two power sequencers and up to two eDP ports.
504 */
505 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300506 pipe = PIPE_A;
507 else
508 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300509
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300510 vlv_steal_power_sequencer(dev, pipe);
511 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300512
513 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
514 pipe_name(intel_dp->pps_pipe),
515 port_name(intel_dig_port->port));
516
517 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300518 intel_dp_init_panel_power_sequencer(dev, intel_dp);
519 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300520
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300521 /*
522 * Even vdd force doesn't work until we've made
523 * the power sequencer lock in on the port.
524 */
525 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300526
527 return intel_dp->pps_pipe;
528}
529
Imre Deak78597992016-06-16 16:37:20 +0300530static int
531bxt_power_sequencer_idx(struct intel_dp *intel_dp)
532{
533 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
534 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100535 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300536
537 lockdep_assert_held(&dev_priv->pps_mutex);
538
539 /* We should never land here with regular DP ports */
540 WARN_ON(!is_edp(intel_dp));
541
542 /*
543 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
544 * mapping needs to be retrieved from VBT, for now just hard-code to
545 * use instance #0 always.
546 */
547 if (!intel_dp->pps_reset)
548 return 0;
549
550 intel_dp->pps_reset = false;
551
552 /*
553 * Only the HW needs to be reprogrammed, the SW state is fixed and
554 * has been setup during connector init.
555 */
556 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
557
558 return 0;
559}
560
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300561typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
562 enum pipe pipe);
563
564static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
565 enum pipe pipe)
566{
Imre Deak44cb7342016-08-10 14:07:29 +0300567 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300568}
569
570static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
571 enum pipe pipe)
572{
Imre Deak44cb7342016-08-10 14:07:29 +0300573 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300574}
575
576static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
577 enum pipe pipe)
578{
579 return true;
580}
581
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300582static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300583vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
584 enum port port,
585 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300586{
Jani Nikulabf13e812013-09-06 07:40:05 +0300587 enum pipe pipe;
588
Jani Nikulabf13e812013-09-06 07:40:05 +0300589 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300590 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300591 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300592
593 if (port_sel != PANEL_PORT_SELECT_VLV(port))
594 continue;
595
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300596 if (!pipe_check(dev_priv, pipe))
597 continue;
598
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300599 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300600 }
601
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300602 return INVALID_PIPE;
603}
604
605static void
606vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
607{
608 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
609 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100610 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300611 enum port port = intel_dig_port->port;
612
613 lockdep_assert_held(&dev_priv->pps_mutex);
614
615 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300616 /* first pick one where the panel is on */
617 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
618 vlv_pipe_has_pp_on);
619 /* didn't find one? pick one where vdd is on */
620 if (intel_dp->pps_pipe == INVALID_PIPE)
621 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
622 vlv_pipe_has_vdd_on);
623 /* didn't find one? pick one with just the correct port */
624 if (intel_dp->pps_pipe == INVALID_PIPE)
625 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
626 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300627
628 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
629 if (intel_dp->pps_pipe == INVALID_PIPE) {
630 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
631 port_name(port));
632 return;
633 }
634
635 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
636 port_name(port), pipe_name(intel_dp->pps_pipe));
637
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300638 intel_dp_init_panel_power_sequencer(dev, intel_dp);
639 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300640}
641
Imre Deak78597992016-06-16 16:37:20 +0300642void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300643{
Chris Wilson91c8a322016-07-05 10:40:23 +0100644 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300645 struct intel_encoder *encoder;
646
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100647 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100648 !IS_BROXTON(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300649 return;
650
651 /*
652 * We can't grab pps_mutex here due to deadlock with power_domain
653 * mutex when power_domain functions are called while holding pps_mutex.
654 * That also means that in order to use pps_pipe the code needs to
655 * hold both a power domain reference and pps_mutex, and the power domain
656 * reference get/put must be done while _not_ holding pps_mutex.
657 * pps_{lock,unlock}() do these steps in the correct order, so one
658 * should use them always.
659 */
660
Jani Nikula19c80542015-12-16 12:48:16 +0200661 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300662 struct intel_dp *intel_dp;
663
664 if (encoder->type != INTEL_OUTPUT_EDP)
665 continue;
666
667 intel_dp = enc_to_intel_dp(&encoder->base);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100668 if (IS_BROXTON(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300669 intel_dp->pps_reset = true;
670 else
671 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300672 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300673}
674
Imre Deak8e8232d2016-06-16 16:37:21 +0300675struct pps_registers {
676 i915_reg_t pp_ctrl;
677 i915_reg_t pp_stat;
678 i915_reg_t pp_on;
679 i915_reg_t pp_off;
680 i915_reg_t pp_div;
681};
682
683static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
684 struct intel_dp *intel_dp,
685 struct pps_registers *regs)
686{
Imre Deak44cb7342016-08-10 14:07:29 +0300687 int pps_idx = 0;
688
Imre Deak8e8232d2016-06-16 16:37:21 +0300689 memset(regs, 0, sizeof(*regs));
690
Imre Deak44cb7342016-08-10 14:07:29 +0300691 if (IS_BROXTON(dev_priv))
692 pps_idx = bxt_power_sequencer_idx(intel_dp);
693 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
694 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300695
Imre Deak44cb7342016-08-10 14:07:29 +0300696 regs->pp_ctrl = PP_CONTROL(pps_idx);
697 regs->pp_stat = PP_STATUS(pps_idx);
698 regs->pp_on = PP_ON_DELAYS(pps_idx);
699 regs->pp_off = PP_OFF_DELAYS(pps_idx);
700 if (!IS_BROXTON(dev_priv))
701 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300702}
703
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200704static i915_reg_t
705_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300706{
Imre Deak8e8232d2016-06-16 16:37:21 +0300707 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300708
Imre Deak8e8232d2016-06-16 16:37:21 +0300709 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
710 &regs);
711
712 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300713}
714
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200715static i915_reg_t
716_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300717{
Imre Deak8e8232d2016-06-16 16:37:21 +0300718 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300719
Imre Deak8e8232d2016-06-16 16:37:21 +0300720 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
721 &regs);
722
723 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300724}
725
Clint Taylor01527b32014-07-07 13:01:46 -0700726/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
727 This function only applicable when panel PM state is not to be tracked */
728static int edp_notify_handler(struct notifier_block *this, unsigned long code,
729 void *unused)
730{
731 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
732 edp_notifier);
733 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100734 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700735
736 if (!is_edp(intel_dp) || code != SYS_RESTART)
737 return 0;
738
Ville Syrjälä773538e82014-09-04 14:54:56 +0300739 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300740
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100741 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300742 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200743 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300744 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300745
Imre Deak44cb7342016-08-10 14:07:29 +0300746 pp_ctrl_reg = PP_CONTROL(pipe);
747 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700748 pp_div = I915_READ(pp_div_reg);
749 pp_div &= PP_REFERENCE_DIVIDER_MASK;
750
751 /* 0x1F write to PP_DIV_REG sets max cycle delay */
752 I915_WRITE(pp_div_reg, pp_div | 0x1F);
753 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
754 msleep(intel_dp->panel_power_cycle_delay);
755 }
756
Ville Syrjälä773538e82014-09-04 14:54:56 +0300757 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300758
Clint Taylor01527b32014-07-07 13:01:46 -0700759 return 0;
760}
761
Daniel Vetter4be73782014-01-17 14:39:48 +0100762static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700763{
Paulo Zanoni30add222012-10-26 19:05:45 -0200764 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100765 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700766
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300767 lockdep_assert_held(&dev_priv->pps_mutex);
768
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100769 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300770 intel_dp->pps_pipe == INVALID_PIPE)
771 return false;
772
Jani Nikulabf13e812013-09-06 07:40:05 +0300773 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700774}
775
Daniel Vetter4be73782014-01-17 14:39:48 +0100776static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700777{
Paulo Zanoni30add222012-10-26 19:05:45 -0200778 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100779 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700780
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300781 lockdep_assert_held(&dev_priv->pps_mutex);
782
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100783 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300784 intel_dp->pps_pipe == INVALID_PIPE)
785 return false;
786
Ville Syrjälä773538e82014-09-04 14:54:56 +0300787 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700788}
789
Keith Packard9b984da2011-09-19 13:54:47 -0700790static void
791intel_dp_check_edp(struct intel_dp *intel_dp)
792{
Paulo Zanoni30add222012-10-26 19:05:45 -0200793 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100794 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700795
Keith Packard9b984da2011-09-19 13:54:47 -0700796 if (!is_edp(intel_dp))
797 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700798
Daniel Vetter4be73782014-01-17 14:39:48 +0100799 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700800 WARN(1, "eDP powered off while attempting aux channel communication.\n");
801 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300802 I915_READ(_pp_stat_reg(intel_dp)),
803 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700804 }
805}
806
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100807static uint32_t
808intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
809{
810 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
811 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100812 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200813 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100814 uint32_t status;
815 bool done;
816
Daniel Vetteref04f002012-12-01 21:03:59 +0100817#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100818 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300819 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300820 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100821 else
Imre Deak713a6b662016-06-28 13:37:33 +0300822 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100823 if (!done)
824 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
825 has_aux_irq);
826#undef C
827
828 return status;
829}
830
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200831static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000832{
833 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200834 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000835
Ville Syrjäläa457f542016-03-02 17:22:17 +0200836 if (index)
837 return 0;
838
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000839 /*
840 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200841 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000842 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200843 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000844}
845
846static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
847{
848 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200849 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000850
851 if (index)
852 return 0;
853
Ville Syrjäläa457f542016-03-02 17:22:17 +0200854 /*
855 * The clock divider is based off the cdclk or PCH rawclk, and would
856 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
857 * divide by 2000 and use that
858 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200859 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200860 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200861 else
862 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000863}
864
865static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300866{
867 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200868 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300869
Ville Syrjäläa457f542016-03-02 17:22:17 +0200870 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300871 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100872 switch (index) {
873 case 0: return 63;
874 case 1: return 72;
875 default: return 0;
876 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300877 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200878
879 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300880}
881
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000882static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
883{
884 /*
885 * SKL doesn't need us to program the AUX clock divider (Hardware will
886 * derive the clock from CDCLK automatically). We still implement the
887 * get_aux_clock_divider vfunc to plug-in into the existing code.
888 */
889 return index ? 0 : 1;
890}
891
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200892static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
893 bool has_aux_irq,
894 int send_bytes,
895 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000896{
897 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100898 struct drm_i915_private *dev_priv =
899 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000900 uint32_t precharge, timeout;
901
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100902 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000903 precharge = 3;
904 else
905 precharge = 5;
906
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100907 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000908 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
909 else
910 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
911
912 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000913 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000914 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000915 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000916 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000917 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000918 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
919 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000920 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000921}
922
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000923static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
924 bool has_aux_irq,
925 int send_bytes,
926 uint32_t unused)
927{
928 return DP_AUX_CH_CTL_SEND_BUSY |
929 DP_AUX_CH_CTL_DONE |
930 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
931 DP_AUX_CH_CTL_TIME_OUT_ERROR |
932 DP_AUX_CH_CTL_TIME_OUT_1600us |
933 DP_AUX_CH_CTL_RECEIVE_ERROR |
934 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200935 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000936 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
937}
938
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700939static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100940intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200941 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700942 uint8_t *recv, int recv_size)
943{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200944 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +0000945 struct drm_i915_private *dev_priv =
946 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200947 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100948 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100949 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700950 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000951 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +0000952 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +0200953 bool vdd;
954
Ville Syrjälä773538e82014-09-04 14:54:56 +0300955 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300956
Ville Syrjälä72c35002014-08-18 22:16:00 +0300957 /*
958 * We will be called with VDD already enabled for dpcd/edid/oui reads.
959 * In such cases we want to leave VDD enabled and it's up to upper layers
960 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
961 * ourselves.
962 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300963 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100964
965 /* dp aux is extremely sensitive to irq latency, hence request the
966 * lowest possible wakeup latency and so prevent the cpu from going into
967 * deep sleep states.
968 */
969 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700970
Keith Packard9b984da2011-09-19 13:54:47 -0700971 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800972
Jesse Barnes11bee432011-08-01 15:02:20 -0700973 /* Try to wait for any previous AUX channel activity */
974 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100975 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700976 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
977 break;
978 msleep(1);
979 }
980
981 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300982 static u32 last_status = -1;
983 const u32 status = I915_READ(ch_ctl);
984
985 if (status != last_status) {
986 WARN(1, "dp_aux_ch not started status 0x%08x\n",
987 status);
988 last_status = status;
989 }
990
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100991 ret = -EBUSY;
992 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100993 }
994
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300995 /* Only 5 data registers! */
996 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
997 ret = -E2BIG;
998 goto out;
999 }
1000
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001001 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001002 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1003 has_aux_irq,
1004 send_bytes,
1005 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001006
Chris Wilsonbc866252013-07-21 16:00:03 +01001007 /* Must try at least 3 times according to DP spec */
1008 for (try = 0; try < 5; try++) {
1009 /* Load the send data into the aux channel data registers */
1010 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001011 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001012 intel_dp_pack_aux(send + i,
1013 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001014
Chris Wilsonbc866252013-07-21 16:00:03 +01001015 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001016 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001017
Chris Wilsonbc866252013-07-21 16:00:03 +01001018 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001019
Chris Wilsonbc866252013-07-21 16:00:03 +01001020 /* Clear done status and any errors */
1021 I915_WRITE(ch_ctl,
1022 status |
1023 DP_AUX_CH_CTL_DONE |
1024 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1025 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001026
Todd Previte74ebf292015-04-15 08:38:41 -07001027 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001028 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001029
1030 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1031 * 400us delay required for errors and timeouts
1032 * Timeout errors from the HW already meet this
1033 * requirement so skip to next iteration
1034 */
1035 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1036 usleep_range(400, 500);
1037 continue;
1038 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001039 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001040 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001041 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001042 }
1043
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001044 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001045 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001046 ret = -EBUSY;
1047 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001048 }
1049
Jim Bridee058c942015-05-27 10:21:48 -07001050done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001051 /* Check for timeout or receive error.
1052 * Timeouts occur when the sink is not connected
1053 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001054 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001055 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001056 ret = -EIO;
1057 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001058 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001059
1060 /* Timeouts occur when the device isn't connected, so they're
1061 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001062 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001063 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001064 ret = -ETIMEDOUT;
1065 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001066 }
1067
1068 /* Unload any bytes sent back from the other side */
1069 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1070 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001071
1072 /*
1073 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1074 * We have no idea of what happened so we return -EBUSY so
1075 * drm layer takes care for the necessary retries.
1076 */
1077 if (recv_bytes == 0 || recv_bytes > 20) {
1078 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1079 recv_bytes);
1080 /*
1081 * FIXME: This patch was created on top of a series that
1082 * organize the retries at drm level. There EBUSY should
1083 * also take care for 1ms wait before retrying.
1084 * That aux retries re-org is still needed and after that is
1085 * merged we remove this sleep from here.
1086 */
1087 usleep_range(1000, 1500);
1088 ret = -EBUSY;
1089 goto out;
1090 }
1091
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001092 if (recv_bytes > recv_size)
1093 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001094
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001095 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001096 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001097 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001098
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001099 ret = recv_bytes;
1100out:
1101 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1102
Jani Nikula884f19e2014-03-14 16:51:14 +02001103 if (vdd)
1104 edp_panel_vdd_off(intel_dp, false);
1105
Ville Syrjälä773538e82014-09-04 14:54:56 +03001106 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001107
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001108 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001109}
1110
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001111#define BARE_ADDRESS_SIZE 3
1112#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001113static ssize_t
1114intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001115{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001116 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1117 uint8_t txbuf[20], rxbuf[20];
1118 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001119 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001120
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001121 txbuf[0] = (msg->request << 4) |
1122 ((msg->address >> 16) & 0xf);
1123 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001124 txbuf[2] = msg->address & 0xff;
1125 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001126
Jani Nikula9d1a1032014-03-14 16:51:15 +02001127 switch (msg->request & ~DP_AUX_I2C_MOT) {
1128 case DP_AUX_NATIVE_WRITE:
1129 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001130 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001131 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001132 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001133
Jani Nikula9d1a1032014-03-14 16:51:15 +02001134 if (WARN_ON(txsize > 20))
1135 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001136
Ville Syrjälädd788092016-07-28 17:55:04 +03001137 WARN_ON(!msg->buffer != !msg->size);
1138
Imre Deakd81a67c2016-01-29 14:52:26 +02001139 if (msg->buffer)
1140 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001141
Jani Nikula9d1a1032014-03-14 16:51:15 +02001142 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1143 if (ret > 0) {
1144 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001145
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001146 if (ret > 1) {
1147 /* Number of bytes written in a short write. */
1148 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1149 } else {
1150 /* Return payload size. */
1151 ret = msg->size;
1152 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001153 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001154 break;
1155
1156 case DP_AUX_NATIVE_READ:
1157 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001158 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001159 rxsize = msg->size + 1;
1160
1161 if (WARN_ON(rxsize > 20))
1162 return -E2BIG;
1163
1164 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1165 if (ret > 0) {
1166 msg->reply = rxbuf[0] >> 4;
1167 /*
1168 * Assume happy day, and copy the data. The caller is
1169 * expected to check msg->reply before touching it.
1170 *
1171 * Return payload size.
1172 */
1173 ret--;
1174 memcpy(msg->buffer, rxbuf + 1, ret);
1175 }
1176 break;
1177
1178 default:
1179 ret = -EINVAL;
1180 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001182
Jani Nikula9d1a1032014-03-14 16:51:15 +02001183 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001184}
1185
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001186static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1187 enum port port)
1188{
1189 const struct ddi_vbt_port_info *info =
1190 &dev_priv->vbt.ddi_port_info[port];
1191 enum port aux_port;
1192
1193 if (!info->alternate_aux_channel) {
1194 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1195 port_name(port), port_name(port));
1196 return port;
1197 }
1198
1199 switch (info->alternate_aux_channel) {
1200 case DP_AUX_A:
1201 aux_port = PORT_A;
1202 break;
1203 case DP_AUX_B:
1204 aux_port = PORT_B;
1205 break;
1206 case DP_AUX_C:
1207 aux_port = PORT_C;
1208 break;
1209 case DP_AUX_D:
1210 aux_port = PORT_D;
1211 break;
1212 default:
1213 MISSING_CASE(info->alternate_aux_channel);
1214 aux_port = PORT_A;
1215 break;
1216 }
1217
1218 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1219 port_name(aux_port), port_name(port));
1220
1221 return aux_port;
1222}
1223
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001224static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001225 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001226{
1227 switch (port) {
1228 case PORT_B:
1229 case PORT_C:
1230 case PORT_D:
1231 return DP_AUX_CH_CTL(port);
1232 default:
1233 MISSING_CASE(port);
1234 return DP_AUX_CH_CTL(PORT_B);
1235 }
1236}
1237
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001238static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001239 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001240{
1241 switch (port) {
1242 case PORT_B:
1243 case PORT_C:
1244 case PORT_D:
1245 return DP_AUX_CH_DATA(port, index);
1246 default:
1247 MISSING_CASE(port);
1248 return DP_AUX_CH_DATA(PORT_B, index);
1249 }
1250}
1251
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001252static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001253 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001254{
1255 switch (port) {
1256 case PORT_A:
1257 return DP_AUX_CH_CTL(port);
1258 case PORT_B:
1259 case PORT_C:
1260 case PORT_D:
1261 return PCH_DP_AUX_CH_CTL(port);
1262 default:
1263 MISSING_CASE(port);
1264 return DP_AUX_CH_CTL(PORT_A);
1265 }
1266}
1267
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001268static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001269 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001270{
1271 switch (port) {
1272 case PORT_A:
1273 return DP_AUX_CH_DATA(port, index);
1274 case PORT_B:
1275 case PORT_C:
1276 case PORT_D:
1277 return PCH_DP_AUX_CH_DATA(port, index);
1278 default:
1279 MISSING_CASE(port);
1280 return DP_AUX_CH_DATA(PORT_A, index);
1281 }
1282}
1283
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001284static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001285 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001286{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001287 switch (port) {
1288 case PORT_A:
1289 case PORT_B:
1290 case PORT_C:
1291 case PORT_D:
1292 return DP_AUX_CH_CTL(port);
1293 default:
1294 MISSING_CASE(port);
1295 return DP_AUX_CH_CTL(PORT_A);
1296 }
1297}
1298
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001299static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001300 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001301{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001302 switch (port) {
1303 case PORT_A:
1304 case PORT_B:
1305 case PORT_C:
1306 case PORT_D:
1307 return DP_AUX_CH_DATA(port, index);
1308 default:
1309 MISSING_CASE(port);
1310 return DP_AUX_CH_DATA(PORT_A, index);
1311 }
1312}
1313
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001314static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001315 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001316{
1317 if (INTEL_INFO(dev_priv)->gen >= 9)
1318 return skl_aux_ctl_reg(dev_priv, port);
1319 else if (HAS_PCH_SPLIT(dev_priv))
1320 return ilk_aux_ctl_reg(dev_priv, port);
1321 else
1322 return g4x_aux_ctl_reg(dev_priv, port);
1323}
1324
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001325static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001326 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001327{
1328 if (INTEL_INFO(dev_priv)->gen >= 9)
1329 return skl_aux_data_reg(dev_priv, port, index);
1330 else if (HAS_PCH_SPLIT(dev_priv))
1331 return ilk_aux_data_reg(dev_priv, port, index);
1332 else
1333 return g4x_aux_data_reg(dev_priv, port, index);
1334}
1335
1336static void intel_aux_reg_init(struct intel_dp *intel_dp)
1337{
1338 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001339 enum port port = intel_aux_port(dev_priv,
1340 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001341 int i;
1342
1343 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1344 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1345 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1346}
1347
Jani Nikula9d1a1032014-03-14 16:51:15 +02001348static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001349intel_dp_aux_fini(struct intel_dp *intel_dp)
1350{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001351 kfree(intel_dp->aux.name);
1352}
1353
Chris Wilson7a418e32016-06-24 14:00:14 +01001354static void
Mika Kaholab6339582016-09-09 14:10:52 +03001355intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001356{
Jani Nikula33ad6622014-03-14 16:51:16 +02001357 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1358 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001359
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001360 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001361 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001362
Chris Wilson7a418e32016-06-24 14:00:14 +01001363 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001364 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001365 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001366}
1367
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001368bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301369{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001370 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001371 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001372
Navare, Manasi D577c5432016-09-27 16:36:53 -07001373 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1374 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301375 return true;
1376 else
1377 return false;
1378}
1379
Daniel Vetter0e503382014-07-04 11:26:04 -03001380static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001381intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001382 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001383{
1384 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001385 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001386 const struct dp_link_dpll *divisor = NULL;
1387 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001388
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001389 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001390 divisor = gen4_dpll;
1391 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001392 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001393 divisor = pch_dpll;
1394 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001395 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001396 divisor = chv_dpll;
1397 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001398 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001399 divisor = vlv_dpll;
1400 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001401 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001402
1403 if (divisor && count) {
1404 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001405 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001406 pipe_config->dpll = divisor[i].dpll;
1407 pipe_config->clock_set = true;
1408 break;
1409 }
1410 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001411 }
1412}
1413
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001414static void snprintf_int_array(char *str, size_t len,
1415 const int *array, int nelem)
1416{
1417 int i;
1418
1419 str[0] = '\0';
1420
1421 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001422 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001423 if (r >= len)
1424 return;
1425 str += r;
1426 len -= r;
1427 }
1428}
1429
1430static void intel_dp_print_rates(struct intel_dp *intel_dp)
1431{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001432 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001433 int source_len, sink_len, common_len;
1434 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001435 char str[128]; /* FIXME: too big for stack? */
1436
1437 if ((drm_debug & DRM_UT_KMS) == 0)
1438 return;
1439
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001440 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001441 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1442 DRM_DEBUG_KMS("source rates: %s\n", str);
1443
1444 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1445 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1446 DRM_DEBUG_KMS("sink rates: %s\n", str);
1447
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001448 common_len = intel_dp_common_rates(intel_dp, common_rates);
1449 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1450 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001451}
1452
Imre Deak489375c2016-10-24 19:33:31 +03001453bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001454__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001455{
Imre Deak7b3fc172016-10-25 16:12:39 +03001456 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1457 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001458
Imre Deak7b3fc172016-10-25 16:12:39 +03001459 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1460 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001461}
1462
Imre Deak12a47a422016-10-24 19:33:29 +03001463bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001464{
Imre Deak7b3fc172016-10-25 16:12:39 +03001465 struct intel_dp_desc *desc = &intel_dp->desc;
1466 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1467 DP_OUI_SUPPORT;
1468 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001469
Imre Deak7b3fc172016-10-25 16:12:39 +03001470 if (!__intel_dp_read_desc(intel_dp, desc))
1471 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001472
Imre Deak7b3fc172016-10-25 16:12:39 +03001473 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1474 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1475 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1476 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1477 dev_id_len, desc->device_id,
1478 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1479 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001480
Imre Deak7b3fc172016-10-25 16:12:39 +03001481 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001482}
1483
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001484static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301485{
1486 int i = 0;
1487
1488 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1489 if (find == rates[i])
1490 break;
1491
1492 return i;
1493}
1494
Ville Syrjälä50fec212015-03-12 17:10:34 +02001495int
1496intel_dp_max_link_rate(struct intel_dp *intel_dp)
1497{
1498 int rates[DP_MAX_SUPPORTED_RATES] = {};
1499 int len;
1500
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001501 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001502 if (WARN_ON(len <= 0))
1503 return 162000;
1504
Ville Syrjälä1354f732016-07-28 17:50:45 +03001505 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001506}
1507
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001508int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1509{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001510 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001511}
1512
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001513void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1514 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001515{
1516 if (intel_dp->num_sink_rates) {
1517 *link_bw = 0;
1518 *rate_select =
1519 intel_dp_rate_select(intel_dp, port_clock);
1520 } else {
1521 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1522 *rate_select = 0;
1523 }
1524}
1525
Jani Nikulaf580bea2016-09-15 16:28:52 +03001526static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1527 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001528{
1529 int bpp, bpc;
1530
1531 bpp = pipe_config->pipe_bpp;
1532 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1533
1534 if (bpc > 0)
1535 bpp = min(bpp, 3*bpc);
1536
1537 return bpp;
1538}
1539
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001540bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001541intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001542 struct intel_crtc_state *pipe_config,
1543 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001544{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001545 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001546 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001547 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001548 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001549 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001550 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001551 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001552 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001553 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001554 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001555 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001556 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301557 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001558 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001559 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001560 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1561 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001562 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301563
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001564 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301565
1566 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001567 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301568
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001569 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001570
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001571 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001572 pipe_config->has_pch_encoder = true;
1573
Vandana Kannanf769cd22014-08-05 07:51:22 -07001574 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001575 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001576
Jani Nikuladd06f902012-10-19 14:51:50 +03001577 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1578 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1579 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001580
1581 if (INTEL_INFO(dev)->gen >= 9) {
1582 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001583 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001584 if (ret)
1585 return ret;
1586 }
1587
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001588 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001589 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1590 intel_connector->panel.fitting_mode);
1591 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001592 intel_pch_panel_fitting(intel_crtc, pipe_config,
1593 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001594 }
1595
Daniel Vettercb1793c2012-06-04 18:39:21 +02001596 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001597 return false;
1598
Daniel Vetter083f9562012-04-20 20:23:49 +02001599 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301600 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001601 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001602 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001603
Daniel Vetter36008362013-03-27 00:44:59 +01001604 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1605 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001606 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001607 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301608
1609 /* Get bpp from vbt only for panels that dont have bpp in edid */
1610 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001611 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001612 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001613 dev_priv->vbt.edp.bpp);
1614 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001615 }
1616
Jani Nikula344c5bb2014-09-09 11:25:13 +03001617 /*
1618 * Use the maximum clock and number of lanes the eDP panel
1619 * advertizes being capable of. The panels are generally
1620 * designed to support only a single clock and lane
1621 * configuration, and typically these values correspond to the
1622 * native resolution of the panel.
1623 */
1624 min_lane_count = max_lane_count;
1625 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001626 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001627
Daniel Vetter36008362013-03-27 00:44:59 +01001628 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001629 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1630 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001631
Dave Airliec6930992014-07-14 11:04:39 +10001632 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301633 for (lane_count = min_lane_count;
1634 lane_count <= max_lane_count;
1635 lane_count <<= 1) {
1636
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001637 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001638 link_avail = intel_dp_max_data_rate(link_clock,
1639 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001640
Daniel Vetter36008362013-03-27 00:44:59 +01001641 if (mode_rate <= link_avail) {
1642 goto found;
1643 }
1644 }
1645 }
1646 }
1647
1648 return false;
1649
1650found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001651 if (intel_dp->color_range_auto) {
1652 /*
1653 * See:
1654 * CEA-861-E - 5.1 Default Encoding Parameters
1655 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1656 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001657 pipe_config->limited_color_range =
1658 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1659 } else {
1660 pipe_config->limited_color_range =
1661 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001662 }
1663
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001664 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301665
Daniel Vetter657445f2013-05-04 10:09:18 +02001666 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001667 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001668
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001669 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1670 &link_bw, &rate_select);
1671
1672 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1673 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001674 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001675 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1676 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001677
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001678 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001679 adjusted_mode->crtc_clock,
1680 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001681 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001682
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301683 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301684 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001685 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301686 intel_link_compute_m_n(bpp, lane_count,
1687 intel_connector->panel.downclock_mode->clock,
1688 pipe_config->port_clock,
1689 &pipe_config->dp_m2_n2);
1690 }
1691
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001692 /*
1693 * DPLL0 VCO may need to be adjusted to get the correct
1694 * clock for eDP. This will affect cdclk as well.
1695 */
1696 if (is_edp(intel_dp) &&
1697 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1698 int vco;
1699
1700 switch (pipe_config->port_clock / 2) {
1701 case 108000:
1702 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001703 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001704 break;
1705 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001706 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001707 break;
1708 }
1709
1710 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1711 }
1712
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001713 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001714 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001715
Daniel Vetter36008362013-03-27 00:44:59 +01001716 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001717}
1718
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001719void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001720 int link_rate, uint8_t lane_count,
1721 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001722{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001723 intel_dp->link_rate = link_rate;
1724 intel_dp->lane_count = lane_count;
1725 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001726}
1727
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001728static void intel_dp_prepare(struct intel_encoder *encoder,
1729 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001730{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001731 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001732 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001733 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001734 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001735 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001736 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001737
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001738 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1739 pipe_config->lane_count,
1740 intel_crtc_has_type(pipe_config,
1741 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001742
Keith Packard417e8222011-11-01 19:54:11 -07001743 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001744 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001745 *
1746 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001747 * SNB CPU
1748 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001749 * CPT PCH
1750 *
1751 * IBX PCH and CPU are the same for almost everything,
1752 * except that the CPU DP PLL is configured in this
1753 * register
1754 *
1755 * CPT PCH is quite different, having many bits moved
1756 * to the TRANS_DP_CTL register instead. That
1757 * configuration happens (oddly) in ironlake_pch_enable
1758 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001759
Keith Packard417e8222011-11-01 19:54:11 -07001760 /* Preserve the BIOS-computed detected bit. This is
1761 * supposed to be read-only.
1762 */
1763 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001764
Keith Packard417e8222011-11-01 19:54:11 -07001765 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001766 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001767 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001768
Keith Packard417e8222011-11-01 19:54:11 -07001769 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001770
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001771 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001772 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1773 intel_dp->DP |= DP_SYNC_HS_HIGH;
1774 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1775 intel_dp->DP |= DP_SYNC_VS_HIGH;
1776 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1777
Jani Nikula6aba5b62013-10-04 15:08:10 +03001778 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001779 intel_dp->DP |= DP_ENHANCED_FRAMING;
1780
Daniel Vetter7c62a162013-06-01 17:16:20 +02001781 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001782 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001783 u32 trans_dp;
1784
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001785 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001786
1787 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1788 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1789 trans_dp |= TRANS_DP_ENH_FRAMING;
1790 else
1791 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1792 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001793 } else {
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001794 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001795 !IS_CHERRYVIEW(dev_priv) &&
1796 pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001797 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001798
1799 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1800 intel_dp->DP |= DP_SYNC_HS_HIGH;
1801 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1802 intel_dp->DP |= DP_SYNC_VS_HIGH;
1803 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1804
Jani Nikula6aba5b62013-10-04 15:08:10 +03001805 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001806 intel_dp->DP |= DP_ENHANCED_FRAMING;
1807
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001808 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001809 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001810 else if (crtc->pipe == PIPE_B)
1811 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001812 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001813}
1814
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001815#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1816#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001817
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001818#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1819#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001820
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001821#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1822#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001823
Imre Deakde9c1b62016-06-16 20:01:46 +03001824static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1825 struct intel_dp *intel_dp);
1826
Daniel Vetter4be73782014-01-17 14:39:48 +01001827static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001828 u32 mask,
1829 u32 value)
1830{
Paulo Zanoni30add222012-10-26 19:05:45 -02001831 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001832 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001833 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001834
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001835 lockdep_assert_held(&dev_priv->pps_mutex);
1836
Imre Deakde9c1b62016-06-16 20:01:46 +03001837 intel_pps_verify_state(dev_priv, intel_dp);
1838
Jani Nikulabf13e812013-09-06 07:40:05 +03001839 pp_stat_reg = _pp_stat_reg(intel_dp);
1840 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001841
1842 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001843 mask, value,
1844 I915_READ(pp_stat_reg),
1845 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001846
Chris Wilson9036ff02016-06-30 15:33:09 +01001847 if (intel_wait_for_register(dev_priv,
1848 pp_stat_reg, mask, value,
1849 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001850 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001851 I915_READ(pp_stat_reg),
1852 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001853
1854 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001855}
1856
Daniel Vetter4be73782014-01-17 14:39:48 +01001857static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001858{
1859 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001860 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001861}
1862
Daniel Vetter4be73782014-01-17 14:39:48 +01001863static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001864{
Keith Packardbd943152011-09-18 23:09:52 -07001865 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001866 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001867}
Keith Packardbd943152011-09-18 23:09:52 -07001868
Daniel Vetter4be73782014-01-17 14:39:48 +01001869static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001870{
Abhay Kumard28d4732016-01-22 17:39:04 -08001871 ktime_t panel_power_on_time;
1872 s64 panel_power_off_duration;
1873
Keith Packard99ea7122011-11-01 19:57:50 -07001874 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001875
Abhay Kumard28d4732016-01-22 17:39:04 -08001876 /* take the difference of currrent time and panel power off time
1877 * and then make panel wait for t11_t12 if needed. */
1878 panel_power_on_time = ktime_get_boottime();
1879 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1880
Paulo Zanonidce56b32013-12-19 14:29:40 -02001881 /* When we disable the VDD override bit last we have to do the manual
1882 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001883 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1884 wait_remaining_ms_from_jiffies(jiffies,
1885 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001886
Daniel Vetter4be73782014-01-17 14:39:48 +01001887 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001888}
Keith Packardbd943152011-09-18 23:09:52 -07001889
Daniel Vetter4be73782014-01-17 14:39:48 +01001890static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001891{
1892 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1893 intel_dp->backlight_on_delay);
1894}
1895
Daniel Vetter4be73782014-01-17 14:39:48 +01001896static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001897{
1898 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1899 intel_dp->backlight_off_delay);
1900}
Keith Packard99ea7122011-11-01 19:57:50 -07001901
Keith Packard832dd3c2011-11-01 19:34:06 -07001902/* Read the current pp_control value, unlocking the register if it
1903 * is locked
1904 */
1905
Jesse Barnes453c5422013-03-28 09:55:41 -07001906static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001907{
Jesse Barnes453c5422013-03-28 09:55:41 -07001908 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001909 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001910 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001911
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001912 lockdep_assert_held(&dev_priv->pps_mutex);
1913
Jani Nikulabf13e812013-09-06 07:40:05 +03001914 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001915 if (WARN_ON(!HAS_DDI(dev_priv) &&
1916 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301917 control &= ~PANEL_UNLOCK_MASK;
1918 control |= PANEL_UNLOCK_REGS;
1919 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001920 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001921}
1922
Ville Syrjälä951468f2014-09-04 14:55:31 +03001923/*
1924 * Must be paired with edp_panel_vdd_off().
1925 * Must hold pps_mutex around the whole on/off sequence.
1926 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1927 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001928static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001929{
Paulo Zanoni30add222012-10-26 19:05:45 -02001930 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001931 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1932 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001933 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001934 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001935 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001936 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001937 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001938
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001939 lockdep_assert_held(&dev_priv->pps_mutex);
1940
Keith Packard97af61f572011-09-28 16:23:51 -07001941 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001942 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001943
Egbert Eich2c623c12014-11-25 12:54:57 +01001944 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001945 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001946
Daniel Vetter4be73782014-01-17 14:39:48 +01001947 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001948 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001949
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001950 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001951 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001952
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001953 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1954 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001955
Daniel Vetter4be73782014-01-17 14:39:48 +01001956 if (!edp_have_panel_power(intel_dp))
1957 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001958
Jesse Barnes453c5422013-03-28 09:55:41 -07001959 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001960 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001961
Jani Nikulabf13e812013-09-06 07:40:05 +03001962 pp_stat_reg = _pp_stat_reg(intel_dp);
1963 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001964
1965 I915_WRITE(pp_ctrl_reg, pp);
1966 POSTING_READ(pp_ctrl_reg);
1967 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1968 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001969 /*
1970 * If the panel wasn't on, delay before accessing aux channel
1971 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001972 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001973 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1974 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001975 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001976 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001977
1978 return need_to_disable;
1979}
1980
Ville Syrjälä951468f2014-09-04 14:55:31 +03001981/*
1982 * Must be paired with intel_edp_panel_vdd_off() or
1983 * intel_edp_panel_off().
1984 * Nested calls to these functions are not allowed since
1985 * we drop the lock. Caller must use some higher level
1986 * locking to prevent nested calls from other threads.
1987 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001988void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001989{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001990 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001991
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001992 if (!is_edp(intel_dp))
1993 return;
1994
Ville Syrjälä773538e82014-09-04 14:54:56 +03001995 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001996 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001997 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001998
Rob Clarke2c719b2014-12-15 13:56:32 -05001999 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002000 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002001}
2002
Daniel Vetter4be73782014-01-17 14:39:48 +01002003static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002004{
Paulo Zanoni30add222012-10-26 19:05:45 -02002005 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002006 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002007 struct intel_digital_port *intel_dig_port =
2008 dp_to_dig_port(intel_dp);
2009 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2010 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002011 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002012 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002013
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002014 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002015
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002016 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002017
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002018 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002019 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002020
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002021 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2022 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002023
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002024 pp = ironlake_get_pp_control(intel_dp);
2025 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002026
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002027 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2028 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002029
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002030 I915_WRITE(pp_ctrl_reg, pp);
2031 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002032
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002033 /* Make sure sequencer is idle before allowing subsequent activity */
2034 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2035 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002036
Imre Deak5a162e22016-08-10 14:07:30 +03002037 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002038 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002039
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002040 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002041 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002042}
2043
Daniel Vetter4be73782014-01-17 14:39:48 +01002044static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002045{
2046 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2047 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002048
Ville Syrjälä773538e82014-09-04 14:54:56 +03002049 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002050 if (!intel_dp->want_panel_vdd)
2051 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002052 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002053}
2054
Imre Deakaba86892014-07-30 15:57:31 +03002055static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2056{
2057 unsigned long delay;
2058
2059 /*
2060 * Queue the timer to fire a long time from now (relative to the power
2061 * down delay) to keep the panel power up across a sequence of
2062 * operations.
2063 */
2064 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2065 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2066}
2067
Ville Syrjälä951468f2014-09-04 14:55:31 +03002068/*
2069 * Must be paired with edp_panel_vdd_on().
2070 * Must hold pps_mutex around the whole on/off sequence.
2071 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2072 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002073static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002074{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002075 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002076
2077 lockdep_assert_held(&dev_priv->pps_mutex);
2078
Keith Packard97af61f572011-09-28 16:23:51 -07002079 if (!is_edp(intel_dp))
2080 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002081
Rob Clarke2c719b2014-12-15 13:56:32 -05002082 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002083 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002084
Keith Packardbd943152011-09-18 23:09:52 -07002085 intel_dp->want_panel_vdd = false;
2086
Imre Deakaba86892014-07-30 15:57:31 +03002087 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002088 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002089 else
2090 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002091}
2092
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002093static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002094{
Paulo Zanoni30add222012-10-26 19:05:45 -02002095 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002096 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002097 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002098 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002099
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002100 lockdep_assert_held(&dev_priv->pps_mutex);
2101
Keith Packard97af61f572011-09-28 16:23:51 -07002102 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002103 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002104
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002105 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2106 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002107
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002108 if (WARN(edp_have_panel_power(intel_dp),
2109 "eDP port %c panel power already on\n",
2110 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002111 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002112
Daniel Vetter4be73782014-01-17 14:39:48 +01002113 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002114
Jani Nikulabf13e812013-09-06 07:40:05 +03002115 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002116 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002117 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002118 /* ILK workaround: disable reset around power sequence */
2119 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002120 I915_WRITE(pp_ctrl_reg, pp);
2121 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002122 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002123
Imre Deak5a162e22016-08-10 14:07:30 +03002124 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002125 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002126 pp |= PANEL_POWER_RESET;
2127
Jesse Barnes453c5422013-03-28 09:55:41 -07002128 I915_WRITE(pp_ctrl_reg, pp);
2129 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002130
Daniel Vetter4be73782014-01-17 14:39:48 +01002131 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002132 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002133
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002134 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002135 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002136 I915_WRITE(pp_ctrl_reg, pp);
2137 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002138 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002139}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002140
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002141void intel_edp_panel_on(struct intel_dp *intel_dp)
2142{
2143 if (!is_edp(intel_dp))
2144 return;
2145
2146 pps_lock(intel_dp);
2147 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002148 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002149}
2150
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002151
2152static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002153{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002154 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2155 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002156 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002157 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002158 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002159 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002160 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002161
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002162 lockdep_assert_held(&dev_priv->pps_mutex);
2163
Keith Packard97af61f572011-09-28 16:23:51 -07002164 if (!is_edp(intel_dp))
2165 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002166
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002167 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2168 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002169
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002170 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2171 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002172
Jesse Barnes453c5422013-03-28 09:55:41 -07002173 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002174 /* We need to switch off panel power _and_ force vdd, for otherwise some
2175 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002176 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002177 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002178
Jani Nikulabf13e812013-09-06 07:40:05 +03002179 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002180
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002181 intel_dp->want_panel_vdd = false;
2182
Jesse Barnes453c5422013-03-28 09:55:41 -07002183 I915_WRITE(pp_ctrl_reg, pp);
2184 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002185
Abhay Kumard28d4732016-01-22 17:39:04 -08002186 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002187 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002188
2189 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002190 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002191 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002192}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002193
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002194void intel_edp_panel_off(struct intel_dp *intel_dp)
2195{
2196 if (!is_edp(intel_dp))
2197 return;
2198
2199 pps_lock(intel_dp);
2200 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002201 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002202}
2203
Jani Nikula1250d102014-08-12 17:11:39 +03002204/* Enable backlight in the panel power control. */
2205static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002206{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002207 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2208 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002209 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002210 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002211 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002212
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002213 /*
2214 * If we enable the backlight right away following a panel power
2215 * on, we may see slight flicker as the panel syncs with the eDP
2216 * link. So delay a bit to make sure the image is solid before
2217 * allowing it to appear.
2218 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002219 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002220
Ville Syrjälä773538e82014-09-04 14:54:56 +03002221 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002222
Jesse Barnes453c5422013-03-28 09:55:41 -07002223 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002224 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002225
Jani Nikulabf13e812013-09-06 07:40:05 +03002226 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002227
2228 I915_WRITE(pp_ctrl_reg, pp);
2229 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002230
Ville Syrjälä773538e82014-09-04 14:54:56 +03002231 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002232}
2233
Jani Nikula1250d102014-08-12 17:11:39 +03002234/* Enable backlight PWM and backlight PP control. */
2235void intel_edp_backlight_on(struct intel_dp *intel_dp)
2236{
2237 if (!is_edp(intel_dp))
2238 return;
2239
2240 DRM_DEBUG_KMS("\n");
2241
2242 intel_panel_enable_backlight(intel_dp->attached_connector);
2243 _intel_edp_backlight_on(intel_dp);
2244}
2245
2246/* Disable backlight in the panel power control. */
2247static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002248{
Paulo Zanoni30add222012-10-26 19:05:45 -02002249 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002250 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002251 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002252 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002253
Keith Packardf01eca22011-09-28 16:48:10 -07002254 if (!is_edp(intel_dp))
2255 return;
2256
Ville Syrjälä773538e82014-09-04 14:54:56 +03002257 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002258
Jesse Barnes453c5422013-03-28 09:55:41 -07002259 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002260 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002261
Jani Nikulabf13e812013-09-06 07:40:05 +03002262 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002263
2264 I915_WRITE(pp_ctrl_reg, pp);
2265 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002266
Ville Syrjälä773538e82014-09-04 14:54:56 +03002267 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002268
Paulo Zanonidce56b32013-12-19 14:29:40 -02002269 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002270 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002271}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002272
Jani Nikula1250d102014-08-12 17:11:39 +03002273/* Disable backlight PP control and backlight PWM. */
2274void intel_edp_backlight_off(struct intel_dp *intel_dp)
2275{
2276 if (!is_edp(intel_dp))
2277 return;
2278
2279 DRM_DEBUG_KMS("\n");
2280
2281 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002282 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002283}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002284
Jani Nikula73580fb72014-08-12 17:11:41 +03002285/*
2286 * Hook for controlling the panel power control backlight through the bl_power
2287 * sysfs attribute. Take care to handle multiple calls.
2288 */
2289static void intel_edp_backlight_power(struct intel_connector *connector,
2290 bool enable)
2291{
2292 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002293 bool is_enabled;
2294
Ville Syrjälä773538e82014-09-04 14:54:56 +03002295 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002296 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002297 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002298
2299 if (is_enabled == enable)
2300 return;
2301
Jani Nikula23ba9372014-08-27 14:08:43 +03002302 DRM_DEBUG_KMS("panel power control backlight %s\n",
2303 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002304
2305 if (enable)
2306 _intel_edp_backlight_on(intel_dp);
2307 else
2308 _intel_edp_backlight_off(intel_dp);
2309}
2310
Ville Syrjälä64e10772015-10-29 21:26:01 +02002311static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2312{
2313 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2314 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2315 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2316
2317 I915_STATE_WARN(cur_state != state,
2318 "DP port %c state assertion failure (expected %s, current %s)\n",
2319 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002320 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002321}
2322#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2323
2324static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2325{
2326 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2327
2328 I915_STATE_WARN(cur_state != state,
2329 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002330 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002331}
2332#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2333#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2334
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002335static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2336 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002337{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002338 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002339 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002340
Ville Syrjälä64e10772015-10-29 21:26:01 +02002341 assert_pipe_disabled(dev_priv, crtc->pipe);
2342 assert_dp_port_disabled(intel_dp);
2343 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002344
Ville Syrjäläabfce942015-10-29 21:26:03 +02002345 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002346 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002347
2348 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2349
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002350 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002351 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2352 else
2353 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2354
2355 I915_WRITE(DP_A, intel_dp->DP);
2356 POSTING_READ(DP_A);
2357 udelay(500);
2358
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002359 /*
2360 * [DevILK] Work around required when enabling DP PLL
2361 * while a pipe is enabled going to FDI:
2362 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2363 * 2. Program DP PLL enable
2364 */
2365 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002366 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002367
Daniel Vetter07679352012-09-06 22:15:42 +02002368 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002369
Daniel Vetter07679352012-09-06 22:15:42 +02002370 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002371 POSTING_READ(DP_A);
2372 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002373}
2374
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002375static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002376{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002377 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002378 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2379 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002380
Ville Syrjälä64e10772015-10-29 21:26:01 +02002381 assert_pipe_disabled(dev_priv, crtc->pipe);
2382 assert_dp_port_disabled(intel_dp);
2383 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002384
Ville Syrjäläabfce942015-10-29 21:26:03 +02002385 DRM_DEBUG_KMS("disabling eDP PLL\n");
2386
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002387 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002388
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002389 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002390 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002391 udelay(200);
2392}
2393
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002394/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002395void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002396{
2397 int ret, i;
2398
2399 /* Should have a valid DPCD by this point */
2400 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2401 return;
2402
2403 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002404 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2405 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002406 } else {
2407 /*
2408 * When turning on, we need to retry for 1ms to give the sink
2409 * time to wake up.
2410 */
2411 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002412 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2413 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002414 if (ret == 1)
2415 break;
2416 msleep(1);
2417 }
2418 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002419
2420 if (ret != 1)
2421 DRM_DEBUG_KMS("failed to %s sink power state\n",
2422 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002423}
2424
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002425static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2426 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002427{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002428 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002429 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002430 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002431 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002432 enum intel_display_power_domain power_domain;
2433 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002434 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002435
2436 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002437 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002438 return false;
2439
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002440 ret = false;
2441
Imre Deak6d129be2014-03-05 16:20:54 +02002442 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002443
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002444 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002445 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002446
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002447 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002448 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002449 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002450 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002451
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002452 for_each_pipe(dev_priv, p) {
2453 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2454 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2455 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002456 ret = true;
2457
2458 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002459 }
2460 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002461
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002462 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002463 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002464 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002465 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2466 } else {
2467 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002468 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002469
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002470 ret = true;
2471
2472out:
2473 intel_display_power_put(dev_priv, power_domain);
2474
2475 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002476}
2477
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002478static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002479 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002480{
2481 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002482 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002483 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002484 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002485 enum port port = dp_to_dig_port(intel_dp)->port;
2486 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002487
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002488 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002489
2490 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002491
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002492 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002493 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2494
2495 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002496 flags |= DRM_MODE_FLAG_PHSYNC;
2497 else
2498 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002499
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002500 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002501 flags |= DRM_MODE_FLAG_PVSYNC;
2502 else
2503 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002504 } else {
2505 if (tmp & DP_SYNC_HS_HIGH)
2506 flags |= DRM_MODE_FLAG_PHSYNC;
2507 else
2508 flags |= DRM_MODE_FLAG_NHSYNC;
2509
2510 if (tmp & DP_SYNC_VS_HIGH)
2511 flags |= DRM_MODE_FLAG_PVSYNC;
2512 else
2513 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002514 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002515
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002516 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002517
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002518 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
2519 !IS_CHERRYVIEW(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002520 pipe_config->limited_color_range = true;
2521
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002522 pipe_config->lane_count =
2523 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2524
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002525 intel_dp_get_m_n(crtc, pipe_config);
2526
Ville Syrjälä18442d02013-09-13 16:00:08 +03002527 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002528 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002529 pipe_config->port_clock = 162000;
2530 else
2531 pipe_config->port_clock = 270000;
2532 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002533
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002534 pipe_config->base.adjusted_mode.crtc_clock =
2535 intel_dotclock_calculate(pipe_config->port_clock,
2536 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002537
Jani Nikula6aa23e62016-03-24 17:50:20 +02002538 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2539 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002540 /*
2541 * This is a big fat ugly hack.
2542 *
2543 * Some machines in UEFI boot mode provide us a VBT that has 18
2544 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2545 * unknown we fail to light up. Yet the same BIOS boots up with
2546 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2547 * max, not what it tells us to use.
2548 *
2549 * Note: This will still be broken if the eDP panel is not lit
2550 * up by the BIOS, and thus we can't get the mode at module
2551 * load.
2552 */
2553 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002554 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2555 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002556 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002557}
2558
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002559static void intel_disable_dp(struct intel_encoder *encoder,
2560 struct intel_crtc_state *old_crtc_state,
2561 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002562{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002563 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002564 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002565
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002566 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002567 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002568
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002569 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002570 intel_psr_disable(intel_dp);
2571
Daniel Vetter6cb49832012-05-20 17:14:50 +02002572 /* Make sure the panel is off before trying to change the mode. But also
2573 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002574 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002575 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002576 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002577 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002578
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002579 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002580 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002581 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002582}
2583
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002584static void ilk_post_disable_dp(struct intel_encoder *encoder,
2585 struct intel_crtc_state *old_crtc_state,
2586 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002587{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002588 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002589 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002590
Ville Syrjälä49277c32014-03-31 18:21:26 +03002591 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002592
2593 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002594 if (port == PORT_A)
2595 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002596}
2597
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002598static void vlv_post_disable_dp(struct intel_encoder *encoder,
2599 struct intel_crtc_state *old_crtc_state,
2600 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002601{
2602 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2603
2604 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002605}
2606
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002607static void chv_post_disable_dp(struct intel_encoder *encoder,
2608 struct intel_crtc_state *old_crtc_state,
2609 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002610{
2611 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002612 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002613 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002614
2615 intel_dp_link_down(intel_dp);
2616
Ville Syrjäläa5805162015-05-26 20:42:30 +03002617 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002618
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002619 /* Assert data lane reset */
2620 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002621
Ville Syrjäläa5805162015-05-26 20:42:30 +03002622 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002623}
2624
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002625static void
2626_intel_dp_set_link_train(struct intel_dp *intel_dp,
2627 uint32_t *DP,
2628 uint8_t dp_train_pat)
2629{
2630 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2631 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002632 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002633 enum port port = intel_dig_port->port;
2634
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002635 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2636 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2637 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2638
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002639 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002640 uint32_t temp = I915_READ(DP_TP_CTL(port));
2641
2642 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2643 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2644 else
2645 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2646
2647 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2648 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2649 case DP_TRAINING_PATTERN_DISABLE:
2650 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2651
2652 break;
2653 case DP_TRAINING_PATTERN_1:
2654 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2655 break;
2656 case DP_TRAINING_PATTERN_2:
2657 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2658 break;
2659 case DP_TRAINING_PATTERN_3:
2660 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2661 break;
2662 }
2663 I915_WRITE(DP_TP_CTL(port), temp);
2664
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002665 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002666 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002667 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2668
2669 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2670 case DP_TRAINING_PATTERN_DISABLE:
2671 *DP |= DP_LINK_TRAIN_OFF_CPT;
2672 break;
2673 case DP_TRAINING_PATTERN_1:
2674 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2675 break;
2676 case DP_TRAINING_PATTERN_2:
2677 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2678 break;
2679 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002680 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002681 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2682 break;
2683 }
2684
2685 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002686 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002687 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2688 else
2689 *DP &= ~DP_LINK_TRAIN_MASK;
2690
2691 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2692 case DP_TRAINING_PATTERN_DISABLE:
2693 *DP |= DP_LINK_TRAIN_OFF;
2694 break;
2695 case DP_TRAINING_PATTERN_1:
2696 *DP |= DP_LINK_TRAIN_PAT_1;
2697 break;
2698 case DP_TRAINING_PATTERN_2:
2699 *DP |= DP_LINK_TRAIN_PAT_2;
2700 break;
2701 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002702 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002703 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2704 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002705 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002706 *DP |= DP_LINK_TRAIN_PAT_2;
2707 }
2708 break;
2709 }
2710 }
2711}
2712
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002713static void intel_dp_enable_port(struct intel_dp *intel_dp,
2714 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002715{
2716 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002717 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002718
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002719 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002720
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002721 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002722
2723 /*
2724 * Magic for VLV/CHV. We _must_ first set up the register
2725 * without actually enabling the port, and then do another
2726 * write to enable the port. Otherwise link training will
2727 * fail when the power sequencer is freshly used for this port.
2728 */
2729 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002730 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002731 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002732
2733 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2734 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002735}
2736
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002737static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002738 struct intel_crtc_state *pipe_config,
2739 struct drm_connector_state *conn_state)
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));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002781 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002782 }
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 Lankhorstbbf35e92016-11-08 13:55:38 +01002791 intel_enable_dp(encoder, pipe_config, conn_state);
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 Lankhorstbbf35e92016-11-08 13:55:38 +01002928 intel_enable_dp(encoder, pipe_config, conn_state);
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 Lankhorstbbf35e92016-11-08 13:55:38 +01002946 intel_enable_dp(encoder, pipe_config, conn_state);
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
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003490 intel_wait_for_vblank_if_active(dev_priv, 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);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003670 struct drm_i915_private *dev_priv = to_i915(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 {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003691 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003692
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);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003714 struct drm_i915_private *dev_priv = to_i915(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
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003742 intel_wait_for_vblank(dev_priv, 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);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003749 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003750 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 {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003760 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003761
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 */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003993 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03003994
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}