blob: 6c05a2b38cc79b8c74caf3dd18fcbd425379cb0b [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;
Manasi Navaref4829842016-12-05 16:27:36 -0800159 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300160
161 return min(source_max, sink_max);
162}
163
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800164int
Keith Packardc8982612012-01-25 08:16:25 -0800165intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800167 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
168 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700169}
170
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800171int
Dave Airliefe27d532010-06-30 11:46:17 +1000172intel_dp_max_data_rate(int max_link_clock, int max_lanes)
173{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800174 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
175 * link rate that is generally expressed in Gbps. Since, 8 bits of data
176 * is transmitted every LS_Clk per lane, there is no need to account for
177 * the channel encoding that is done in the PHY layer here.
178 */
179
180 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000181}
182
Mika Kahola70ec0642016-09-09 14:10:55 +0300183static int
184intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
185{
186 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
187 struct intel_encoder *encoder = &intel_dig_port->base;
188 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
189 int max_dotclk = dev_priv->max_dotclk_freq;
190 int ds_max_dotclk;
191
192 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
193
194 if (type != DP_DS_PORT_TYPE_VGA)
195 return max_dotclk;
196
197 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
198 intel_dp->downstream_ports);
199
200 if (ds_max_dotclk != 0)
201 max_dotclk = min(max_dotclk, ds_max_dotclk);
202
203 return max_dotclk;
204}
205
Navare, Manasi D40dba342016-10-26 16:25:55 -0700206static int
207intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
208{
209 if (intel_dp->num_sink_rates) {
210 *sink_rates = intel_dp->sink_rates;
211 return intel_dp->num_sink_rates;
212 }
213
214 *sink_rates = default_rates;
215
Manasi Navaref4829842016-12-05 16:27:36 -0800216 return (intel_dp->max_sink_link_bw >> 3) + 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700217}
218
219static int
220intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
221{
222 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
223 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
224 int size;
225
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200226 if (IS_GEN9_LP(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700227 *source_rates = bxt_rates;
228 size = ARRAY_SIZE(bxt_rates);
229 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
230 *source_rates = skl_rates;
231 size = ARRAY_SIZE(skl_rates);
232 } else {
233 *source_rates = default_rates;
234 size = ARRAY_SIZE(default_rates);
235 }
236
237 /* This depends on the fact that 5.4 is last value in the array */
238 if (!intel_dp_source_supports_hbr2(intel_dp))
239 size--;
240
241 return size;
242}
243
244static int intersect_rates(const int *source_rates, int source_len,
245 const int *sink_rates, int sink_len,
246 int *common_rates)
247{
248 int i = 0, j = 0, k = 0;
249
250 while (i < source_len && j < sink_len) {
251 if (source_rates[i] == sink_rates[j]) {
252 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
253 return k;
254 common_rates[k] = source_rates[i];
255 ++k;
256 ++i;
257 ++j;
258 } else if (source_rates[i] < sink_rates[j]) {
259 ++i;
260 } else {
261 ++j;
262 }
263 }
264 return k;
265}
266
267static int intel_dp_common_rates(struct intel_dp *intel_dp,
268 int *common_rates)
269{
270 const int *source_rates, *sink_rates;
271 int source_len, sink_len;
272
273 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
274 source_len = intel_dp_source_rates(intel_dp, &source_rates);
275
276 return intersect_rates(source_rates, source_len,
277 sink_rates, sink_len,
278 common_rates);
279}
280
Manasi Navarefdb14d32016-12-08 19:05:12 -0800281static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
282 int *common_rates, int link_rate)
283{
284 int common_len;
285 int index;
286
287 common_len = intel_dp_common_rates(intel_dp, common_rates);
288 for (index = 0; index < common_len; index++) {
289 if (link_rate == common_rates[common_len - index - 1])
290 return common_len - index - 1;
291 }
292
293 return -1;
294}
295
296int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
297 int link_rate, uint8_t lane_count)
298{
299 int common_rates[DP_MAX_SUPPORTED_RATES];
300 int link_rate_index;
301
302 link_rate_index = intel_dp_link_rate_index(intel_dp,
303 common_rates,
304 link_rate);
305 if (link_rate_index > 0) {
306 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
307 intel_dp->max_sink_lane_count = lane_count;
308 } else if (lane_count > 1) {
309 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
310 intel_dp->max_sink_lane_count = lane_count >> 1;
311 } else {
312 DRM_ERROR("Link Training Unsuccessful\n");
313 return -1;
314 }
315
316 return 0;
317}
318
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000319static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700320intel_dp_mode_valid(struct drm_connector *connector,
321 struct drm_display_mode *mode)
322{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100323 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300324 struct intel_connector *intel_connector = to_intel_connector(connector);
325 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100326 int target_clock = mode->clock;
327 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300328 int max_dotclk;
329
330 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700331
Jani Nikuladd06f902012-10-19 14:51:50 +0300332 if (is_edp(intel_dp) && fixed_mode) {
333 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100334 return MODE_PANEL;
335
Jani Nikuladd06f902012-10-19 14:51:50 +0300336 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100337 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200338
339 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100340 }
341
Ville Syrjälä50fec212015-03-12 17:10:34 +0200342 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300343 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100344
345 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
346 mode_rate = intel_dp_link_required(target_clock, 18);
347
Mika Kahola799487f2016-02-02 15:16:38 +0200348 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200349 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700350
351 if (mode->clock < 10000)
352 return MODE_CLOCK_LOW;
353
Daniel Vetter0af78a22012-05-23 11:30:55 +0200354 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
355 return MODE_H_ILLEGAL;
356
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700357 return MODE_OK;
358}
359
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800360uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700361{
362 int i;
363 uint32_t v = 0;
364
365 if (src_bytes > 4)
366 src_bytes = 4;
367 for (i = 0; i < src_bytes; i++)
368 v |= ((uint32_t) src[i]) << ((3-i) * 8);
369 return v;
370}
371
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000372static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700373{
374 int i;
375 if (dst_bytes > 4)
376 dst_bytes = 4;
377 for (i = 0; i < dst_bytes; i++)
378 dst[i] = src >> ((3-i) * 8);
379}
380
Jani Nikulabf13e812013-09-06 07:40:05 +0300381static void
382intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300383 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300384static void
385intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300386 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300387static void
388intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300389
Ville Syrjälä773538e82014-09-04 14:54:56 +0300390static void pps_lock(struct intel_dp *intel_dp)
391{
392 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
393 struct intel_encoder *encoder = &intel_dig_port->base;
394 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100395 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300396 enum intel_display_power_domain power_domain;
397
398 /*
399 * See vlv_power_sequencer_reset() why we need
400 * a power domain reference here.
401 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100402 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300403 intel_display_power_get(dev_priv, power_domain);
404
405 mutex_lock(&dev_priv->pps_mutex);
406}
407
408static void pps_unlock(struct intel_dp *intel_dp)
409{
410 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
411 struct intel_encoder *encoder = &intel_dig_port->base;
412 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100413 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300414 enum intel_display_power_domain power_domain;
415
416 mutex_unlock(&dev_priv->pps_mutex);
417
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100418 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300419 intel_display_power_put(dev_priv, power_domain);
420}
421
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300422static void
423vlv_power_sequencer_kick(struct intel_dp *intel_dp)
424{
425 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200426 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300427 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300428 bool pll_enabled, release_cl_override = false;
429 enum dpio_phy phy = DPIO_PHY(pipe);
430 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300431 uint32_t DP;
432
433 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
434 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
435 pipe_name(pipe), port_name(intel_dig_port->port)))
436 return;
437
438 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
439 pipe_name(pipe), port_name(intel_dig_port->port));
440
441 /* Preserve the BIOS-computed detected bit. This is
442 * supposed to be read-only.
443 */
444 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
445 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
446 DP |= DP_PORT_WIDTH(1);
447 DP |= DP_LINK_TRAIN_PAT_1;
448
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100449 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300450 DP |= DP_PIPE_SELECT_CHV(pipe);
451 else if (pipe == PIPE_B)
452 DP |= DP_PIPEB_SELECT;
453
Ville Syrjäläd288f652014-10-28 13:20:22 +0200454 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
455
456 /*
457 * The DPLL for the pipe must be enabled for this to work.
458 * So enable temporarily it if it's not already enabled.
459 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300460 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100461 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300462 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
463
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200464 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000465 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
466 DRM_ERROR("Failed to force on pll for pipe %c!\n",
467 pipe_name(pipe));
468 return;
469 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300470 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200471
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300472 /*
473 * Similar magic as in intel_dp_enable_port().
474 * We _must_ do this port enable + disable trick
475 * to make this power seqeuencer lock onto the port.
476 * Otherwise even VDD force bit won't work.
477 */
478 I915_WRITE(intel_dp->output_reg, DP);
479 POSTING_READ(intel_dp->output_reg);
480
481 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
482 POSTING_READ(intel_dp->output_reg);
483
484 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
485 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200486
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300487 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200488 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300489
490 if (release_cl_override)
491 chv_phy_powergate_ch(dev_priv, phy, ch, false);
492 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300493}
494
Jani Nikulabf13e812013-09-06 07:40:05 +0300495static enum pipe
496vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
497{
498 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300499 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100500 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300501 struct intel_encoder *encoder;
502 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300503 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300504
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300505 lockdep_assert_held(&dev_priv->pps_mutex);
506
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300507 /* We should never land here with regular DP ports */
508 WARN_ON(!is_edp(intel_dp));
509
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300510 if (intel_dp->pps_pipe != INVALID_PIPE)
511 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300512
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300513 /*
514 * We don't have power sequencer currently.
515 * Pick one that's not used by other ports.
516 */
Jani Nikula19c80542015-12-16 12:48:16 +0200517 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300518 struct intel_dp *tmp;
519
520 if (encoder->type != INTEL_OUTPUT_EDP)
521 continue;
522
523 tmp = enc_to_intel_dp(&encoder->base);
524
525 if (tmp->pps_pipe != INVALID_PIPE)
526 pipes &= ~(1 << tmp->pps_pipe);
527 }
528
529 /*
530 * Didn't find one. This should not happen since there
531 * are two power sequencers and up to two eDP ports.
532 */
533 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300534 pipe = PIPE_A;
535 else
536 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300537
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300538 vlv_steal_power_sequencer(dev, pipe);
539 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300540
541 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
542 pipe_name(intel_dp->pps_pipe),
543 port_name(intel_dig_port->port));
544
545 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300546 intel_dp_init_panel_power_sequencer(dev, intel_dp);
547 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300548
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300549 /*
550 * Even vdd force doesn't work until we've made
551 * the power sequencer lock in on the port.
552 */
553 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300554
555 return intel_dp->pps_pipe;
556}
557
Imre Deak78597992016-06-16 16:37:20 +0300558static int
559bxt_power_sequencer_idx(struct intel_dp *intel_dp)
560{
561 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
562 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100563 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300564
565 lockdep_assert_held(&dev_priv->pps_mutex);
566
567 /* We should never land here with regular DP ports */
568 WARN_ON(!is_edp(intel_dp));
569
570 /*
571 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
572 * mapping needs to be retrieved from VBT, for now just hard-code to
573 * use instance #0 always.
574 */
575 if (!intel_dp->pps_reset)
576 return 0;
577
578 intel_dp->pps_reset = false;
579
580 /*
581 * Only the HW needs to be reprogrammed, the SW state is fixed and
582 * has been setup during connector init.
583 */
584 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
585
586 return 0;
587}
588
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300589typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
590 enum pipe pipe);
591
592static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
593 enum pipe pipe)
594{
Imre Deak44cb7342016-08-10 14:07:29 +0300595 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300596}
597
598static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
599 enum pipe pipe)
600{
Imre Deak44cb7342016-08-10 14:07:29 +0300601 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300602}
603
604static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
605 enum pipe pipe)
606{
607 return true;
608}
609
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300610static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300611vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
612 enum port port,
613 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300614{
Jani Nikulabf13e812013-09-06 07:40:05 +0300615 enum pipe pipe;
616
Jani Nikulabf13e812013-09-06 07:40:05 +0300617 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300618 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300619 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300620
621 if (port_sel != PANEL_PORT_SELECT_VLV(port))
622 continue;
623
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300624 if (!pipe_check(dev_priv, pipe))
625 continue;
626
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300627 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300628 }
629
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300630 return INVALID_PIPE;
631}
632
633static void
634vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
635{
636 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
637 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100638 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300639 enum port port = intel_dig_port->port;
640
641 lockdep_assert_held(&dev_priv->pps_mutex);
642
643 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300644 /* first pick one where the panel is on */
645 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
646 vlv_pipe_has_pp_on);
647 /* didn't find one? pick one where vdd is on */
648 if (intel_dp->pps_pipe == INVALID_PIPE)
649 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
650 vlv_pipe_has_vdd_on);
651 /* didn't find one? pick one with just the correct port */
652 if (intel_dp->pps_pipe == INVALID_PIPE)
653 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
654 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300655
656 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
657 if (intel_dp->pps_pipe == INVALID_PIPE) {
658 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
659 port_name(port));
660 return;
661 }
662
663 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
664 port_name(port), pipe_name(intel_dp->pps_pipe));
665
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300666 intel_dp_init_panel_power_sequencer(dev, intel_dp);
667 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300668}
669
Imre Deak78597992016-06-16 16:37:20 +0300670void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300671{
Chris Wilson91c8a322016-07-05 10:40:23 +0100672 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300673 struct intel_encoder *encoder;
674
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100675 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200676 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300677 return;
678
679 /*
680 * We can't grab pps_mutex here due to deadlock with power_domain
681 * mutex when power_domain functions are called while holding pps_mutex.
682 * That also means that in order to use pps_pipe the code needs to
683 * hold both a power domain reference and pps_mutex, and the power domain
684 * reference get/put must be done while _not_ holding pps_mutex.
685 * pps_{lock,unlock}() do these steps in the correct order, so one
686 * should use them always.
687 */
688
Jani Nikula19c80542015-12-16 12:48:16 +0200689 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300690 struct intel_dp *intel_dp;
691
692 if (encoder->type != INTEL_OUTPUT_EDP)
693 continue;
694
695 intel_dp = enc_to_intel_dp(&encoder->base);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200696 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300697 intel_dp->pps_reset = true;
698 else
699 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300700 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300701}
702
Imre Deak8e8232d2016-06-16 16:37:21 +0300703struct pps_registers {
704 i915_reg_t pp_ctrl;
705 i915_reg_t pp_stat;
706 i915_reg_t pp_on;
707 i915_reg_t pp_off;
708 i915_reg_t pp_div;
709};
710
711static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
712 struct intel_dp *intel_dp,
713 struct pps_registers *regs)
714{
Imre Deak44cb7342016-08-10 14:07:29 +0300715 int pps_idx = 0;
716
Imre Deak8e8232d2016-06-16 16:37:21 +0300717 memset(regs, 0, sizeof(*regs));
718
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200719 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300720 pps_idx = bxt_power_sequencer_idx(intel_dp);
721 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
722 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300723
Imre Deak44cb7342016-08-10 14:07:29 +0300724 regs->pp_ctrl = PP_CONTROL(pps_idx);
725 regs->pp_stat = PP_STATUS(pps_idx);
726 regs->pp_on = PP_ON_DELAYS(pps_idx);
727 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200728 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300729 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300730}
731
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200732static i915_reg_t
733_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300734{
Imre Deak8e8232d2016-06-16 16:37:21 +0300735 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300736
Imre Deak8e8232d2016-06-16 16:37:21 +0300737 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
738 &regs);
739
740 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300741}
742
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200743static i915_reg_t
744_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300745{
Imre Deak8e8232d2016-06-16 16:37:21 +0300746 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300747
Imre Deak8e8232d2016-06-16 16:37:21 +0300748 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
749 &regs);
750
751 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300752}
753
Clint Taylor01527b32014-07-07 13:01:46 -0700754/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
755 This function only applicable when panel PM state is not to be tracked */
756static int edp_notify_handler(struct notifier_block *this, unsigned long code,
757 void *unused)
758{
759 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
760 edp_notifier);
761 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100762 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700763
764 if (!is_edp(intel_dp) || code != SYS_RESTART)
765 return 0;
766
Ville Syrjälä773538e82014-09-04 14:54:56 +0300767 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300768
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100769 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300770 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200771 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300772 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300773
Imre Deak44cb7342016-08-10 14:07:29 +0300774 pp_ctrl_reg = PP_CONTROL(pipe);
775 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700776 pp_div = I915_READ(pp_div_reg);
777 pp_div &= PP_REFERENCE_DIVIDER_MASK;
778
779 /* 0x1F write to PP_DIV_REG sets max cycle delay */
780 I915_WRITE(pp_div_reg, pp_div | 0x1F);
781 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
782 msleep(intel_dp->panel_power_cycle_delay);
783 }
784
Ville Syrjälä773538e82014-09-04 14:54:56 +0300785 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300786
Clint Taylor01527b32014-07-07 13:01:46 -0700787 return 0;
788}
789
Daniel Vetter4be73782014-01-17 14:39:48 +0100790static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700791{
Paulo Zanoni30add222012-10-26 19:05:45 -0200792 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100793 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700794
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300795 lockdep_assert_held(&dev_priv->pps_mutex);
796
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100797 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300798 intel_dp->pps_pipe == INVALID_PIPE)
799 return false;
800
Jani Nikulabf13e812013-09-06 07:40:05 +0300801 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700802}
803
Daniel Vetter4be73782014-01-17 14:39:48 +0100804static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700805{
Paulo Zanoni30add222012-10-26 19:05:45 -0200806 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100807 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700808
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300809 lockdep_assert_held(&dev_priv->pps_mutex);
810
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100811 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300812 intel_dp->pps_pipe == INVALID_PIPE)
813 return false;
814
Ville Syrjälä773538e82014-09-04 14:54:56 +0300815 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700816}
817
Keith Packard9b984da2011-09-19 13:54:47 -0700818static void
819intel_dp_check_edp(struct intel_dp *intel_dp)
820{
Paulo Zanoni30add222012-10-26 19:05:45 -0200821 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100822 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700823
Keith Packard9b984da2011-09-19 13:54:47 -0700824 if (!is_edp(intel_dp))
825 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700826
Daniel Vetter4be73782014-01-17 14:39:48 +0100827 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700828 WARN(1, "eDP powered off while attempting aux channel communication.\n");
829 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300830 I915_READ(_pp_stat_reg(intel_dp)),
831 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700832 }
833}
834
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100835static uint32_t
836intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
837{
838 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
839 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100840 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200841 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100842 uint32_t status;
843 bool done;
844
Daniel Vetteref04f002012-12-01 21:03:59 +0100845#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100846 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300847 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300848 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100849 else
Imre Deak713a6b662016-06-28 13:37:33 +0300850 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100851 if (!done)
852 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
853 has_aux_irq);
854#undef C
855
856 return status;
857}
858
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200859static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000860{
861 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200862 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000863
Ville Syrjäläa457f542016-03-02 17:22:17 +0200864 if (index)
865 return 0;
866
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000867 /*
868 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200869 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000870 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200871 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000872}
873
874static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
875{
876 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200877 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000878
879 if (index)
880 return 0;
881
Ville Syrjäläa457f542016-03-02 17:22:17 +0200882 /*
883 * The clock divider is based off the cdclk or PCH rawclk, and would
884 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
885 * divide by 2000 and use that
886 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200887 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200888 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200889 else
890 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000891}
892
893static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300894{
895 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200896 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300897
Ville Syrjäläa457f542016-03-02 17:22:17 +0200898 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300899 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100900 switch (index) {
901 case 0: return 63;
902 case 1: return 72;
903 default: return 0;
904 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300905 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200906
907 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300908}
909
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000910static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
911{
912 /*
913 * SKL doesn't need us to program the AUX clock divider (Hardware will
914 * derive the clock from CDCLK automatically). We still implement the
915 * get_aux_clock_divider vfunc to plug-in into the existing code.
916 */
917 return index ? 0 : 1;
918}
919
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200920static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
921 bool has_aux_irq,
922 int send_bytes,
923 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000924{
925 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100926 struct drm_i915_private *dev_priv =
927 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000928 uint32_t precharge, timeout;
929
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100930 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000931 precharge = 3;
932 else
933 precharge = 5;
934
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100935 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000936 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
937 else
938 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
939
940 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000941 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000942 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000943 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000944 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000945 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000946 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
947 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000948 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000949}
950
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000951static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
952 bool has_aux_irq,
953 int send_bytes,
954 uint32_t unused)
955{
956 return DP_AUX_CH_CTL_SEND_BUSY |
957 DP_AUX_CH_CTL_DONE |
958 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
959 DP_AUX_CH_CTL_TIME_OUT_ERROR |
960 DP_AUX_CH_CTL_TIME_OUT_1600us |
961 DP_AUX_CH_CTL_RECEIVE_ERROR |
962 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200963 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000964 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
965}
966
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700967static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100968intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200969 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700970 uint8_t *recv, int recv_size)
971{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200972 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +0000973 struct drm_i915_private *dev_priv =
974 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200975 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100976 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100977 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700978 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000979 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +0000980 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +0200981 bool vdd;
982
Ville Syrjälä773538e82014-09-04 14:54:56 +0300983 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300984
Ville Syrjälä72c35002014-08-18 22:16:00 +0300985 /*
986 * We will be called with VDD already enabled for dpcd/edid/oui reads.
987 * In such cases we want to leave VDD enabled and it's up to upper layers
988 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
989 * ourselves.
990 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300991 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100992
993 /* dp aux is extremely sensitive to irq latency, hence request the
994 * lowest possible wakeup latency and so prevent the cpu from going into
995 * deep sleep states.
996 */
997 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700998
Keith Packard9b984da2011-09-19 13:54:47 -0700999 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001000
Jesse Barnes11bee432011-08-01 15:02:20 -07001001 /* Try to wait for any previous AUX channel activity */
1002 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001003 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001004 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1005 break;
1006 msleep(1);
1007 }
1008
1009 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001010 static u32 last_status = -1;
1011 const u32 status = I915_READ(ch_ctl);
1012
1013 if (status != last_status) {
1014 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1015 status);
1016 last_status = status;
1017 }
1018
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001019 ret = -EBUSY;
1020 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001021 }
1022
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001023 /* Only 5 data registers! */
1024 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1025 ret = -E2BIG;
1026 goto out;
1027 }
1028
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001029 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001030 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1031 has_aux_irq,
1032 send_bytes,
1033 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001034
Chris Wilsonbc866252013-07-21 16:00:03 +01001035 /* Must try at least 3 times according to DP spec */
1036 for (try = 0; try < 5; try++) {
1037 /* Load the send data into the aux channel data registers */
1038 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001039 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001040 intel_dp_pack_aux(send + i,
1041 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001042
Chris Wilsonbc866252013-07-21 16:00:03 +01001043 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001044 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001045
Chris Wilsonbc866252013-07-21 16:00:03 +01001046 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001047
Chris Wilsonbc866252013-07-21 16:00:03 +01001048 /* Clear done status and any errors */
1049 I915_WRITE(ch_ctl,
1050 status |
1051 DP_AUX_CH_CTL_DONE |
1052 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1053 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001054
Todd Previte74ebf292015-04-15 08:38:41 -07001055 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001056 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001057
1058 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1059 * 400us delay required for errors and timeouts
1060 * Timeout errors from the HW already meet this
1061 * requirement so skip to next iteration
1062 */
1063 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1064 usleep_range(400, 500);
1065 continue;
1066 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001067 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001068 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001069 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001070 }
1071
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001072 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001073 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001074 ret = -EBUSY;
1075 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001076 }
1077
Jim Bridee058c942015-05-27 10:21:48 -07001078done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001079 /* Check for timeout or receive error.
1080 * Timeouts occur when the sink is not connected
1081 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001082 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001083 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001084 ret = -EIO;
1085 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001086 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001087
1088 /* Timeouts occur when the device isn't connected, so they're
1089 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001090 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001091 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001092 ret = -ETIMEDOUT;
1093 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001094 }
1095
1096 /* Unload any bytes sent back from the other side */
1097 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1098 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001099
1100 /*
1101 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1102 * We have no idea of what happened so we return -EBUSY so
1103 * drm layer takes care for the necessary retries.
1104 */
1105 if (recv_bytes == 0 || recv_bytes > 20) {
1106 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1107 recv_bytes);
1108 /*
1109 * FIXME: This patch was created on top of a series that
1110 * organize the retries at drm level. There EBUSY should
1111 * also take care for 1ms wait before retrying.
1112 * That aux retries re-org is still needed and after that is
1113 * merged we remove this sleep from here.
1114 */
1115 usleep_range(1000, 1500);
1116 ret = -EBUSY;
1117 goto out;
1118 }
1119
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001120 if (recv_bytes > recv_size)
1121 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001122
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001123 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001124 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001125 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001126
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001127 ret = recv_bytes;
1128out:
1129 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1130
Jani Nikula884f19e2014-03-14 16:51:14 +02001131 if (vdd)
1132 edp_panel_vdd_off(intel_dp, false);
1133
Ville Syrjälä773538e82014-09-04 14:54:56 +03001134 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001135
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001136 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001137}
1138
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001139#define BARE_ADDRESS_SIZE 3
1140#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001141static ssize_t
1142intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001143{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001144 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1145 uint8_t txbuf[20], rxbuf[20];
1146 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001147 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001148
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001149 txbuf[0] = (msg->request << 4) |
1150 ((msg->address >> 16) & 0xf);
1151 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001152 txbuf[2] = msg->address & 0xff;
1153 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001154
Jani Nikula9d1a1032014-03-14 16:51:15 +02001155 switch (msg->request & ~DP_AUX_I2C_MOT) {
1156 case DP_AUX_NATIVE_WRITE:
1157 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001158 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001159 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001160 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001161
Jani Nikula9d1a1032014-03-14 16:51:15 +02001162 if (WARN_ON(txsize > 20))
1163 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001164
Ville Syrjälädd788092016-07-28 17:55:04 +03001165 WARN_ON(!msg->buffer != !msg->size);
1166
Imre Deakd81a67c2016-01-29 14:52:26 +02001167 if (msg->buffer)
1168 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001169
Jani Nikula9d1a1032014-03-14 16:51:15 +02001170 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1171 if (ret > 0) {
1172 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001173
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001174 if (ret > 1) {
1175 /* Number of bytes written in a short write. */
1176 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1177 } else {
1178 /* Return payload size. */
1179 ret = msg->size;
1180 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001182 break;
1183
1184 case DP_AUX_NATIVE_READ:
1185 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001186 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001187 rxsize = msg->size + 1;
1188
1189 if (WARN_ON(rxsize > 20))
1190 return -E2BIG;
1191
1192 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1193 if (ret > 0) {
1194 msg->reply = rxbuf[0] >> 4;
1195 /*
1196 * Assume happy day, and copy the data. The caller is
1197 * expected to check msg->reply before touching it.
1198 *
1199 * Return payload size.
1200 */
1201 ret--;
1202 memcpy(msg->buffer, rxbuf + 1, ret);
1203 }
1204 break;
1205
1206 default:
1207 ret = -EINVAL;
1208 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001209 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001210
Jani Nikula9d1a1032014-03-14 16:51:15 +02001211 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001212}
1213
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001214static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1215 enum port port)
1216{
1217 const struct ddi_vbt_port_info *info =
1218 &dev_priv->vbt.ddi_port_info[port];
1219 enum port aux_port;
1220
1221 if (!info->alternate_aux_channel) {
1222 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1223 port_name(port), port_name(port));
1224 return port;
1225 }
1226
1227 switch (info->alternate_aux_channel) {
1228 case DP_AUX_A:
1229 aux_port = PORT_A;
1230 break;
1231 case DP_AUX_B:
1232 aux_port = PORT_B;
1233 break;
1234 case DP_AUX_C:
1235 aux_port = PORT_C;
1236 break;
1237 case DP_AUX_D:
1238 aux_port = PORT_D;
1239 break;
1240 default:
1241 MISSING_CASE(info->alternate_aux_channel);
1242 aux_port = PORT_A;
1243 break;
1244 }
1245
1246 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1247 port_name(aux_port), port_name(port));
1248
1249 return aux_port;
1250}
1251
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001252static i915_reg_t g4x_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_B:
1257 case PORT_C:
1258 case PORT_D:
1259 return DP_AUX_CH_CTL(port);
1260 default:
1261 MISSING_CASE(port);
1262 return DP_AUX_CH_CTL(PORT_B);
1263 }
1264}
1265
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001266static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001267 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001268{
1269 switch (port) {
1270 case PORT_B:
1271 case PORT_C:
1272 case PORT_D:
1273 return DP_AUX_CH_DATA(port, index);
1274 default:
1275 MISSING_CASE(port);
1276 return DP_AUX_CH_DATA(PORT_B, index);
1277 }
1278}
1279
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001280static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001281 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001282{
1283 switch (port) {
1284 case PORT_A:
1285 return DP_AUX_CH_CTL(port);
1286 case PORT_B:
1287 case PORT_C:
1288 case PORT_D:
1289 return PCH_DP_AUX_CH_CTL(port);
1290 default:
1291 MISSING_CASE(port);
1292 return DP_AUX_CH_CTL(PORT_A);
1293 }
1294}
1295
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001296static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001297 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001298{
1299 switch (port) {
1300 case PORT_A:
1301 return DP_AUX_CH_DATA(port, index);
1302 case PORT_B:
1303 case PORT_C:
1304 case PORT_D:
1305 return PCH_DP_AUX_CH_DATA(port, index);
1306 default:
1307 MISSING_CASE(port);
1308 return DP_AUX_CH_DATA(PORT_A, index);
1309 }
1310}
1311
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001312static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001313 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001314{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001315 switch (port) {
1316 case PORT_A:
1317 case PORT_B:
1318 case PORT_C:
1319 case PORT_D:
1320 return DP_AUX_CH_CTL(port);
1321 default:
1322 MISSING_CASE(port);
1323 return DP_AUX_CH_CTL(PORT_A);
1324 }
1325}
1326
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001327static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001328 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001329{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001330 switch (port) {
1331 case PORT_A:
1332 case PORT_B:
1333 case PORT_C:
1334 case PORT_D:
1335 return DP_AUX_CH_DATA(port, index);
1336 default:
1337 MISSING_CASE(port);
1338 return DP_AUX_CH_DATA(PORT_A, index);
1339 }
1340}
1341
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001342static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001343 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001344{
1345 if (INTEL_INFO(dev_priv)->gen >= 9)
1346 return skl_aux_ctl_reg(dev_priv, port);
1347 else if (HAS_PCH_SPLIT(dev_priv))
1348 return ilk_aux_ctl_reg(dev_priv, port);
1349 else
1350 return g4x_aux_ctl_reg(dev_priv, port);
1351}
1352
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001353static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001354 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001355{
1356 if (INTEL_INFO(dev_priv)->gen >= 9)
1357 return skl_aux_data_reg(dev_priv, port, index);
1358 else if (HAS_PCH_SPLIT(dev_priv))
1359 return ilk_aux_data_reg(dev_priv, port, index);
1360 else
1361 return g4x_aux_data_reg(dev_priv, port, index);
1362}
1363
1364static void intel_aux_reg_init(struct intel_dp *intel_dp)
1365{
1366 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001367 enum port port = intel_aux_port(dev_priv,
1368 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001369 int i;
1370
1371 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1372 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1373 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1374}
1375
Jani Nikula9d1a1032014-03-14 16:51:15 +02001376static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001377intel_dp_aux_fini(struct intel_dp *intel_dp)
1378{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001379 kfree(intel_dp->aux.name);
1380}
1381
Chris Wilson7a418e32016-06-24 14:00:14 +01001382static void
Mika Kaholab6339582016-09-09 14:10:52 +03001383intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001384{
Jani Nikula33ad6622014-03-14 16:51:16 +02001385 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1386 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001387
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001388 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001389 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001390
Chris Wilson7a418e32016-06-24 14:00:14 +01001391 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001392 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001393 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001394}
1395
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001396bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301397{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001398 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001399 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001400
Navare, Manasi D577c5432016-09-27 16:36:53 -07001401 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1402 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301403 return true;
1404 else
1405 return false;
1406}
1407
Daniel Vetter0e503382014-07-04 11:26:04 -03001408static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001409intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001410 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001411{
1412 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001413 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001414 const struct dp_link_dpll *divisor = NULL;
1415 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001416
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001417 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001418 divisor = gen4_dpll;
1419 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001420 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001421 divisor = pch_dpll;
1422 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001423 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001424 divisor = chv_dpll;
1425 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001426 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001427 divisor = vlv_dpll;
1428 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001429 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001430
1431 if (divisor && count) {
1432 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001433 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001434 pipe_config->dpll = divisor[i].dpll;
1435 pipe_config->clock_set = true;
1436 break;
1437 }
1438 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001439 }
1440}
1441
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001442static void snprintf_int_array(char *str, size_t len,
1443 const int *array, int nelem)
1444{
1445 int i;
1446
1447 str[0] = '\0';
1448
1449 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001450 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001451 if (r >= len)
1452 return;
1453 str += r;
1454 len -= r;
1455 }
1456}
1457
1458static void intel_dp_print_rates(struct intel_dp *intel_dp)
1459{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001460 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001461 int source_len, sink_len, common_len;
1462 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001463 char str[128]; /* FIXME: too big for stack? */
1464
1465 if ((drm_debug & DRM_UT_KMS) == 0)
1466 return;
1467
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001468 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001469 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1470 DRM_DEBUG_KMS("source rates: %s\n", str);
1471
1472 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1473 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1474 DRM_DEBUG_KMS("sink rates: %s\n", str);
1475
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001476 common_len = intel_dp_common_rates(intel_dp, common_rates);
1477 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1478 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001479}
1480
Imre Deak489375c2016-10-24 19:33:31 +03001481bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001482__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001483{
Imre Deak7b3fc172016-10-25 16:12:39 +03001484 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1485 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001486
Imre Deak7b3fc172016-10-25 16:12:39 +03001487 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1488 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001489}
1490
Imre Deak12a47a422016-10-24 19:33:29 +03001491bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001492{
Imre Deak7b3fc172016-10-25 16:12:39 +03001493 struct intel_dp_desc *desc = &intel_dp->desc;
1494 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1495 DP_OUI_SUPPORT;
1496 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001497
Imre Deak7b3fc172016-10-25 16:12:39 +03001498 if (!__intel_dp_read_desc(intel_dp, desc))
1499 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001500
Imre Deak7b3fc172016-10-25 16:12:39 +03001501 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1502 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1503 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1504 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1505 dev_id_len, desc->device_id,
1506 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1507 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001508
Imre Deak7b3fc172016-10-25 16:12:39 +03001509 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001510}
1511
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001512static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301513{
1514 int i = 0;
1515
1516 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1517 if (find == rates[i])
1518 break;
1519
1520 return i;
1521}
1522
Ville Syrjälä50fec212015-03-12 17:10:34 +02001523int
1524intel_dp_max_link_rate(struct intel_dp *intel_dp)
1525{
1526 int rates[DP_MAX_SUPPORTED_RATES] = {};
1527 int len;
1528
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001529 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001530 if (WARN_ON(len <= 0))
1531 return 162000;
1532
Ville Syrjälä1354f732016-07-28 17:50:45 +03001533 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001534}
1535
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001536int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1537{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001538 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001539}
1540
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001541void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1542 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001543{
1544 if (intel_dp->num_sink_rates) {
1545 *link_bw = 0;
1546 *rate_select =
1547 intel_dp_rate_select(intel_dp, port_clock);
1548 } else {
1549 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1550 *rate_select = 0;
1551 }
1552}
1553
Jani Nikulaf580bea2016-09-15 16:28:52 +03001554static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1555 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001556{
1557 int bpp, bpc;
1558
1559 bpp = pipe_config->pipe_bpp;
1560 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1561
1562 if (bpc > 0)
1563 bpp = min(bpp, 3*bpc);
1564
1565 return bpp;
1566}
1567
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001568bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001569intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001570 struct intel_crtc_state *pipe_config,
1571 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001572{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001573 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001574 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001575 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001576 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001577 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001578 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001579 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001580 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001581 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001582 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001583 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301584 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001585 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001586 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001587 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1588 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001589 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301590
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001591 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301592
1593 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001594 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301595
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001596 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001597
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001598 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001599 pipe_config->has_pch_encoder = true;
1600
Vandana Kannanf769cd22014-08-05 07:51:22 -07001601 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001602 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001603
Jani Nikuladd06f902012-10-19 14:51:50 +03001604 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1605 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1606 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001607
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001608 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001609 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001610 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001611 if (ret)
1612 return ret;
1613 }
1614
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001615 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001616 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1617 intel_connector->panel.fitting_mode);
1618 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001619 intel_pch_panel_fitting(intel_crtc, pipe_config,
1620 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001621 }
1622
Daniel Vettercb1793c2012-06-04 18:39:21 +02001623 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001624 return false;
1625
Daniel Vetter083f9562012-04-20 20:23:49 +02001626 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301627 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001628 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001629 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001630
Daniel Vetter36008362013-03-27 00:44:59 +01001631 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1632 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001633 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001634 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301635
1636 /* Get bpp from vbt only for panels that dont have bpp in edid */
1637 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001638 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001639 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001640 dev_priv->vbt.edp.bpp);
1641 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001642 }
1643
Jani Nikula344c5bb2014-09-09 11:25:13 +03001644 /*
1645 * Use the maximum clock and number of lanes the eDP panel
1646 * advertizes being capable of. The panels are generally
1647 * designed to support only a single clock and lane
1648 * configuration, and typically these values correspond to the
1649 * native resolution of the panel.
1650 */
1651 min_lane_count = max_lane_count;
1652 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001653 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001654
Daniel Vetter36008362013-03-27 00:44:59 +01001655 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001656 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1657 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001658
Dave Airliec6930992014-07-14 11:04:39 +10001659 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301660 for (lane_count = min_lane_count;
1661 lane_count <= max_lane_count;
1662 lane_count <<= 1) {
1663
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001664 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001665 link_avail = intel_dp_max_data_rate(link_clock,
1666 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001667
Daniel Vetter36008362013-03-27 00:44:59 +01001668 if (mode_rate <= link_avail) {
1669 goto found;
1670 }
1671 }
1672 }
1673 }
1674
1675 return false;
1676
1677found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001678 if (intel_dp->color_range_auto) {
1679 /*
1680 * See:
1681 * CEA-861-E - 5.1 Default Encoding Parameters
1682 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1683 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001684 pipe_config->limited_color_range =
1685 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1686 } else {
1687 pipe_config->limited_color_range =
1688 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001689 }
1690
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001691 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301692
Daniel Vetter657445f2013-05-04 10:09:18 +02001693 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001694 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001695
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001696 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1697 &link_bw, &rate_select);
1698
1699 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1700 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001701 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001702 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1703 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001704
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001705 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001706 adjusted_mode->crtc_clock,
1707 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001708 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001709
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301710 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301711 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001712 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301713 intel_link_compute_m_n(bpp, lane_count,
1714 intel_connector->panel.downclock_mode->clock,
1715 pipe_config->port_clock,
1716 &pipe_config->dp_m2_n2);
1717 }
1718
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001719 /*
1720 * DPLL0 VCO may need to be adjusted to get the correct
1721 * clock for eDP. This will affect cdclk as well.
1722 */
1723 if (is_edp(intel_dp) &&
1724 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1725 int vco;
1726
1727 switch (pipe_config->port_clock / 2) {
1728 case 108000:
1729 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001730 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001731 break;
1732 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001733 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001734 break;
1735 }
1736
1737 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1738 }
1739
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001740 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001741 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001742
Daniel Vetter36008362013-03-27 00:44:59 +01001743 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001744}
1745
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001746void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001747 int link_rate, uint8_t lane_count,
1748 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001749{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001750 intel_dp->link_rate = link_rate;
1751 intel_dp->lane_count = lane_count;
1752 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001753}
1754
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001755static void intel_dp_prepare(struct intel_encoder *encoder,
1756 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001757{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001758 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001759 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001760 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001761 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001762 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001763 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001764
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001765 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1766 pipe_config->lane_count,
1767 intel_crtc_has_type(pipe_config,
1768 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001769
Keith Packard417e8222011-11-01 19:54:11 -07001770 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001771 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001772 *
1773 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001774 * SNB CPU
1775 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001776 * CPT PCH
1777 *
1778 * IBX PCH and CPU are the same for almost everything,
1779 * except that the CPU DP PLL is configured in this
1780 * register
1781 *
1782 * CPT PCH is quite different, having many bits moved
1783 * to the TRANS_DP_CTL register instead. That
1784 * configuration happens (oddly) in ironlake_pch_enable
1785 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001786
Keith Packard417e8222011-11-01 19:54:11 -07001787 /* Preserve the BIOS-computed detected bit. This is
1788 * supposed to be read-only.
1789 */
1790 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001791
Keith Packard417e8222011-11-01 19:54:11 -07001792 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001793 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001794 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795
Keith Packard417e8222011-11-01 19:54:11 -07001796 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001797
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001798 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001799 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_CPT;
1804
Jani Nikula6aba5b62013-10-04 15:08:10 +03001805 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001806 intel_dp->DP |= DP_ENHANCED_FRAMING;
1807
Daniel Vetter7c62a162013-06-01 17:16:20 +02001808 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001809 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001810 u32 trans_dp;
1811
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001812 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001813
1814 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1815 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1816 trans_dp |= TRANS_DP_ENH_FRAMING;
1817 else
1818 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1819 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001820 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001821 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001822 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001823
1824 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1825 intel_dp->DP |= DP_SYNC_HS_HIGH;
1826 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1827 intel_dp->DP |= DP_SYNC_VS_HIGH;
1828 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1829
Jani Nikula6aba5b62013-10-04 15:08:10 +03001830 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001831 intel_dp->DP |= DP_ENHANCED_FRAMING;
1832
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001833 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001834 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001835 else if (crtc->pipe == PIPE_B)
1836 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001837 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001838}
1839
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001840#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1841#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001842
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001843#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1844#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001845
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001846#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1847#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001848
Imre Deakde9c1b62016-06-16 20:01:46 +03001849static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1850 struct intel_dp *intel_dp);
1851
Daniel Vetter4be73782014-01-17 14:39:48 +01001852static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001853 u32 mask,
1854 u32 value)
1855{
Paulo Zanoni30add222012-10-26 19:05:45 -02001856 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001857 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001858 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001859
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001860 lockdep_assert_held(&dev_priv->pps_mutex);
1861
Imre Deakde9c1b62016-06-16 20:01:46 +03001862 intel_pps_verify_state(dev_priv, intel_dp);
1863
Jani Nikulabf13e812013-09-06 07:40:05 +03001864 pp_stat_reg = _pp_stat_reg(intel_dp);
1865 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001866
1867 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001868 mask, value,
1869 I915_READ(pp_stat_reg),
1870 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001871
Chris Wilson9036ff02016-06-30 15:33:09 +01001872 if (intel_wait_for_register(dev_priv,
1873 pp_stat_reg, mask, value,
1874 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001875 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001876 I915_READ(pp_stat_reg),
1877 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001878
1879 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001880}
1881
Daniel Vetter4be73782014-01-17 14:39:48 +01001882static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001883{
1884 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001885 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001886}
1887
Daniel Vetter4be73782014-01-17 14:39:48 +01001888static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001889{
Keith Packardbd943152011-09-18 23:09:52 -07001890 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001891 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001892}
Keith Packardbd943152011-09-18 23:09:52 -07001893
Daniel Vetter4be73782014-01-17 14:39:48 +01001894static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001895{
Abhay Kumard28d4732016-01-22 17:39:04 -08001896 ktime_t panel_power_on_time;
1897 s64 panel_power_off_duration;
1898
Keith Packard99ea7122011-11-01 19:57:50 -07001899 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001900
Abhay Kumard28d4732016-01-22 17:39:04 -08001901 /* take the difference of currrent time and panel power off time
1902 * and then make panel wait for t11_t12 if needed. */
1903 panel_power_on_time = ktime_get_boottime();
1904 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1905
Paulo Zanonidce56b32013-12-19 14:29:40 -02001906 /* When we disable the VDD override bit last we have to do the manual
1907 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001908 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1909 wait_remaining_ms_from_jiffies(jiffies,
1910 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001911
Daniel Vetter4be73782014-01-17 14:39:48 +01001912 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001913}
Keith Packardbd943152011-09-18 23:09:52 -07001914
Daniel Vetter4be73782014-01-17 14:39:48 +01001915static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001916{
1917 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1918 intel_dp->backlight_on_delay);
1919}
1920
Daniel Vetter4be73782014-01-17 14:39:48 +01001921static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001922{
1923 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1924 intel_dp->backlight_off_delay);
1925}
Keith Packard99ea7122011-11-01 19:57:50 -07001926
Keith Packard832dd3c2011-11-01 19:34:06 -07001927/* Read the current pp_control value, unlocking the register if it
1928 * is locked
1929 */
1930
Jesse Barnes453c5422013-03-28 09:55:41 -07001931static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001932{
Jesse Barnes453c5422013-03-28 09:55:41 -07001933 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001934 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001935 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001936
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001937 lockdep_assert_held(&dev_priv->pps_mutex);
1938
Jani Nikulabf13e812013-09-06 07:40:05 +03001939 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001940 if (WARN_ON(!HAS_DDI(dev_priv) &&
1941 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301942 control &= ~PANEL_UNLOCK_MASK;
1943 control |= PANEL_UNLOCK_REGS;
1944 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001945 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001946}
1947
Ville Syrjälä951468f2014-09-04 14:55:31 +03001948/*
1949 * Must be paired with edp_panel_vdd_off().
1950 * Must hold pps_mutex around the whole on/off sequence.
1951 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1952 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001953static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001954{
Paulo Zanoni30add222012-10-26 19:05:45 -02001955 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001956 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1957 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001958 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001959 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001960 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001961 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001962 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001963
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001964 lockdep_assert_held(&dev_priv->pps_mutex);
1965
Keith Packard97af61f572011-09-28 16:23:51 -07001966 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001967 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001968
Egbert Eich2c623c12014-11-25 12:54:57 +01001969 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001970 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001971
Daniel Vetter4be73782014-01-17 14:39:48 +01001972 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001973 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001974
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001975 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001976 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001977
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001978 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1979 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001980
Daniel Vetter4be73782014-01-17 14:39:48 +01001981 if (!edp_have_panel_power(intel_dp))
1982 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001983
Jesse Barnes453c5422013-03-28 09:55:41 -07001984 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001985 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001986
Jani Nikulabf13e812013-09-06 07:40:05 +03001987 pp_stat_reg = _pp_stat_reg(intel_dp);
1988 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001989
1990 I915_WRITE(pp_ctrl_reg, pp);
1991 POSTING_READ(pp_ctrl_reg);
1992 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1993 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001994 /*
1995 * If the panel wasn't on, delay before accessing aux channel
1996 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001997 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001998 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1999 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002000 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002001 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002002
2003 return need_to_disable;
2004}
2005
Ville Syrjälä951468f2014-09-04 14:55:31 +03002006/*
2007 * Must be paired with intel_edp_panel_vdd_off() or
2008 * intel_edp_panel_off().
2009 * Nested calls to these functions are not allowed since
2010 * we drop the lock. Caller must use some higher level
2011 * locking to prevent nested calls from other threads.
2012 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002013void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002014{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002015 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002016
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002017 if (!is_edp(intel_dp))
2018 return;
2019
Ville Syrjälä773538e82014-09-04 14:54:56 +03002020 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002021 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002022 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002023
Rob Clarke2c719b2014-12-15 13:56:32 -05002024 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002025 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002026}
2027
Daniel Vetter4be73782014-01-17 14:39:48 +01002028static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002029{
Paulo Zanoni30add222012-10-26 19:05:45 -02002030 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002031 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002032 struct intel_digital_port *intel_dig_port =
2033 dp_to_dig_port(intel_dp);
2034 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2035 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002036 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002037 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002038
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002039 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002040
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002041 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002042
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002043 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002044 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002045
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002046 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2047 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002048
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002049 pp = ironlake_get_pp_control(intel_dp);
2050 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002051
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002052 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2053 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002054
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002055 I915_WRITE(pp_ctrl_reg, pp);
2056 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002057
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002058 /* Make sure sequencer is idle before allowing subsequent activity */
2059 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2060 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002061
Imre Deak5a162e22016-08-10 14:07:30 +03002062 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002063 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002064
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002065 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002066 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002067}
2068
Daniel Vetter4be73782014-01-17 14:39:48 +01002069static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002070{
2071 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2072 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002073
Ville Syrjälä773538e82014-09-04 14:54:56 +03002074 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002075 if (!intel_dp->want_panel_vdd)
2076 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002077 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002078}
2079
Imre Deakaba86892014-07-30 15:57:31 +03002080static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2081{
2082 unsigned long delay;
2083
2084 /*
2085 * Queue the timer to fire a long time from now (relative to the power
2086 * down delay) to keep the panel power up across a sequence of
2087 * operations.
2088 */
2089 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2090 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2091}
2092
Ville Syrjälä951468f2014-09-04 14:55:31 +03002093/*
2094 * Must be paired with edp_panel_vdd_on().
2095 * Must hold pps_mutex around the whole on/off sequence.
2096 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2097 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002098static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002099{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002100 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002101
2102 lockdep_assert_held(&dev_priv->pps_mutex);
2103
Keith Packard97af61f572011-09-28 16:23:51 -07002104 if (!is_edp(intel_dp))
2105 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002106
Rob Clarke2c719b2014-12-15 13:56:32 -05002107 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002108 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002109
Keith Packardbd943152011-09-18 23:09:52 -07002110 intel_dp->want_panel_vdd = false;
2111
Imre Deakaba86892014-07-30 15:57:31 +03002112 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002113 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002114 else
2115 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002116}
2117
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002118static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002119{
Paulo Zanoni30add222012-10-26 19:05:45 -02002120 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002121 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002122 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002123 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002124
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002125 lockdep_assert_held(&dev_priv->pps_mutex);
2126
Keith Packard97af61f572011-09-28 16:23:51 -07002127 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002128 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002129
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002130 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2131 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002132
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002133 if (WARN(edp_have_panel_power(intel_dp),
2134 "eDP port %c panel power already on\n",
2135 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002136 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002137
Daniel Vetter4be73782014-01-17 14:39:48 +01002138 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002139
Jani Nikulabf13e812013-09-06 07:40:05 +03002140 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002141 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002142 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002143 /* ILK workaround: disable reset around power sequence */
2144 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002145 I915_WRITE(pp_ctrl_reg, pp);
2146 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002147 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002148
Imre Deak5a162e22016-08-10 14:07:30 +03002149 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002150 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002151 pp |= PANEL_POWER_RESET;
2152
Jesse Barnes453c5422013-03-28 09:55:41 -07002153 I915_WRITE(pp_ctrl_reg, pp);
2154 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002155
Daniel Vetter4be73782014-01-17 14:39:48 +01002156 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002157 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002158
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002159 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002160 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002161 I915_WRITE(pp_ctrl_reg, pp);
2162 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002163 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002164}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002165
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002166void intel_edp_panel_on(struct intel_dp *intel_dp)
2167{
2168 if (!is_edp(intel_dp))
2169 return;
2170
2171 pps_lock(intel_dp);
2172 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002173 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002174}
2175
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002176
2177static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002178{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002179 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2180 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002181 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002182 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002183 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002184 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002185 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002186
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002187 lockdep_assert_held(&dev_priv->pps_mutex);
2188
Keith Packard97af61f572011-09-28 16:23:51 -07002189 if (!is_edp(intel_dp))
2190 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002191
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002192 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2193 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002194
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002195 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2196 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002197
Jesse Barnes453c5422013-03-28 09:55:41 -07002198 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002199 /* We need to switch off panel power _and_ force vdd, for otherwise some
2200 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002201 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002202 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002203
Jani Nikulabf13e812013-09-06 07:40:05 +03002204 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002205
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002206 intel_dp->want_panel_vdd = false;
2207
Jesse Barnes453c5422013-03-28 09:55:41 -07002208 I915_WRITE(pp_ctrl_reg, pp);
2209 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002210
Abhay Kumard28d4732016-01-22 17:39:04 -08002211 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002212 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002213
2214 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002215 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002216 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002217}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002218
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002219void intel_edp_panel_off(struct intel_dp *intel_dp)
2220{
2221 if (!is_edp(intel_dp))
2222 return;
2223
2224 pps_lock(intel_dp);
2225 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002226 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002227}
2228
Jani Nikula1250d102014-08-12 17:11:39 +03002229/* Enable backlight in the panel power control. */
2230static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002231{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002232 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2233 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002234 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002235 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002236 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002237
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002238 /*
2239 * If we enable the backlight right away following a panel power
2240 * on, we may see slight flicker as the panel syncs with the eDP
2241 * link. So delay a bit to make sure the image is solid before
2242 * allowing it to appear.
2243 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002244 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002245
Ville Syrjälä773538e82014-09-04 14:54:56 +03002246 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002247
Jesse Barnes453c5422013-03-28 09:55:41 -07002248 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002249 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002250
Jani Nikulabf13e812013-09-06 07:40:05 +03002251 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002252
2253 I915_WRITE(pp_ctrl_reg, pp);
2254 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002255
Ville Syrjälä773538e82014-09-04 14:54:56 +03002256 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002257}
2258
Jani Nikula1250d102014-08-12 17:11:39 +03002259/* Enable backlight PWM and backlight PP control. */
2260void intel_edp_backlight_on(struct intel_dp *intel_dp)
2261{
2262 if (!is_edp(intel_dp))
2263 return;
2264
2265 DRM_DEBUG_KMS("\n");
2266
2267 intel_panel_enable_backlight(intel_dp->attached_connector);
2268 _intel_edp_backlight_on(intel_dp);
2269}
2270
2271/* Disable backlight in the panel power control. */
2272static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002273{
Paulo Zanoni30add222012-10-26 19:05:45 -02002274 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002275 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002276 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002277 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002278
Keith Packardf01eca22011-09-28 16:48:10 -07002279 if (!is_edp(intel_dp))
2280 return;
2281
Ville Syrjälä773538e82014-09-04 14:54:56 +03002282 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002283
Jesse Barnes453c5422013-03-28 09:55:41 -07002284 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002285 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002286
Jani Nikulabf13e812013-09-06 07:40:05 +03002287 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002288
2289 I915_WRITE(pp_ctrl_reg, pp);
2290 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002291
Ville Syrjälä773538e82014-09-04 14:54:56 +03002292 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002293
Paulo Zanonidce56b32013-12-19 14:29:40 -02002294 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002295 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002296}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002297
Jani Nikula1250d102014-08-12 17:11:39 +03002298/* Disable backlight PP control and backlight PWM. */
2299void intel_edp_backlight_off(struct intel_dp *intel_dp)
2300{
2301 if (!is_edp(intel_dp))
2302 return;
2303
2304 DRM_DEBUG_KMS("\n");
2305
2306 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002307 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002308}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002309
Jani Nikula73580fb72014-08-12 17:11:41 +03002310/*
2311 * Hook for controlling the panel power control backlight through the bl_power
2312 * sysfs attribute. Take care to handle multiple calls.
2313 */
2314static void intel_edp_backlight_power(struct intel_connector *connector,
2315 bool enable)
2316{
2317 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002318 bool is_enabled;
2319
Ville Syrjälä773538e82014-09-04 14:54:56 +03002320 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002321 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002322 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002323
2324 if (is_enabled == enable)
2325 return;
2326
Jani Nikula23ba9372014-08-27 14:08:43 +03002327 DRM_DEBUG_KMS("panel power control backlight %s\n",
2328 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002329
2330 if (enable)
2331 _intel_edp_backlight_on(intel_dp);
2332 else
2333 _intel_edp_backlight_off(intel_dp);
2334}
2335
Ville Syrjälä64e10772015-10-29 21:26:01 +02002336static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2337{
2338 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2339 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2340 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2341
2342 I915_STATE_WARN(cur_state != state,
2343 "DP port %c state assertion failure (expected %s, current %s)\n",
2344 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002345 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002346}
2347#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2348
2349static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2350{
2351 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2352
2353 I915_STATE_WARN(cur_state != state,
2354 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002355 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002356}
2357#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2358#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2359
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002360static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2361 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002362{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002363 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002364 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002365
Ville Syrjälä64e10772015-10-29 21:26:01 +02002366 assert_pipe_disabled(dev_priv, crtc->pipe);
2367 assert_dp_port_disabled(intel_dp);
2368 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002369
Ville Syrjäläabfce942015-10-29 21:26:03 +02002370 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002371 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002372
2373 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2374
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002375 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002376 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2377 else
2378 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2379
2380 I915_WRITE(DP_A, intel_dp->DP);
2381 POSTING_READ(DP_A);
2382 udelay(500);
2383
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002384 /*
2385 * [DevILK] Work around required when enabling DP PLL
2386 * while a pipe is enabled going to FDI:
2387 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2388 * 2. Program DP PLL enable
2389 */
2390 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002391 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002392
Daniel Vetter07679352012-09-06 22:15:42 +02002393 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002394
Daniel Vetter07679352012-09-06 22:15:42 +02002395 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002396 POSTING_READ(DP_A);
2397 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002398}
2399
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002400static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002401{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002402 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002403 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002405
Ville Syrjälä64e10772015-10-29 21:26:01 +02002406 assert_pipe_disabled(dev_priv, crtc->pipe);
2407 assert_dp_port_disabled(intel_dp);
2408 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002409
Ville Syrjäläabfce942015-10-29 21:26:03 +02002410 DRM_DEBUG_KMS("disabling eDP PLL\n");
2411
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002412 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002413
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002414 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002415 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002416 udelay(200);
2417}
2418
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002419/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002420void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002421{
2422 int ret, i;
2423
2424 /* Should have a valid DPCD by this point */
2425 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2426 return;
2427
2428 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002429 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2430 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002431 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002432 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2433
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002434 /*
2435 * When turning on, we need to retry for 1ms to give the sink
2436 * time to wake up.
2437 */
2438 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002439 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2440 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002441 if (ret == 1)
2442 break;
2443 msleep(1);
2444 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002445
2446 if (ret == 1 && lspcon->active)
2447 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002448 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002449
2450 if (ret != 1)
2451 DRM_DEBUG_KMS("failed to %s sink power state\n",
2452 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002453}
2454
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002455static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2456 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002457{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002458 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002459 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002460 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002461 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002462 enum intel_display_power_domain power_domain;
2463 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002464 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002465
2466 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002467 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002468 return false;
2469
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002470 ret = false;
2471
Imre Deak6d129be2014-03-05 16:20:54 +02002472 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002473
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002474 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002475 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002476
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002477 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002478 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002479 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002480 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002481
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002482 for_each_pipe(dev_priv, p) {
2483 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2484 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2485 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002486 ret = true;
2487
2488 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002489 }
2490 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002491
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002492 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002493 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002494 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002495 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2496 } else {
2497 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002498 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002499
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002500 ret = true;
2501
2502out:
2503 intel_display_power_put(dev_priv, power_domain);
2504
2505 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002506}
2507
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002508static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002509 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002510{
2511 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002512 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002513 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002514 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002515 enum port port = dp_to_dig_port(intel_dp)->port;
2516 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002517
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002518 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002519
2520 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002521
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002522 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002523 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2524
2525 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002526 flags |= DRM_MODE_FLAG_PHSYNC;
2527 else
2528 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002529
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002530 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002531 flags |= DRM_MODE_FLAG_PVSYNC;
2532 else
2533 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002534 } else {
2535 if (tmp & DP_SYNC_HS_HIGH)
2536 flags |= DRM_MODE_FLAG_PHSYNC;
2537 else
2538 flags |= DRM_MODE_FLAG_NHSYNC;
2539
2540 if (tmp & DP_SYNC_VS_HIGH)
2541 flags |= DRM_MODE_FLAG_PVSYNC;
2542 else
2543 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002544 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002545
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002546 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002547
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002548 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002549 pipe_config->limited_color_range = true;
2550
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002551 pipe_config->lane_count =
2552 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2553
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002554 intel_dp_get_m_n(crtc, pipe_config);
2555
Ville Syrjälä18442d02013-09-13 16:00:08 +03002556 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002557 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002558 pipe_config->port_clock = 162000;
2559 else
2560 pipe_config->port_clock = 270000;
2561 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002562
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002563 pipe_config->base.adjusted_mode.crtc_clock =
2564 intel_dotclock_calculate(pipe_config->port_clock,
2565 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002566
Jani Nikula6aa23e62016-03-24 17:50:20 +02002567 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2568 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002569 /*
2570 * This is a big fat ugly hack.
2571 *
2572 * Some machines in UEFI boot mode provide us a VBT that has 18
2573 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2574 * unknown we fail to light up. Yet the same BIOS boots up with
2575 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2576 * max, not what it tells us to use.
2577 *
2578 * Note: This will still be broken if the eDP panel is not lit
2579 * up by the BIOS, and thus we can't get the mode at module
2580 * load.
2581 */
2582 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002583 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2584 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002585 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002586}
2587
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002588static void intel_disable_dp(struct intel_encoder *encoder,
2589 struct intel_crtc_state *old_crtc_state,
2590 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002591{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002592 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002593 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002594
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002595 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002596 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002597
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002598 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002599 intel_psr_disable(intel_dp);
2600
Daniel Vetter6cb49832012-05-20 17:14:50 +02002601 /* Make sure the panel is off before trying to change the mode. But also
2602 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002603 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002604 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002605 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002606 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002607
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002608 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002609 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002610 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002611}
2612
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002613static void ilk_post_disable_dp(struct intel_encoder *encoder,
2614 struct intel_crtc_state *old_crtc_state,
2615 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002616{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002617 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002618 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002619
Ville Syrjälä49277c32014-03-31 18:21:26 +03002620 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002621
2622 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002623 if (port == PORT_A)
2624 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002625}
2626
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002627static void vlv_post_disable_dp(struct intel_encoder *encoder,
2628 struct intel_crtc_state *old_crtc_state,
2629 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002630{
2631 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2632
2633 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002634}
2635
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002636static void chv_post_disable_dp(struct intel_encoder *encoder,
2637 struct intel_crtc_state *old_crtc_state,
2638 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002639{
2640 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002641 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002642 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002643
2644 intel_dp_link_down(intel_dp);
2645
Ville Syrjäläa5805162015-05-26 20:42:30 +03002646 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002647
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002648 /* Assert data lane reset */
2649 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002650
Ville Syrjäläa5805162015-05-26 20:42:30 +03002651 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002652}
2653
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002654static void
2655_intel_dp_set_link_train(struct intel_dp *intel_dp,
2656 uint32_t *DP,
2657 uint8_t dp_train_pat)
2658{
2659 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2660 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002661 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002662 enum port port = intel_dig_port->port;
2663
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002664 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2665 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2666 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2667
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002668 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002669 uint32_t temp = I915_READ(DP_TP_CTL(port));
2670
2671 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2672 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2673 else
2674 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2675
2676 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2677 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2678 case DP_TRAINING_PATTERN_DISABLE:
2679 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2680
2681 break;
2682 case DP_TRAINING_PATTERN_1:
2683 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2684 break;
2685 case DP_TRAINING_PATTERN_2:
2686 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2687 break;
2688 case DP_TRAINING_PATTERN_3:
2689 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2690 break;
2691 }
2692 I915_WRITE(DP_TP_CTL(port), temp);
2693
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002694 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002695 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002696 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2697
2698 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2699 case DP_TRAINING_PATTERN_DISABLE:
2700 *DP |= DP_LINK_TRAIN_OFF_CPT;
2701 break;
2702 case DP_TRAINING_PATTERN_1:
2703 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2704 break;
2705 case DP_TRAINING_PATTERN_2:
2706 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2707 break;
2708 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002709 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002710 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2711 break;
2712 }
2713
2714 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002715 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002716 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2717 else
2718 *DP &= ~DP_LINK_TRAIN_MASK;
2719
2720 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2721 case DP_TRAINING_PATTERN_DISABLE:
2722 *DP |= DP_LINK_TRAIN_OFF;
2723 break;
2724 case DP_TRAINING_PATTERN_1:
2725 *DP |= DP_LINK_TRAIN_PAT_1;
2726 break;
2727 case DP_TRAINING_PATTERN_2:
2728 *DP |= DP_LINK_TRAIN_PAT_2;
2729 break;
2730 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002731 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002732 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2733 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002734 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002735 *DP |= DP_LINK_TRAIN_PAT_2;
2736 }
2737 break;
2738 }
2739 }
2740}
2741
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002742static void intel_dp_enable_port(struct intel_dp *intel_dp,
2743 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002744{
2745 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002746 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002747
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002748 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002749
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002750 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002751
2752 /*
2753 * Magic for VLV/CHV. We _must_ first set up the register
2754 * without actually enabling the port, and then do another
2755 * write to enable the port. Otherwise link training will
2756 * fail when the power sequencer is freshly used for this port.
2757 */
2758 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002759 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002760 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002761
2762 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2763 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002764}
2765
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002766static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002767 struct intel_crtc_state *pipe_config,
2768 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002769{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002770 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2771 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002772 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002773 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002774 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002775 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002776
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002777 if (WARN_ON(dp_reg & DP_PORT_EN))
2778 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002779
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002780 pps_lock(intel_dp);
2781
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002782 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002783 vlv_init_panel_power_sequencer(intel_dp);
2784
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002785 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002786
2787 edp_panel_vdd_on(intel_dp);
2788 edp_panel_on(intel_dp);
2789 edp_panel_vdd_off(intel_dp, true);
2790
2791 pps_unlock(intel_dp);
2792
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002793 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002794 unsigned int lane_mask = 0x0;
2795
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002796 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002797 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002798
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002799 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2800 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002801 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002802
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002803 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2804 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002805 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002806
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002807 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002808 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002809 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002810 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002811 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002812}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002813
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002814static void g4x_enable_dp(struct intel_encoder *encoder,
2815 struct intel_crtc_state *pipe_config,
2816 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002817{
Jani Nikula828f5c62013-09-05 16:44:45 +03002818 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2819
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002820 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002821 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002822}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002823
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002824static void vlv_enable_dp(struct intel_encoder *encoder,
2825 struct intel_crtc_state *pipe_config,
2826 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002827{
Jani Nikula828f5c62013-09-05 16:44:45 +03002828 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2829
Daniel Vetter4be73782014-01-17 14:39:48 +01002830 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002831 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002832}
2833
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002834static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2835 struct intel_crtc_state *pipe_config,
2836 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002837{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002838 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002839 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002840
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002841 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002842
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002843 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002844 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002845 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002846}
2847
Ville Syrjälä83b84592014-10-16 21:29:51 +03002848static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2849{
2850 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002851 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002852 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002853 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002854
2855 edp_panel_vdd_off_sync(intel_dp);
2856
2857 /*
2858 * VLV seems to get confused when multiple power seqeuencers
2859 * have the same port selected (even if only one has power/vdd
2860 * enabled). The failure manifests as vlv_wait_port_ready() failing
2861 * CHV on the other hand doesn't seem to mind having the same port
2862 * selected in multiple power seqeuencers, but let's clear the
2863 * port select always when logically disconnecting a power sequencer
2864 * from a port.
2865 */
2866 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2867 pipe_name(pipe), port_name(intel_dig_port->port));
2868 I915_WRITE(pp_on_reg, 0);
2869 POSTING_READ(pp_on_reg);
2870
2871 intel_dp->pps_pipe = INVALID_PIPE;
2872}
2873
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002874static void vlv_steal_power_sequencer(struct drm_device *dev,
2875 enum pipe pipe)
2876{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002877 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002878 struct intel_encoder *encoder;
2879
2880 lockdep_assert_held(&dev_priv->pps_mutex);
2881
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002882 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2883 return;
2884
Jani Nikula19c80542015-12-16 12:48:16 +02002885 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002886 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002887 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002888
2889 if (encoder->type != INTEL_OUTPUT_EDP)
2890 continue;
2891
2892 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002893 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002894
2895 if (intel_dp->pps_pipe != pipe)
2896 continue;
2897
2898 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002899 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002900
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002901 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002902 "stealing pipe %c power sequencer from active eDP port %c\n",
2903 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002904
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002905 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002906 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002907 }
2908}
2909
2910static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2911{
2912 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2913 struct intel_encoder *encoder = &intel_dig_port->base;
2914 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002915 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002916 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002917
2918 lockdep_assert_held(&dev_priv->pps_mutex);
2919
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002920 if (!is_edp(intel_dp))
2921 return;
2922
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002923 if (intel_dp->pps_pipe == crtc->pipe)
2924 return;
2925
2926 /*
2927 * If another power sequencer was being used on this
2928 * port previously make sure to turn off vdd there while
2929 * we still have control of it.
2930 */
2931 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002932 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002933
2934 /*
2935 * We may be stealing the power
2936 * sequencer from another port.
2937 */
2938 vlv_steal_power_sequencer(dev, crtc->pipe);
2939
2940 /* now it's all ours */
2941 intel_dp->pps_pipe = crtc->pipe;
2942
2943 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2944 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2945
2946 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002947 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2948 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002949}
2950
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002951static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2952 struct intel_crtc_state *pipe_config,
2953 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002954{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002955 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002956
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002957 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002958}
2959
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002960static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2961 struct intel_crtc_state *pipe_config,
2962 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002963{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002964 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002965
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002966 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002967}
2968
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002969static void chv_pre_enable_dp(struct intel_encoder *encoder,
2970 struct intel_crtc_state *pipe_config,
2971 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002972{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002973 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002974
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002975 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002976
2977 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002978 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002979}
2980
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002981static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2982 struct intel_crtc_state *pipe_config,
2983 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002984{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002985 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002986
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002987 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002988}
2989
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002990static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2991 struct intel_crtc_state *pipe_config,
2992 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002993{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002994 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002995}
2996
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002997/*
2998 * Fetch AUX CH registers 0x202 - 0x207 which contain
2999 * link status information
3000 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003001bool
Keith Packard93f62da2011-11-01 19:45:03 -07003002intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003003{
Lyude9f085eb2016-04-13 10:58:33 -04003004 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3005 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003006}
3007
Paulo Zanoni11002442014-06-13 18:45:41 -03003008/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003009uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003010intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003011{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003012 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003013 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003014
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003015 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303016 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003017 else if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02003018 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303019 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003020 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003021 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303022 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003023 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303024 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003025 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303026 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003027 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303028 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003029}
3030
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003031uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003032intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3033{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003034 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003035 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003036
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003037 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003038 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3039 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3040 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3041 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3042 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3043 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3044 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303045 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3046 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003047 default:
3048 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3049 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003050 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003051 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303052 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3053 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3054 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3055 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3056 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3057 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3058 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003059 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303060 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003061 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003062 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003063 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303064 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3065 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3066 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3067 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3068 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3069 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3070 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003071 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303072 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003073 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003074 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003075 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303076 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3077 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3078 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3079 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3080 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003081 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303082 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003083 }
3084 } else {
3085 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303086 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3087 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3088 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3089 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3090 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3091 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3092 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003093 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303094 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003095 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003096 }
3097}
3098
Daniel Vetter5829975c2015-04-16 11:36:52 +02003099static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003100{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003101 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003102 unsigned long demph_reg_value, preemph_reg_value,
3103 uniqtranscale_reg_value;
3104 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003105
3106 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003108 preemph_reg_value = 0x0004000;
3109 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003111 demph_reg_value = 0x2B405555;
3112 uniqtranscale_reg_value = 0x552AB83A;
3113 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303114 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003115 demph_reg_value = 0x2B404040;
3116 uniqtranscale_reg_value = 0x5548B83A;
3117 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303118 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003119 demph_reg_value = 0x2B245555;
3120 uniqtranscale_reg_value = 0x5560B83A;
3121 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303122 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003123 demph_reg_value = 0x2B405555;
3124 uniqtranscale_reg_value = 0x5598DA3A;
3125 break;
3126 default:
3127 return 0;
3128 }
3129 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303130 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003131 preemph_reg_value = 0x0002000;
3132 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303133 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003134 demph_reg_value = 0x2B404040;
3135 uniqtranscale_reg_value = 0x5552B83A;
3136 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003138 demph_reg_value = 0x2B404848;
3139 uniqtranscale_reg_value = 0x5580B83A;
3140 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003142 demph_reg_value = 0x2B404040;
3143 uniqtranscale_reg_value = 0x55ADDA3A;
3144 break;
3145 default:
3146 return 0;
3147 }
3148 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003150 preemph_reg_value = 0x0000000;
3151 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303152 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003153 demph_reg_value = 0x2B305555;
3154 uniqtranscale_reg_value = 0x5570B83A;
3155 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003157 demph_reg_value = 0x2B2B4040;
3158 uniqtranscale_reg_value = 0x55ADDA3A;
3159 break;
3160 default:
3161 return 0;
3162 }
3163 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303164 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003165 preemph_reg_value = 0x0006000;
3166 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303167 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003168 demph_reg_value = 0x1B405555;
3169 uniqtranscale_reg_value = 0x55ADDA3A;
3170 break;
3171 default:
3172 return 0;
3173 }
3174 break;
3175 default:
3176 return 0;
3177 }
3178
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003179 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3180 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003181
3182 return 0;
3183}
3184
Daniel Vetter5829975c2015-04-16 11:36:52 +02003185static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003186{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003187 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3188 u32 deemph_reg_value, margin_reg_value;
3189 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003190 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003191
3192 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003194 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003196 deemph_reg_value = 128;
3197 margin_reg_value = 52;
3198 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003200 deemph_reg_value = 128;
3201 margin_reg_value = 77;
3202 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003204 deemph_reg_value = 128;
3205 margin_reg_value = 102;
3206 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303207 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003208 deemph_reg_value = 128;
3209 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003210 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003211 break;
3212 default:
3213 return 0;
3214 }
3215 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303216 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003217 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003219 deemph_reg_value = 85;
3220 margin_reg_value = 78;
3221 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003223 deemph_reg_value = 85;
3224 margin_reg_value = 116;
3225 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303226 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003227 deemph_reg_value = 85;
3228 margin_reg_value = 154;
3229 break;
3230 default:
3231 return 0;
3232 }
3233 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303234 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003235 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303236 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003237 deemph_reg_value = 64;
3238 margin_reg_value = 104;
3239 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303240 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003241 deemph_reg_value = 64;
3242 margin_reg_value = 154;
3243 break;
3244 default:
3245 return 0;
3246 }
3247 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303248 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003249 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003251 deemph_reg_value = 43;
3252 margin_reg_value = 154;
3253 break;
3254 default:
3255 return 0;
3256 }
3257 break;
3258 default:
3259 return 0;
3260 }
3261
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003262 chv_set_phy_signal_level(encoder, deemph_reg_value,
3263 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003264
3265 return 0;
3266}
3267
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003268static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003269gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003270{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003271 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003272
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003273 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303274 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003275 default:
3276 signal_levels |= DP_VOLTAGE_0_4;
3277 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303278 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003279 signal_levels |= DP_VOLTAGE_0_6;
3280 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003282 signal_levels |= DP_VOLTAGE_0_8;
3283 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003285 signal_levels |= DP_VOLTAGE_1_2;
3286 break;
3287 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003288 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003290 default:
3291 signal_levels |= DP_PRE_EMPHASIS_0;
3292 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003294 signal_levels |= DP_PRE_EMPHASIS_3_5;
3295 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303296 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003297 signal_levels |= DP_PRE_EMPHASIS_6;
3298 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003300 signal_levels |= DP_PRE_EMPHASIS_9_5;
3301 break;
3302 }
3303 return signal_levels;
3304}
3305
Zhenyu Wange3421a12010-04-08 09:43:27 +08003306/* Gen6's DP voltage swing and pre-emphasis control */
3307static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003308gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003309{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003310 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:
3314 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003315 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303316 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003317 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3319 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003320 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003323 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3325 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003326 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003327 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003328 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3329 "0x%x\n", signal_levels);
3330 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003331 }
3332}
3333
Keith Packard1a2eb462011-11-16 16:26:07 -08003334/* Gen7's DP voltage swing and pre-emphasis control */
3335static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003336gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003337{
3338 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3339 DP_TRAIN_PRE_EMPHASIS_MASK);
3340 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303341 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003342 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303343 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003344 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303345 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003346 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3347
Sonika Jindalbd600182014-08-08 16:23:41 +05303348 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003349 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303350 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003351 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3352
Sonika Jindalbd600182014-08-08 16:23:41 +05303353 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003354 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303355 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003356 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3357
3358 default:
3359 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3360 "0x%x\n", signal_levels);
3361 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3362 }
3363}
3364
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003365void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003366intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003367{
3368 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003369 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003370 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003371 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003372 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003373 uint8_t train_set = intel_dp->train_set[0];
3374
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003375 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003376 signal_levels = ddi_signal_levels(intel_dp);
3377
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003378 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003379 signal_levels = 0;
3380 else
3381 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003382 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003383 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003384 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003385 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003386 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003387 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003388 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003389 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003390 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003391 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3392 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003393 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003394 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3395 }
3396
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303397 if (mask)
3398 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3399
3400 DRM_DEBUG_KMS("Using vswing level %d\n",
3401 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3402 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3403 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3404 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003405
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003406 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003407
3408 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3409 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003410}
3411
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003412void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003413intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3414 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003415{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003416 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003417 struct drm_i915_private *dev_priv =
3418 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003419
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003420 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003421
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003422 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003423 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003424}
3425
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003426void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003427{
3428 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3429 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003430 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003431 enum port port = intel_dig_port->port;
3432 uint32_t val;
3433
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003434 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003435 return;
3436
3437 val = I915_READ(DP_TP_CTL(port));
3438 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3439 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3440 I915_WRITE(DP_TP_CTL(port), val);
3441
3442 /*
3443 * On PORT_A we can have only eDP in SST mode. There the only reason
3444 * we need to set idle transmission mode is to work around a HW issue
3445 * where we enable the pipe while not in idle link-training mode.
3446 * In this case there is requirement to wait for a minimum number of
3447 * idle patterns to be sent.
3448 */
3449 if (port == PORT_A)
3450 return;
3451
Chris Wilsona7670172016-06-30 15:33:10 +01003452 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3453 DP_TP_STATUS_IDLE_DONE,
3454 DP_TP_STATUS_IDLE_DONE,
3455 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003456 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3457}
3458
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003459static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003460intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003461{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003462 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003463 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003464 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003465 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003466 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003467 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003468
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003469 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003470 return;
3471
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003472 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003473 return;
3474
Zhao Yakui28c97732009-10-09 11:39:41 +08003475 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003476
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003477 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003478 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003479 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003480 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003481 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003482 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003483 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3484 else
3485 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003486 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003487 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003488 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003489 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003490
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003491 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3492 I915_WRITE(intel_dp->output_reg, DP);
3493 POSTING_READ(intel_dp->output_reg);
3494
3495 /*
3496 * HW workaround for IBX, we need to move the port
3497 * to transcoder A after disabling it to allow the
3498 * matching HDMI port to be enabled on transcoder A.
3499 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003500 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003501 /*
3502 * We get CPU/PCH FIFO underruns on the other pipe when
3503 * doing the workaround. Sweep them under the rug.
3504 */
3505 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3506 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3507
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003508 /* always enable with pattern 1 (as per spec) */
3509 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3510 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3511 I915_WRITE(intel_dp->output_reg, DP);
3512 POSTING_READ(intel_dp->output_reg);
3513
3514 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003515 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003516 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003517
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003518 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003519 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3520 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003521 }
3522
Keith Packardf01eca22011-09-28 16:48:10 -07003523 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003524
3525 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003526}
3527
Imre Deak24e807e2016-10-24 19:33:28 +03003528bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003529intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003530{
Lyude9f085eb2016-04-13 10:58:33 -04003531 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3532 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003533 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003534
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003535 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003536
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003537 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3538}
3539
3540static bool
3541intel_edp_init_dpcd(struct intel_dp *intel_dp)
3542{
3543 struct drm_i915_private *dev_priv =
3544 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3545
3546 /* this function is meant to be called only once */
3547 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3548
3549 if (!intel_dp_read_dpcd(intel_dp))
3550 return false;
3551
Imre Deak12a47a422016-10-24 19:33:29 +03003552 intel_dp_read_desc(intel_dp);
3553
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003554 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3555 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3556 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3557
3558 /* Check if the panel supports PSR */
3559 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3560 intel_dp->psr_dpcd,
3561 sizeof(intel_dp->psr_dpcd));
3562 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3563 dev_priv->psr.sink_support = true;
3564 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3565 }
3566
3567 if (INTEL_GEN(dev_priv) >= 9 &&
3568 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3569 uint8_t frame_sync_cap;
3570
3571 dev_priv->psr.sink_support = true;
3572 drm_dp_dpcd_read(&intel_dp->aux,
3573 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3574 &frame_sync_cap, 1);
3575 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3576 /* PSR2 needs frame sync as well */
3577 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3578 DRM_DEBUG_KMS("PSR2 %s on sink",
3579 dev_priv->psr.psr2_support ? "supported" : "not supported");
3580 }
3581
3582 /* Read the eDP Display control capabilities registers */
3583 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3584 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003585 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3586 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003587 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3588 intel_dp->edp_dpcd);
3589
3590 /* Intermediate frequency support */
3591 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3592 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3593 int i;
3594
3595 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3596 sink_rates, sizeof(sink_rates));
3597
3598 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3599 int val = le16_to_cpu(sink_rates[i]);
3600
3601 if (val == 0)
3602 break;
3603
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003604 /* Value read multiplied by 200kHz gives the per-lane
3605 * link rate in kHz. The source rates are, however,
3606 * stored in terms of LS_Clk kHz. The full conversion
3607 * back to symbols is
3608 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3609 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003610 intel_dp->sink_rates[i] = (val * 200) / 10;
3611 }
3612 intel_dp->num_sink_rates = i;
3613 }
3614
3615 return true;
3616}
3617
3618
3619static bool
3620intel_dp_get_dpcd(struct intel_dp *intel_dp)
3621{
3622 if (!intel_dp_read_dpcd(intel_dp))
3623 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003624
Lyude9f085eb2016-04-13 10:58:33 -04003625 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3626 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303627 return false;
3628
3629 /*
3630 * Sink count can change between short pulse hpd hence
3631 * a member variable in intel_dp will track any changes
3632 * between short pulse interrupts.
3633 */
3634 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3635
3636 /*
3637 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3638 * a dongle is present but no display. Unless we require to know
3639 * if a dongle is present or not, we don't need to update
3640 * downstream port information. So, an early return here saves
3641 * time from performing other operations which are not required.
3642 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303643 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303644 return false;
3645
Imre Deakc726ad02016-10-24 19:33:24 +03003646 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003647 return true; /* native DP sink */
3648
3649 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3650 return true; /* no per-port downstream info */
3651
Lyude9f085eb2016-04-13 10:58:33 -04003652 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3653 intel_dp->downstream_ports,
3654 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003655 return false; /* downstream port status fetch failed */
3656
3657 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003658}
3659
Dave Airlie0e32b392014-05-02 14:02:48 +10003660static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003661intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003662{
3663 u8 buf[1];
3664
Nathan Schulte7cc96132016-03-15 10:14:05 -05003665 if (!i915.enable_dp_mst)
3666 return false;
3667
Dave Airlie0e32b392014-05-02 14:02:48 +10003668 if (!intel_dp->can_mst)
3669 return false;
3670
3671 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3672 return false;
3673
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003674 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3675 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003676
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003677 return buf[0] & DP_MST_CAP;
3678}
3679
3680static void
3681intel_dp_configure_mst(struct intel_dp *intel_dp)
3682{
3683 if (!i915.enable_dp_mst)
3684 return;
3685
3686 if (!intel_dp->can_mst)
3687 return;
3688
3689 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3690
3691 if (intel_dp->is_mst)
3692 DRM_DEBUG_KMS("Sink is MST capable\n");
3693 else
3694 DRM_DEBUG_KMS("Sink is not MST capable\n");
3695
3696 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3697 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003698}
3699
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003700static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003701{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003702 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003703 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003704 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003705 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003706 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003707 int count = 0;
3708 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003709
3710 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003711 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003712 ret = -EIO;
3713 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003714 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003715
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003716 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003717 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003718 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003719 ret = -EIO;
3720 goto out;
3721 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003722
Rodrigo Vivic6297842015-11-05 10:50:20 -08003723 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003724 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003725
3726 if (drm_dp_dpcd_readb(&intel_dp->aux,
3727 DP_TEST_SINK_MISC, &buf) < 0) {
3728 ret = -EIO;
3729 goto out;
3730 }
3731 count = buf & DP_TEST_COUNT_MASK;
3732 } while (--attempts && count);
3733
3734 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003735 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003736 ret = -ETIMEDOUT;
3737 }
3738
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003739 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003740 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003741 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003742}
3743
3744static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3745{
3746 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003747 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003748 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3749 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003750 int ret;
3751
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003752 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3753 return -EIO;
3754
3755 if (!(buf & DP_TEST_CRC_SUPPORTED))
3756 return -ENOTTY;
3757
3758 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3759 return -EIO;
3760
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003761 if (buf & DP_TEST_SINK_START) {
3762 ret = intel_dp_sink_crc_stop(intel_dp);
3763 if (ret)
3764 return ret;
3765 }
3766
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003767 hsw_disable_ips(intel_crtc);
3768
3769 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3770 buf | DP_TEST_SINK_START) < 0) {
3771 hsw_enable_ips(intel_crtc);
3772 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003773 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003774
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003775 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003776 return 0;
3777}
3778
3779int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3780{
3781 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003782 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003783 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3784 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003785 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003786 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003787
3788 ret = intel_dp_sink_crc_start(intel_dp);
3789 if (ret)
3790 return ret;
3791
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003792 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003793 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003794
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003795 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003796 DP_TEST_SINK_MISC, &buf) < 0) {
3797 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003798 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003799 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003800 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003801
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003802 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003803
3804 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003805 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3806 ret = -ETIMEDOUT;
3807 goto stop;
3808 }
3809
3810 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3811 ret = -EIO;
3812 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003813 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003814
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003815stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003816 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003817 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003818}
3819
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003820static bool
3821intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3822{
Lyude9f085eb2016-04-13 10:58:33 -04003823 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003824 DP_DEVICE_SERVICE_IRQ_VECTOR,
3825 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003826}
3827
Dave Airlie0e32b392014-05-02 14:02:48 +10003828static bool
3829intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3830{
3831 int ret;
3832
Lyude9f085eb2016-04-13 10:58:33 -04003833 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003834 DP_SINK_COUNT_ESI,
3835 sink_irq_vector, 14);
3836 if (ret != 14)
3837 return false;
3838
3839 return true;
3840}
3841
Todd Previtec5d5ab72015-04-15 08:38:38 -07003842static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003843{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003844 uint8_t test_result = DP_TEST_ACK;
3845 return test_result;
3846}
3847
3848static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3849{
3850 uint8_t test_result = DP_TEST_NAK;
3851 return test_result;
3852}
3853
3854static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3855{
3856 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003857 struct intel_connector *intel_connector = intel_dp->attached_connector;
3858 struct drm_connector *connector = &intel_connector->base;
3859
3860 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003861 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003862 intel_dp->aux.i2c_defer_count > 6) {
3863 /* Check EDID read for NACKs, DEFERs and corruption
3864 * (DP CTS 1.2 Core r1.1)
3865 * 4.2.2.4 : Failed EDID read, I2C_NAK
3866 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3867 * 4.2.2.6 : EDID corruption detected
3868 * Use failsafe mode for all cases
3869 */
3870 if (intel_dp->aux.i2c_nack_count > 0 ||
3871 intel_dp->aux.i2c_defer_count > 0)
3872 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3873 intel_dp->aux.i2c_nack_count,
3874 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003875 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07003876 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303877 struct edid *block = intel_connector->detect_edid;
3878
3879 /* We have to write the checksum
3880 * of the last block read
3881 */
3882 block += intel_connector->detect_edid->extensions;
3883
Todd Previte559be302015-05-04 07:48:20 -07003884 if (!drm_dp_dpcd_write(&intel_dp->aux,
3885 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303886 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003887 1))
Todd Previte559be302015-05-04 07:48:20 -07003888 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3889
3890 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navarec1617ab2016-12-09 16:22:50 -08003891 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD;
Todd Previte559be302015-05-04 07:48:20 -07003892 }
3893
3894 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08003895 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07003896
Todd Previtec5d5ab72015-04-15 08:38:38 -07003897 return test_result;
3898}
3899
3900static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3901{
3902 uint8_t test_result = DP_TEST_NAK;
3903 return test_result;
3904}
3905
3906static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3907{
3908 uint8_t response = DP_TEST_NAK;
3909 uint8_t rxdata = 0;
3910 int status = 0;
3911
Todd Previtec5d5ab72015-04-15 08:38:38 -07003912 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3913 if (status <= 0) {
3914 DRM_DEBUG_KMS("Could not read test request from sink\n");
3915 goto update_status;
3916 }
3917
3918 switch (rxdata) {
3919 case DP_TEST_LINK_TRAINING:
3920 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003921 intel_dp->compliance.test_type = DP_TEST_LINK_TRAINING;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003922 response = intel_dp_autotest_link_training(intel_dp);
3923 break;
3924 case DP_TEST_LINK_VIDEO_PATTERN:
3925 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003926 intel_dp->compliance.test_type = DP_TEST_LINK_VIDEO_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003927 response = intel_dp_autotest_video_pattern(intel_dp);
3928 break;
3929 case DP_TEST_LINK_EDID_READ:
3930 DRM_DEBUG_KMS("EDID test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003931 intel_dp->compliance.test_type = DP_TEST_LINK_EDID_READ;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003932 response = intel_dp_autotest_edid(intel_dp);
3933 break;
3934 case DP_TEST_LINK_PHY_TEST_PATTERN:
3935 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003936 intel_dp->compliance.test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003937 response = intel_dp_autotest_phy_pattern(intel_dp);
3938 break;
3939 default:
3940 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3941 break;
3942 }
3943
3944update_status:
3945 status = drm_dp_dpcd_write(&intel_dp->aux,
3946 DP_TEST_RESPONSE,
3947 &response, 1);
3948 if (status <= 0)
3949 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003950}
3951
Dave Airlie0e32b392014-05-02 14:02:48 +10003952static int
3953intel_dp_check_mst_status(struct intel_dp *intel_dp)
3954{
3955 bool bret;
3956
3957 if (intel_dp->is_mst) {
3958 u8 esi[16] = { 0 };
3959 int ret = 0;
3960 int retry;
3961 bool handled;
3962 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3963go_again:
3964 if (bret == true) {
3965
3966 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003967 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003968 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003969 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3970 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003971 intel_dp_stop_link_train(intel_dp);
3972 }
3973
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003974 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003975 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3976
3977 if (handled) {
3978 for (retry = 0; retry < 3; retry++) {
3979 int wret;
3980 wret = drm_dp_dpcd_write(&intel_dp->aux,
3981 DP_SINK_COUNT_ESI+1,
3982 &esi[1], 3);
3983 if (wret == 3) {
3984 break;
3985 }
3986 }
3987
3988 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3989 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003990 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003991 goto go_again;
3992 }
3993 } else
3994 ret = 0;
3995
3996 return ret;
3997 } else {
3998 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3999 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4000 intel_dp->is_mst = false;
4001 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4002 /* send a hotplug event */
4003 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4004 }
4005 }
4006 return -EINVAL;
4007}
4008
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304009static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004010intel_dp_retrain_link(struct intel_dp *intel_dp)
4011{
4012 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4013 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4014 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4015
4016 /* Suppress underruns caused by re-training */
4017 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4018 if (crtc->config->has_pch_encoder)
4019 intel_set_pch_fifo_underrun_reporting(dev_priv,
4020 intel_crtc_pch_transcoder(crtc), false);
4021
4022 intel_dp_start_link_train(intel_dp);
4023 intel_dp_stop_link_train(intel_dp);
4024
4025 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004026 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004027
4028 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4029 if (crtc->config->has_pch_encoder)
4030 intel_set_pch_fifo_underrun_reporting(dev_priv,
4031 intel_crtc_pch_transcoder(crtc), true);
4032}
4033
4034static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304035intel_dp_check_link_status(struct intel_dp *intel_dp)
4036{
4037 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4038 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4039 u8 link_status[DP_LINK_STATUS_SIZE];
4040
4041 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4042
4043 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4044 DRM_ERROR("Failed to get link status\n");
4045 return;
4046 }
4047
4048 if (!intel_encoder->base.crtc)
4049 return;
4050
4051 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4052 return;
4053
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004054 /* FIXME: we need to synchronize this sort of stuff with hardware
4055 * readout */
4056 if (WARN_ON_ONCE(!intel_dp->lane_count))
4057 return;
4058
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304059 /* if link training is requested we should perform it always */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004060 if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304061 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4062 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4063 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004064
4065 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304066 }
4067}
4068
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004069/*
4070 * According to DP spec
4071 * 5.1.2:
4072 * 1. Read DPCD
4073 * 2. Configure link according to Receiver Capabilities
4074 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4075 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304076 *
4077 * intel_dp_short_pulse - handles short pulse interrupts
4078 * when full detection is not required.
4079 * Returns %true if short pulse is handled and full detection
4080 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004081 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304082static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304083intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004084{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004085 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004086 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304087 u8 old_sink_count = intel_dp->sink_count;
4088 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004089
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304090 /*
4091 * Clearing compliance test variables to allow capturing
4092 * of values for next automated test request.
4093 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004094 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304095
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304096 /*
4097 * Now read the DPCD to see if it's actually running
4098 * If the current value of sink count doesn't match with
4099 * the value that was stored earlier or dpcd read failed
4100 * we need to do full detection
4101 */
4102 ret = intel_dp_get_dpcd(intel_dp);
4103
4104 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4105 /* No need to proceed if we are going to do full detect */
4106 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004107 }
4108
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004109 /* Try to read the source of the interrupt */
4110 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004111 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4112 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004113 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004114 drm_dp_dpcd_writeb(&intel_dp->aux,
4115 DP_DEVICE_SERVICE_IRQ_VECTOR,
4116 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004117
4118 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004119 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004120 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4121 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4122 }
4123
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304124 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4125 intel_dp_check_link_status(intel_dp);
4126 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304127
4128 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004129}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004130
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004131/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004132static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004133intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004134{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004135 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004136 uint8_t type;
4137
4138 if (!intel_dp_get_dpcd(intel_dp))
4139 return connector_status_disconnected;
4140
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304141 if (is_edp(intel_dp))
4142 return connector_status_connected;
4143
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004144 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004145 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004146 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004147
4148 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004149 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4150 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004151
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304152 return intel_dp->sink_count ?
4153 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004154 }
4155
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004156 if (intel_dp_can_mst(intel_dp))
4157 return connector_status_connected;
4158
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004159 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004160 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004161 return connector_status_connected;
4162
4163 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004164 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4165 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4166 if (type == DP_DS_PORT_TYPE_VGA ||
4167 type == DP_DS_PORT_TYPE_NON_EDID)
4168 return connector_status_unknown;
4169 } else {
4170 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4171 DP_DWN_STRM_PORT_TYPE_MASK;
4172 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4173 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4174 return connector_status_unknown;
4175 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004176
4177 /* Anything else is out of spec, warn and ignore */
4178 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004179 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004180}
4181
4182static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004183edp_detect(struct intel_dp *intel_dp)
4184{
4185 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004186 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004187 enum drm_connector_status status;
4188
Mika Kahola1650be72016-12-13 10:02:47 +02004189 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004190 if (status == connector_status_unknown)
4191 status = connector_status_connected;
4192
4193 return status;
4194}
4195
Jani Nikulab93433c2015-08-20 10:47:36 +03004196static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4197 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004198{
Jani Nikulab93433c2015-08-20 10:47:36 +03004199 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004200
Jani Nikula0df53b72015-08-20 10:47:40 +03004201 switch (port->port) {
4202 case PORT_A:
4203 return true;
4204 case PORT_B:
4205 bit = SDE_PORTB_HOTPLUG;
4206 break;
4207 case PORT_C:
4208 bit = SDE_PORTC_HOTPLUG;
4209 break;
4210 case PORT_D:
4211 bit = SDE_PORTD_HOTPLUG;
4212 break;
4213 default:
4214 MISSING_CASE(port->port);
4215 return false;
4216 }
4217
4218 return I915_READ(SDEISR) & bit;
4219}
4220
4221static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4222 struct intel_digital_port *port)
4223{
4224 u32 bit;
4225
4226 switch (port->port) {
4227 case PORT_A:
4228 return true;
4229 case PORT_B:
4230 bit = SDE_PORTB_HOTPLUG_CPT;
4231 break;
4232 case PORT_C:
4233 bit = SDE_PORTC_HOTPLUG_CPT;
4234 break;
4235 case PORT_D:
4236 bit = SDE_PORTD_HOTPLUG_CPT;
4237 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004238 case PORT_E:
4239 bit = SDE_PORTE_HOTPLUG_SPT;
4240 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004241 default:
4242 MISSING_CASE(port->port);
4243 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004244 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004245
Jani Nikulab93433c2015-08-20 10:47:36 +03004246 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004247}
4248
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004249static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004250 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004251{
Jani Nikula9642c812015-08-20 10:47:41 +03004252 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004253
Jani Nikula9642c812015-08-20 10:47:41 +03004254 switch (port->port) {
4255 case PORT_B:
4256 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4257 break;
4258 case PORT_C:
4259 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4260 break;
4261 case PORT_D:
4262 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4263 break;
4264 default:
4265 MISSING_CASE(port->port);
4266 return false;
4267 }
4268
4269 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4270}
4271
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004272static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4273 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004274{
4275 u32 bit;
4276
4277 switch (port->port) {
4278 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004279 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004280 break;
4281 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004282 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004283 break;
4284 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004285 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004286 break;
4287 default:
4288 MISSING_CASE(port->port);
4289 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004290 }
4291
Jani Nikula1d245982015-08-20 10:47:37 +03004292 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004293}
4294
Jani Nikulae464bfd2015-08-20 10:47:42 +03004295static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304296 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004297{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304298 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4299 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004300 u32 bit;
4301
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304302 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4303 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004304 case PORT_A:
4305 bit = BXT_DE_PORT_HP_DDIA;
4306 break;
4307 case PORT_B:
4308 bit = BXT_DE_PORT_HP_DDIB;
4309 break;
4310 case PORT_C:
4311 bit = BXT_DE_PORT_HP_DDIC;
4312 break;
4313 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304314 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004315 return false;
4316 }
4317
4318 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4319}
4320
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004321/*
4322 * intel_digital_port_connected - is the specified port connected?
4323 * @dev_priv: i915 private structure
4324 * @port: the port to test
4325 *
4326 * Return %true if @port is connected, %false otherwise.
4327 */
David Weinehall23f889b2016-08-17 15:47:48 +03004328static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004329 struct intel_digital_port *port)
4330{
Jani Nikula0df53b72015-08-20 10:47:40 +03004331 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004332 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004333 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004334 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004335 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004336 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004337 else if (IS_GM45(dev_priv))
4338 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004339 else
4340 return g4x_digital_port_connected(dev_priv, port);
4341}
4342
Keith Packard8c241fe2011-09-28 16:38:44 -07004343static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004344intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004345{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004346 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004347
Jani Nikula9cd300e2012-10-19 14:51:52 +03004348 /* use cached edid if we have one */
4349 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004350 /* invalid edid */
4351 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004352 return NULL;
4353
Jani Nikula55e9ede2013-10-01 10:38:54 +03004354 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004355 } else
4356 return drm_get_edid(&intel_connector->base,
4357 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004358}
4359
Chris Wilsonbeb60602014-09-02 20:04:00 +01004360static void
4361intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004362{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004363 struct intel_connector *intel_connector = intel_dp->attached_connector;
4364 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004365
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304366 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004367 edid = intel_dp_get_edid(intel_dp);
4368 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004369
Chris Wilsonbeb60602014-09-02 20:04:00 +01004370 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4371 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4372 else
4373 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4374}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004375
Chris Wilsonbeb60602014-09-02 20:04:00 +01004376static void
4377intel_dp_unset_edid(struct intel_dp *intel_dp)
4378{
4379 struct intel_connector *intel_connector = intel_dp->attached_connector;
4380
4381 kfree(intel_connector->detect_edid);
4382 intel_connector->detect_edid = NULL;
4383
4384 intel_dp->has_audio = false;
4385}
4386
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004387static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304388intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004389{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304390 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004391 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004392 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4393 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004394 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004395 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004396 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004397 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004398
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004399 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4400 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004401
Chris Wilsond410b562014-09-02 20:03:59 +01004402 /* Can't disconnect eDP, but you can close the lid... */
4403 if (is_edp(intel_dp))
4404 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004405 else if (intel_digital_port_connected(to_i915(dev),
4406 dp_to_dig_port(intel_dp)))
4407 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004408 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004409 status = connector_status_disconnected;
4410
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004411 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004412 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304413
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004414 if (intel_dp->is_mst) {
4415 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4416 intel_dp->is_mst,
4417 intel_dp->mst_mgr.mst_state);
4418 intel_dp->is_mst = false;
4419 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4420 intel_dp->is_mst);
4421 }
4422
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004423 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304424 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004425
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304426 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004427 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304428
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004429 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4430 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4431 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4432
Manasi Navaref4829842016-12-05 16:27:36 -08004433 /* Set the max lane count for sink */
4434 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
4435
4436 /* Set the max link BW for sink */
4437 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4438
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004439 intel_dp_print_rates(intel_dp);
4440
Imre Deak7b3fc172016-10-25 16:12:39 +03004441 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004442
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004443 intel_dp_configure_mst(intel_dp);
4444
4445 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304446 /*
4447 * If we are in MST mode then this connector
4448 * won't appear connected or have anything
4449 * with EDID on it
4450 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004451 status = connector_status_disconnected;
4452 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304453 } else if (connector->status == connector_status_connected) {
4454 /*
4455 * If display was connected already and is still connected
4456 * check links status, there has been known issues of
4457 * link loss triggerring long pulse!!!!
4458 */
4459 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4460 intel_dp_check_link_status(intel_dp);
4461 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4462 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004463 }
4464
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304465 /*
4466 * Clearing NACK and defer counts to get their exact values
4467 * while reading EDID which are required by Compliance tests
4468 * 4.2.2.4 and 4.2.2.5
4469 */
4470 intel_dp->aux.i2c_nack_count = 0;
4471 intel_dp->aux.i2c_defer_count = 0;
4472
Chris Wilsonbeb60602014-09-02 20:04:00 +01004473 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004474 if (is_edp(intel_dp) || intel_connector->detect_edid)
4475 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304476 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004477
Todd Previte09b1eb12015-04-20 15:27:34 -07004478 /* Try to read the source of the interrupt */
4479 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004480 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4481 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004482 /* Clear interrupt source */
4483 drm_dp_dpcd_writeb(&intel_dp->aux,
4484 DP_DEVICE_SERVICE_IRQ_VECTOR,
4485 sink_irq_vector);
4486
4487 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4488 intel_dp_handle_test_request(intel_dp);
4489 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4490 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4491 }
4492
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004493out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004494 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304495 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304496
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004497 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004498 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304499}
4500
4501static enum drm_connector_status
4502intel_dp_detect(struct drm_connector *connector, bool force)
4503{
4504 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004505 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304506
4507 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4508 connector->base.id, connector->name);
4509
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304510 /* If full detect is not performed yet, do a full detect */
4511 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004512 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304513
4514 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304515
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004516 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004517}
4518
Chris Wilsonbeb60602014-09-02 20:04:00 +01004519static void
4520intel_dp_force(struct drm_connector *connector)
4521{
4522 struct intel_dp *intel_dp = intel_attached_dp(connector);
4523 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004524 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004525 enum intel_display_power_domain power_domain;
4526
4527 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4528 connector->base.id, connector->name);
4529 intel_dp_unset_edid(intel_dp);
4530
4531 if (connector->status != connector_status_connected)
4532 return;
4533
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004534 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4535 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004536
4537 intel_dp_set_edid(intel_dp);
4538
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004539 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004540
4541 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004542 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004543}
4544
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004545static int intel_dp_get_modes(struct drm_connector *connector)
4546{
Jani Nikuladd06f902012-10-19 14:51:50 +03004547 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004548 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004549
Chris Wilsonbeb60602014-09-02 20:04:00 +01004550 edid = intel_connector->detect_edid;
4551 if (edid) {
4552 int ret = intel_connector_update_modes(connector, edid);
4553 if (ret)
4554 return ret;
4555 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004556
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004557 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004558 if (is_edp(intel_attached_dp(connector)) &&
4559 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004560 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004561
4562 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004563 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004564 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004565 drm_mode_probed_add(connector, mode);
4566 return 1;
4567 }
4568 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004569
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004570 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004571}
4572
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004573static bool
4574intel_dp_detect_audio(struct drm_connector *connector)
4575{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004576 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004577 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004578
Chris Wilsonbeb60602014-09-02 20:04:00 +01004579 edid = to_intel_connector(connector)->detect_edid;
4580 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004581 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004582
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004583 return has_audio;
4584}
4585
Chris Wilsonf6849602010-09-19 09:29:33 +01004586static int
4587intel_dp_set_property(struct drm_connector *connector,
4588 struct drm_property *property,
4589 uint64_t val)
4590{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004591 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004592 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004593 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4594 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004595 int ret;
4596
Rob Clark662595d2012-10-11 20:36:04 -05004597 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004598 if (ret)
4599 return ret;
4600
Chris Wilson3f43c482011-05-12 22:17:24 +01004601 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004602 int i = val;
4603 bool has_audio;
4604
4605 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004606 return 0;
4607
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004608 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004609
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004610 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004611 has_audio = intel_dp_detect_audio(connector);
4612 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004613 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004614
4615 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004616 return 0;
4617
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004618 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004619 goto done;
4620 }
4621
Chris Wilsone953fd72011-02-21 22:23:52 +00004622 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004623 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004624 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004625
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004626 switch (val) {
4627 case INTEL_BROADCAST_RGB_AUTO:
4628 intel_dp->color_range_auto = true;
4629 break;
4630 case INTEL_BROADCAST_RGB_FULL:
4631 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004632 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004633 break;
4634 case INTEL_BROADCAST_RGB_LIMITED:
4635 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004636 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004637 break;
4638 default:
4639 return -EINVAL;
4640 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004641
4642 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004643 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004644 return 0;
4645
Chris Wilsone953fd72011-02-21 22:23:52 +00004646 goto done;
4647 }
4648
Yuly Novikov53b41832012-10-26 12:04:00 +03004649 if (is_edp(intel_dp) &&
4650 property == connector->dev->mode_config.scaling_mode_property) {
4651 if (val == DRM_MODE_SCALE_NONE) {
4652 DRM_DEBUG_KMS("no scaling not supported\n");
4653 return -EINVAL;
4654 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004655 if (HAS_GMCH_DISPLAY(dev_priv) &&
4656 val == DRM_MODE_SCALE_CENTER) {
4657 DRM_DEBUG_KMS("centering not supported\n");
4658 return -EINVAL;
4659 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004660
4661 if (intel_connector->panel.fitting_mode == val) {
4662 /* the eDP scaling property is not changed */
4663 return 0;
4664 }
4665 intel_connector->panel.fitting_mode = val;
4666
4667 goto done;
4668 }
4669
Chris Wilsonf6849602010-09-19 09:29:33 +01004670 return -EINVAL;
4671
4672done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004673 if (intel_encoder->base.crtc)
4674 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004675
4676 return 0;
4677}
4678
Chris Wilson7a418e32016-06-24 14:00:14 +01004679static int
4680intel_dp_connector_register(struct drm_connector *connector)
4681{
4682 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004683 int ret;
4684
4685 ret = intel_connector_register(connector);
4686 if (ret)
4687 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004688
4689 i915_debugfs_connector_add(connector);
4690
4691 DRM_DEBUG_KMS("registering %s bus for %s\n",
4692 intel_dp->aux.name, connector->kdev->kobj.name);
4693
4694 intel_dp->aux.dev = connector->kdev;
4695 return drm_dp_aux_register(&intel_dp->aux);
4696}
4697
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004698static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004699intel_dp_connector_unregister(struct drm_connector *connector)
4700{
4701 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4702 intel_connector_unregister(connector);
4703}
4704
4705static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004706intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004707{
Jani Nikula1d508702012-10-19 14:51:49 +03004708 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004709
Chris Wilson10e972d2014-09-04 21:43:45 +01004710 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004711
Jani Nikula9cd300e2012-10-19 14:51:52 +03004712 if (!IS_ERR_OR_NULL(intel_connector->edid))
4713 kfree(intel_connector->edid);
4714
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004715 /* Can't call is_edp() since the encoder may have been destroyed
4716 * already. */
4717 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004718 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004719
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004720 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004721 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004722}
4723
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004724void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004725{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004726 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4727 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004728
Dave Airlie0e32b392014-05-02 14:02:48 +10004729 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004730 if (is_edp(intel_dp)) {
4731 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004732 /*
4733 * vdd might still be enabled do to the delayed vdd off.
4734 * Make sure vdd is actually turned off here.
4735 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004736 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004737 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004738 pps_unlock(intel_dp);
4739
Clint Taylor01527b32014-07-07 13:01:46 -07004740 if (intel_dp->edp_notifier.notifier_call) {
4741 unregister_reboot_notifier(&intel_dp->edp_notifier);
4742 intel_dp->edp_notifier.notifier_call = NULL;
4743 }
Keith Packardbd943152011-09-18 23:09:52 -07004744 }
Chris Wilson99681882016-06-20 09:29:17 +01004745
4746 intel_dp_aux_fini(intel_dp);
4747
Imre Deakc8bd0e42014-12-12 17:57:38 +02004748 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004749 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004750}
4751
Imre Deakbf93ba62016-04-18 10:04:21 +03004752void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004753{
4754 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4755
4756 if (!is_edp(intel_dp))
4757 return;
4758
Ville Syrjälä951468f2014-09-04 14:55:31 +03004759 /*
4760 * vdd might still be enabled do to the delayed vdd off.
4761 * Make sure vdd is actually turned off here.
4762 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004763 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004764 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004765 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004766 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004767}
4768
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004769static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4770{
4771 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4772 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004773 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004774 enum intel_display_power_domain power_domain;
4775
4776 lockdep_assert_held(&dev_priv->pps_mutex);
4777
4778 if (!edp_have_panel_vdd(intel_dp))
4779 return;
4780
4781 /*
4782 * The VDD bit needs a power domain reference, so if the bit is
4783 * already enabled when we boot or resume, grab this reference and
4784 * schedule a vdd off, so we don't hold on to the reference
4785 * indefinitely.
4786 */
4787 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004788 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004789 intel_display_power_get(dev_priv, power_domain);
4790
4791 edp_panel_vdd_schedule_off(intel_dp);
4792}
4793
Imre Deakbf93ba62016-04-18 10:04:21 +03004794void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004795{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004796 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004797 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4798 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004799
4800 if (!HAS_DDI(dev_priv))
4801 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004802
Imre Deakdd75f6d2016-11-21 21:15:05 +02004803 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05304804 lspcon_resume(lspcon);
4805
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004806 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4807 return;
4808
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004809 pps_lock(intel_dp);
4810
Imre Deak335f7522016-08-10 14:07:32 +03004811 /* Reinit the power sequencer, in case BIOS did something with it. */
4812 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004813 intel_edp_panel_vdd_sanitize(intel_dp);
4814
4815 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004816}
4817
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004818static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004819 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004820 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004821 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004822 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004823 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004824 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004825 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004826 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004827 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004828 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004829 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004830};
4831
4832static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4833 .get_modes = intel_dp_get_modes,
4834 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004835};
4836
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004837static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004838 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004839 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004840};
4841
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004842enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004843intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4844{
4845 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004846 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004847 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004848 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004849 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004850 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004851
Takashi Iwai25400582015-11-19 12:09:56 +01004852 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4853 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004854 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004855
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004856 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4857 /*
4858 * vdd off can generate a long pulse on eDP which
4859 * would require vdd on to handle it, and thus we
4860 * would end up in an endless cycle of
4861 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4862 */
4863 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4864 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02004865 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004866 }
4867
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004868 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4869 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004870 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004871
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004872 if (long_hpd) {
4873 intel_dp->detect_done = false;
4874 return IRQ_NONE;
4875 }
4876
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004877 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004878 intel_display_power_get(dev_priv, power_domain);
4879
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004880 if (intel_dp->is_mst) {
4881 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4882 /*
4883 * If we were in MST mode, and device is not
4884 * there, get out of MST mode
4885 */
4886 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4887 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4888 intel_dp->is_mst = false;
4889 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4890 intel_dp->is_mst);
4891 intel_dp->detect_done = false;
4892 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004893 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004894 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004895
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004896 if (!intel_dp->is_mst) {
4897 if (!intel_dp_short_pulse(intel_dp)) {
4898 intel_dp->detect_done = false;
4899 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304900 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004901 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004902
4903 ret = IRQ_HANDLED;
4904
Imre Deak1c767b32014-08-18 14:42:42 +03004905put_power:
4906 intel_display_power_put(dev_priv, power_domain);
4907
4908 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004909}
4910
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004911/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00004912bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004913{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004914 /*
4915 * eDP not supported on g4x. so bail out early just
4916 * for a bit extra safety in case the VBT is bonkers.
4917 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00004918 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004919 return false;
4920
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004921 if (port == PORT_A)
4922 return true;
4923
Jani Nikula951d9ef2016-03-16 12:43:31 +02004924 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004925}
4926
Dave Airlie0e32b392014-05-02 14:02:48 +10004927void
Chris Wilsonf6849602010-09-19 09:29:33 +01004928intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4929{
Yuly Novikov53b41832012-10-26 12:04:00 +03004930 struct intel_connector *intel_connector = to_intel_connector(connector);
4931
Chris Wilson3f43c482011-05-12 22:17:24 +01004932 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004933 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004934 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004935
4936 if (is_edp(intel_dp)) {
4937 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004938 drm_object_attach_property(
4939 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004940 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004941 DRM_MODE_SCALE_ASPECT);
4942 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004943 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004944}
4945
Imre Deakdada1a92014-01-29 13:25:41 +02004946static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4947{
Abhay Kumard28d4732016-01-22 17:39:04 -08004948 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004949 intel_dp->last_power_on = jiffies;
4950 intel_dp->last_backlight_off = jiffies;
4951}
4952
Daniel Vetter67a54562012-10-20 20:57:45 +02004953static void
Imre Deak54648612016-06-16 16:37:22 +03004954intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4955 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004956{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304957 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004958 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004959
Imre Deak8e8232d2016-06-16 16:37:21 +03004960 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004961
4962 /* Workaround: Need to write PP_CONTROL with the unlock key as
4963 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304964 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004965
Imre Deak8e8232d2016-06-16 16:37:21 +03004966 pp_on = I915_READ(regs.pp_on);
4967 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004968 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004969 I915_WRITE(regs.pp_ctrl, pp_ctl);
4970 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304971 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004972
4973 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004974 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4975 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004976
Imre Deak54648612016-06-16 16:37:22 +03004977 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4978 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004979
Imre Deak54648612016-06-16 16:37:22 +03004980 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4981 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004982
Imre Deak54648612016-06-16 16:37:22 +03004983 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4984 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004985
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004986 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304987 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4988 BXT_POWER_CYCLE_DELAY_SHIFT;
4989 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004990 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304991 else
Imre Deak54648612016-06-16 16:37:22 +03004992 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304993 } else {
Imre Deak54648612016-06-16 16:37:22 +03004994 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004995 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304996 }
Imre Deak54648612016-06-16 16:37:22 +03004997}
4998
4999static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005000intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5001{
5002 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5003 state_name,
5004 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5005}
5006
5007static void
5008intel_pps_verify_state(struct drm_i915_private *dev_priv,
5009 struct intel_dp *intel_dp)
5010{
5011 struct edp_power_seq hw;
5012 struct edp_power_seq *sw = &intel_dp->pps_delays;
5013
5014 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5015
5016 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5017 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5018 DRM_ERROR("PPS state mismatch\n");
5019 intel_pps_dump_state("sw", sw);
5020 intel_pps_dump_state("hw", &hw);
5021 }
5022}
5023
5024static void
Imre Deak54648612016-06-16 16:37:22 +03005025intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5026 struct intel_dp *intel_dp)
5027{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005028 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005029 struct edp_power_seq cur, vbt, spec,
5030 *final = &intel_dp->pps_delays;
5031
5032 lockdep_assert_held(&dev_priv->pps_mutex);
5033
5034 /* already initialized? */
5035 if (final->t11_t12 != 0)
5036 return;
5037
5038 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005039
Imre Deakde9c1b62016-06-16 20:01:46 +03005040 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005041
Jani Nikula6aa23e62016-03-24 17:50:20 +02005042 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005043
5044 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5045 * our hw here, which are all in 100usec. */
5046 spec.t1_t3 = 210 * 10;
5047 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5048 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5049 spec.t10 = 500 * 10;
5050 /* This one is special and actually in units of 100ms, but zero
5051 * based in the hw (so we need to add 100 ms). But the sw vbt
5052 * table multiplies it with 1000 to make it in units of 100usec,
5053 * too. */
5054 spec.t11_t12 = (510 + 100) * 10;
5055
Imre Deakde9c1b62016-06-16 20:01:46 +03005056 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005057
5058 /* Use the max of the register settings and vbt. If both are
5059 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005060#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005061 spec.field : \
5062 max(cur.field, vbt.field))
5063 assign_final(t1_t3);
5064 assign_final(t8);
5065 assign_final(t9);
5066 assign_final(t10);
5067 assign_final(t11_t12);
5068#undef assign_final
5069
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005070#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005071 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5072 intel_dp->backlight_on_delay = get_delay(t8);
5073 intel_dp->backlight_off_delay = get_delay(t9);
5074 intel_dp->panel_power_down_delay = get_delay(t10);
5075 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5076#undef get_delay
5077
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005078 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5079 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5080 intel_dp->panel_power_cycle_delay);
5081
5082 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5083 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005084
5085 /*
5086 * We override the HW backlight delays to 1 because we do manual waits
5087 * on them. For T8, even BSpec recommends doing it. For T9, if we
5088 * don't do this, we'll end up waiting for the backlight off delay
5089 * twice: once when we do the manual sleep, and once when we disable
5090 * the panel and wait for the PP_STATUS bit to become zero.
5091 */
5092 final->t8 = 1;
5093 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005094}
5095
5096static void
5097intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005098 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005099{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005100 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005101 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005102 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005103 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005104 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005105 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005106
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005107 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005108
Imre Deak8e8232d2016-06-16 16:37:21 +03005109 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005110
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005111 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005112 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5113 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005114 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005115 /* Compute the divisor for the pp clock, simply match the Bspec
5116 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005117 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005118 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305119 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5120 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5121 << BXT_POWER_CYCLE_DELAY_SHIFT);
5122 } else {
5123 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5124 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5125 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5126 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005127
5128 /* Haswell doesn't have any port selection bits for the panel
5129 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005130 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005131 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005132 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005133 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005134 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005135 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005136 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005137 }
5138
Jesse Barnes453c5422013-03-28 09:55:41 -07005139 pp_on |= port_sel;
5140
Imre Deak8e8232d2016-06-16 16:37:21 +03005141 I915_WRITE(regs.pp_on, pp_on);
5142 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005143 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005144 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305145 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005146 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005147
Daniel Vetter67a54562012-10-20 20:57:45 +02005148 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 +03005149 I915_READ(regs.pp_on),
5150 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005151 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005152 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5153 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005154}
5155
Imre Deak335f7522016-08-10 14:07:32 +03005156static void intel_dp_pps_init(struct drm_device *dev,
5157 struct intel_dp *intel_dp)
5158{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005159 struct drm_i915_private *dev_priv = to_i915(dev);
5160
5161 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005162 vlv_initial_power_sequencer_setup(intel_dp);
5163 } else {
5164 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5165 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5166 }
5167}
5168
Vandana Kannanb33a2812015-02-13 15:33:03 +05305169/**
5170 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005171 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005172 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305173 * @refresh_rate: RR to be programmed
5174 *
5175 * This function gets called when refresh rate (RR) has to be changed from
5176 * one frequency to another. Switches can be between high and low RR
5177 * supported by the panel or to any other RR based on media playback (in
5178 * this case, RR value needs to be passed from user space).
5179 *
5180 * The caller of this function needs to take a lock on dev_priv->drrs.
5181 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005182static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5183 struct intel_crtc_state *crtc_state,
5184 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305185{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305186 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305187 struct intel_digital_port *dig_port = NULL;
5188 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005189 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305190 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305191
5192 if (refresh_rate <= 0) {
5193 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5194 return;
5195 }
5196
Vandana Kannan96178ee2015-01-10 02:25:56 +05305197 if (intel_dp == NULL) {
5198 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305199 return;
5200 }
5201
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005202 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005203 * FIXME: This needs proper synchronization with psr state for some
5204 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005205 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305206
Vandana Kannan96178ee2015-01-10 02:25:56 +05305207 dig_port = dp_to_dig_port(intel_dp);
5208 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005209 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305210
5211 if (!intel_crtc) {
5212 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5213 return;
5214 }
5215
Vandana Kannan96178ee2015-01-10 02:25:56 +05305216 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305217 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5218 return;
5219 }
5220
Vandana Kannan96178ee2015-01-10 02:25:56 +05305221 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5222 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305223 index = DRRS_LOW_RR;
5224
Vandana Kannan96178ee2015-01-10 02:25:56 +05305225 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305226 DRM_DEBUG_KMS(
5227 "DRRS requested for previously set RR...ignoring\n");
5228 return;
5229 }
5230
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005231 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305232 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5233 return;
5234 }
5235
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005236 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305237 switch (index) {
5238 case DRRS_HIGH_RR:
5239 intel_dp_set_m_n(intel_crtc, M1_N1);
5240 break;
5241 case DRRS_LOW_RR:
5242 intel_dp_set_m_n(intel_crtc, M2_N2);
5243 break;
5244 case DRRS_MAX_RR:
5245 default:
5246 DRM_ERROR("Unsupported refreshrate type\n");
5247 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005248 } else if (INTEL_GEN(dev_priv) > 6) {
5249 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005250 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305251
Ville Syrjälä649636e2015-09-22 19:50:01 +03005252 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305253 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005254 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305255 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5256 else
5257 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305258 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005259 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305260 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5261 else
5262 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305263 }
5264 I915_WRITE(reg, val);
5265 }
5266
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305267 dev_priv->drrs.refresh_rate_type = index;
5268
5269 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5270}
5271
Vandana Kannanb33a2812015-02-13 15:33:03 +05305272/**
5273 * intel_edp_drrs_enable - init drrs struct if supported
5274 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005275 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305276 *
5277 * Initializes frontbuffer_bits and drrs.dp
5278 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005279void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5280 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305281{
5282 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005283 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305284
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005285 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305286 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5287 return;
5288 }
5289
5290 mutex_lock(&dev_priv->drrs.mutex);
5291 if (WARN_ON(dev_priv->drrs.dp)) {
5292 DRM_ERROR("DRRS already enabled\n");
5293 goto unlock;
5294 }
5295
5296 dev_priv->drrs.busy_frontbuffer_bits = 0;
5297
5298 dev_priv->drrs.dp = intel_dp;
5299
5300unlock:
5301 mutex_unlock(&dev_priv->drrs.mutex);
5302}
5303
Vandana Kannanb33a2812015-02-13 15:33:03 +05305304/**
5305 * intel_edp_drrs_disable - Disable DRRS
5306 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005307 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305308 *
5309 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005310void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5311 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305312{
5313 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005314 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305315
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005316 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305317 return;
5318
5319 mutex_lock(&dev_priv->drrs.mutex);
5320 if (!dev_priv->drrs.dp) {
5321 mutex_unlock(&dev_priv->drrs.mutex);
5322 return;
5323 }
5324
5325 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005326 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5327 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305328
5329 dev_priv->drrs.dp = NULL;
5330 mutex_unlock(&dev_priv->drrs.mutex);
5331
5332 cancel_delayed_work_sync(&dev_priv->drrs.work);
5333}
5334
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305335static void intel_edp_drrs_downclock_work(struct work_struct *work)
5336{
5337 struct drm_i915_private *dev_priv =
5338 container_of(work, typeof(*dev_priv), drrs.work.work);
5339 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305340
Vandana Kannan96178ee2015-01-10 02:25:56 +05305341 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305342
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305343 intel_dp = dev_priv->drrs.dp;
5344
5345 if (!intel_dp)
5346 goto unlock;
5347
5348 /*
5349 * The delayed work can race with an invalidate hence we need to
5350 * recheck.
5351 */
5352
5353 if (dev_priv->drrs.busy_frontbuffer_bits)
5354 goto unlock;
5355
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005356 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5357 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5358
5359 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5360 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5361 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305362
5363unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305364 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305365}
5366
Vandana Kannanb33a2812015-02-13 15:33:03 +05305367/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305368 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005369 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305370 * @frontbuffer_bits: frontbuffer plane tracking bits
5371 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305372 * This function gets called everytime rendering on the given planes start.
5373 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305374 *
5375 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5376 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005377void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5378 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305379{
Vandana Kannana93fad02015-01-10 02:25:59 +05305380 struct drm_crtc *crtc;
5381 enum pipe pipe;
5382
Daniel Vetter9da7d692015-04-09 16:44:15 +02005383 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305384 return;
5385
Daniel Vetter88f933a2015-04-09 16:44:16 +02005386 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305387
Vandana Kannana93fad02015-01-10 02:25:59 +05305388 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005389 if (!dev_priv->drrs.dp) {
5390 mutex_unlock(&dev_priv->drrs.mutex);
5391 return;
5392 }
5393
Vandana Kannana93fad02015-01-10 02:25:59 +05305394 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5395 pipe = to_intel_crtc(crtc)->pipe;
5396
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005397 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5398 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5399
Ramalingam C0ddfd202015-06-15 20:50:05 +05305400 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005401 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005402 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5403 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305404
Vandana Kannana93fad02015-01-10 02:25:59 +05305405 mutex_unlock(&dev_priv->drrs.mutex);
5406}
5407
Vandana Kannanb33a2812015-02-13 15:33:03 +05305408/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305409 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005410 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305411 * @frontbuffer_bits: frontbuffer plane tracking bits
5412 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305413 * This function gets called every time rendering on the given planes has
5414 * completed or flip on a crtc is completed. So DRRS should be upclocked
5415 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5416 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305417 *
5418 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5419 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005420void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5421 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305422{
Vandana Kannana93fad02015-01-10 02:25:59 +05305423 struct drm_crtc *crtc;
5424 enum pipe pipe;
5425
Daniel Vetter9da7d692015-04-09 16:44:15 +02005426 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305427 return;
5428
Daniel Vetter88f933a2015-04-09 16:44:16 +02005429 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305430
Vandana Kannana93fad02015-01-10 02:25:59 +05305431 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005432 if (!dev_priv->drrs.dp) {
5433 mutex_unlock(&dev_priv->drrs.mutex);
5434 return;
5435 }
5436
Vandana Kannana93fad02015-01-10 02:25:59 +05305437 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5438 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005439
5440 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305441 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5442
Ramalingam C0ddfd202015-06-15 20:50:05 +05305443 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005444 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005445 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5446 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305447
5448 /*
5449 * flush also means no more activity hence schedule downclock, if all
5450 * other fbs are quiescent too
5451 */
5452 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305453 schedule_delayed_work(&dev_priv->drrs.work,
5454 msecs_to_jiffies(1000));
5455 mutex_unlock(&dev_priv->drrs.mutex);
5456}
5457
Vandana Kannanb33a2812015-02-13 15:33:03 +05305458/**
5459 * DOC: Display Refresh Rate Switching (DRRS)
5460 *
5461 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5462 * which enables swtching between low and high refresh rates,
5463 * dynamically, based on the usage scenario. This feature is applicable
5464 * for internal panels.
5465 *
5466 * Indication that the panel supports DRRS is given by the panel EDID, which
5467 * would list multiple refresh rates for one resolution.
5468 *
5469 * DRRS is of 2 types - static and seamless.
5470 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5471 * (may appear as a blink on screen) and is used in dock-undock scenario.
5472 * Seamless DRRS involves changing RR without any visual effect to the user
5473 * and can be used during normal system usage. This is done by programming
5474 * certain registers.
5475 *
5476 * Support for static/seamless DRRS may be indicated in the VBT based on
5477 * inputs from the panel spec.
5478 *
5479 * DRRS saves power by switching to low RR based on usage scenarios.
5480 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005481 * The implementation is based on frontbuffer tracking implementation. When
5482 * there is a disturbance on the screen triggered by user activity or a periodic
5483 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5484 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5485 * made.
5486 *
5487 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5488 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305489 *
5490 * DRRS can be further extended to support other internal panels and also
5491 * the scenario of video playback wherein RR is set based on the rate
5492 * requested by userspace.
5493 */
5494
5495/**
5496 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5497 * @intel_connector: eDP connector
5498 * @fixed_mode: preferred mode of panel
5499 *
5500 * This function is called only once at driver load to initialize basic
5501 * DRRS stuff.
5502 *
5503 * Returns:
5504 * Downclock mode if panel supports it, else return NULL.
5505 * DRRS support is determined by the presence of downclock mode (apart
5506 * from VBT setting).
5507 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305508static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305509intel_dp_drrs_init(struct intel_connector *intel_connector,
5510 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305511{
5512 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305513 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005514 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305515 struct drm_display_mode *downclock_mode = NULL;
5516
Daniel Vetter9da7d692015-04-09 16:44:15 +02005517 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5518 mutex_init(&dev_priv->drrs.mutex);
5519
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005520 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305521 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5522 return NULL;
5523 }
5524
5525 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005526 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305527 return NULL;
5528 }
5529
5530 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005531 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305532
5533 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305534 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305535 return NULL;
5536 }
5537
Vandana Kannan96178ee2015-01-10 02:25:56 +05305538 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305539
Vandana Kannan96178ee2015-01-10 02:25:56 +05305540 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005541 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305542 return downclock_mode;
5543}
5544
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005545static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005546 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005547{
5548 struct drm_connector *connector = &intel_connector->base;
5549 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005550 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5551 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005552 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005553 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305554 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005555 bool has_dpcd;
5556 struct drm_display_mode *scan;
5557 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005558 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005559
5560 if (!is_edp(intel_dp))
5561 return true;
5562
Imre Deak97a824e12016-06-21 11:51:47 +03005563 /*
5564 * On IBX/CPT we may get here with LVDS already registered. Since the
5565 * driver uses the only internal power sequencer available for both
5566 * eDP and LVDS bail out early in this case to prevent interfering
5567 * with an already powered-on LVDS power sequencer.
5568 */
5569 if (intel_get_lvds_encoder(dev)) {
5570 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5571 DRM_INFO("LVDS was detected, not registering eDP\n");
5572
5573 return false;
5574 }
5575
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005576 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005577
5578 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005579 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005580 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005581
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005582 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005583
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005584 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005585 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005586
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005587 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005588 /* if this fails, presume the device is a ghost */
5589 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005590 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005591 }
5592
Daniel Vetter060c8772014-03-21 23:22:35 +01005593 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005594 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005595 if (edid) {
5596 if (drm_add_edid_modes(connector, edid)) {
5597 drm_mode_connector_update_edid_property(connector,
5598 edid);
5599 drm_edid_to_eld(connector, edid);
5600 } else {
5601 kfree(edid);
5602 edid = ERR_PTR(-EINVAL);
5603 }
5604 } else {
5605 edid = ERR_PTR(-ENOENT);
5606 }
5607 intel_connector->edid = edid;
5608
5609 /* prefer fixed mode from EDID if available */
5610 list_for_each_entry(scan, &connector->probed_modes, head) {
5611 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5612 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305613 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305614 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005615 break;
5616 }
5617 }
5618
5619 /* fallback to VBT if available for eDP */
5620 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5621 fixed_mode = drm_mode_duplicate(dev,
5622 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005623 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005624 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005625 connector->display_info.width_mm = fixed_mode->width_mm;
5626 connector->display_info.height_mm = fixed_mode->height_mm;
5627 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005628 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005629 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005630
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005631 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005632 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5633 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005634
5635 /*
5636 * Figure out the current pipe for the initial backlight setup.
5637 * If the current pipe isn't valid, try the PPS pipe, and if that
5638 * fails just assume pipe A.
5639 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005640 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6517d272014-11-07 11:16:02 +02005641 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5642 else
5643 pipe = PORT_TO_PIPE(intel_dp->DP);
5644
5645 if (pipe != PIPE_A && pipe != PIPE_B)
5646 pipe = intel_dp->pps_pipe;
5647
5648 if (pipe != PIPE_A && pipe != PIPE_B)
5649 pipe = PIPE_A;
5650
5651 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5652 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005653 }
5654
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305655 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005656 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005657 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005658
5659 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005660
5661out_vdd_off:
5662 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5663 /*
5664 * vdd might still be enabled do to the delayed vdd off.
5665 * Make sure vdd is actually turned off here.
5666 */
5667 pps_lock(intel_dp);
5668 edp_panel_vdd_off_sync(intel_dp);
5669 pps_unlock(intel_dp);
5670
5671 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005672}
5673
Paulo Zanoni16c25532013-06-12 17:27:25 -03005674bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005675intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5676 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005677{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005678 struct drm_connector *connector = &intel_connector->base;
5679 struct intel_dp *intel_dp = &intel_dig_port->dp;
5680 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5681 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005682 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005683 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005684 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005685
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005686 if (WARN(intel_dig_port->max_lanes < 1,
5687 "Not enough lanes (%d) for DP on port %c\n",
5688 intel_dig_port->max_lanes, port_name(port)))
5689 return false;
5690
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005691 intel_dp->pps_pipe = INVALID_PIPE;
5692
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005693 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005694 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005695 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005696 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005697 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005698 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005699 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5700 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005701 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005702
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005703 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005704 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5705 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005706 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005707
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005708 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005709 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5710
Daniel Vetter07679352012-09-06 22:15:42 +02005711 /* Preserve the current hw state. */
5712 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005713 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005714
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005715 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305716 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005717 else
5718 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005719
Imre Deakf7d24902013-05-08 13:14:05 +03005720 /*
5721 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5722 * for DP the encoder type can be set by the caller to
5723 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5724 */
5725 if (type == DRM_MODE_CONNECTOR_eDP)
5726 intel_encoder->type = INTEL_OUTPUT_EDP;
5727
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005728 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005729 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005730 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005731 return false;
5732
Imre Deake7281ea2013-05-08 13:14:08 +03005733 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5734 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5735 port_name(port));
5736
Adam Jacksonb3295302010-07-16 14:46:28 -04005737 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005738 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5739
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005740 connector->interlace_allowed = true;
5741 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005742
Mika Kaholab6339582016-09-09 14:10:52 +03005743 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005744
Daniel Vetter66a92782012-07-12 20:08:18 +02005745 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005746 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005747
Chris Wilsondf0e9242010-09-09 16:20:55 +01005748 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005749
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005750 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005751 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5752 else
5753 intel_connector->get_hw_state = intel_connector_get_hw_state;
5754
Jani Nikula0b998362014-03-14 16:51:17 +02005755 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005756 switch (port) {
5757 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005758 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005759 break;
5760 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005761 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005762 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305763 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005764 break;
5765 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005766 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005767 break;
5768 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005769 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005770 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005771 case PORT_E:
5772 intel_encoder->hpd_pin = HPD_PORT_E;
5773 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005774 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005775 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005776 }
5777
Dave Airlie0e32b392014-05-02 14:02:48 +10005778 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00005779 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005780 (port == PORT_B || port == PORT_C || port == PORT_D))
5781 intel_dp_mst_encoder_init(intel_dig_port,
5782 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005783
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005784 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005785 intel_dp_aux_fini(intel_dp);
5786 intel_dp_mst_encoder_cleanup(intel_dig_port);
5787 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005788 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005789
Chris Wilsonf6849602010-09-19 09:29:33 +01005790 intel_dp_add_properties(intel_dp, connector);
5791
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005792 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5793 * 0xd. Failure to do so will result in spurious interrupts being
5794 * generated on the port when a cable is not attached.
5795 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005796 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005797 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5798 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5799 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005800
5801 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005802
5803fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005804 drm_connector_cleanup(connector);
5805
5806 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005807}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005808
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005809bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01005810 i915_reg_t output_reg,
5811 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005812{
5813 struct intel_digital_port *intel_dig_port;
5814 struct intel_encoder *intel_encoder;
5815 struct drm_encoder *encoder;
5816 struct intel_connector *intel_connector;
5817
Daniel Vetterb14c5672013-09-19 12:18:32 +02005818 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005819 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005820 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005821
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005822 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305823 if (!intel_connector)
5824 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005825
5826 intel_encoder = &intel_dig_port->base;
5827 encoder = &intel_encoder->base;
5828
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005829 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
5830 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
5831 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305832 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005833
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005834 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005835 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005836 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005837 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005838 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005839 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005840 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005841 intel_encoder->pre_enable = chv_pre_enable_dp;
5842 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005843 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005844 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005845 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005846 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005847 intel_encoder->pre_enable = vlv_pre_enable_dp;
5848 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005849 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005850 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005851 intel_encoder->pre_enable = g4x_pre_enable_dp;
5852 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005853 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005854 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005855 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005856
Paulo Zanoni174edf12012-10-26 19:05:50 -02005857 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005858 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005859 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005860
Ville Syrjäläcca05022016-06-22 21:57:06 +03005861 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005862 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005863 if (port == PORT_D)
5864 intel_encoder->crtc_mask = 1 << 2;
5865 else
5866 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5867 } else {
5868 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5869 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005870 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005871 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005872
Dave Airlie13cf5502014-06-18 11:29:35 +10005873 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005874 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005875
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305876 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5877 goto err_init_connector;
5878
Chris Wilson457c52d2016-06-01 08:27:50 +01005879 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305880
5881err_init_connector:
5882 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305883err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305884 kfree(intel_connector);
5885err_connector_alloc:
5886 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005887 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005888}
Dave Airlie0e32b392014-05-02 14:02:48 +10005889
5890void intel_dp_mst_suspend(struct drm_device *dev)
5891{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005892 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005893 int i;
5894
5895 /* disable MST */
5896 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005897 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005898
5899 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005900 continue;
5901
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005902 if (intel_dig_port->dp.is_mst)
5903 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005904 }
5905}
5906
5907void intel_dp_mst_resume(struct drm_device *dev)
5908{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005909 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005910 int i;
5911
5912 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005913 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005914 int ret;
5915
5916 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005917 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005918
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005919 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5920 if (ret)
5921 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005922 }
5923}