blob: 10a0e9f149b5ece28a80d53a229d1c3db40bfc17 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Manasi Navare611032b2017-01-24 08:21:49 -080031#include <linux/types.h>
Clint Taylor01527b32014-07-07 13:01:46 -070032#include <linux/notifier.h>
33#include <linux/reboot.h>
Manasi Navare611032b2017-01-24 08:21:49 -080034#include <asm/byteorder.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_crtc.h>
38#include <drm/drm_crtc_helper.h>
Sean Paul20f24d72018-01-08 14:55:43 -050039#include <drm/drm_dp_helper.h>
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/drm_edid.h>
Sean Paul20f24d72018-01-08 14:55:43 -050041#include <drm/drm_hdcp.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010043#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070045
Keith Packarda4fc5ed2009-04-07 16:16:42 -070046#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -070047#define DP_DPRX_ESI_LEN 14
Keith Packarda4fc5ed2009-04-07 16:16:42 -070048
Todd Previte559be302015-05-04 07:48:20 -070049/* Compliance test status bits */
50#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
51#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
52#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
53#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
54
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080055struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 struct dpll dpll;
58};
59
60static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030061 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080062 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
65};
66
67static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030068 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080069 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080071 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
72};
73
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080074static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030075 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080076 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030077 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080078 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
79};
80
Chon Ming Leeef9348c2014-04-09 13:28:18 +030081/*
82 * CHV supports eDP 1.4 that have more link rates.
83 * Below only provides the fixed rate but exclude variable rate.
84 */
85static const struct dp_link_dpll chv_dpll[] = {
86 /*
87 * CHV requires to program fractional division for m2.
88 * m2 is stored in fixed point format using formula below
89 * (m2_int << 22) | m2_fraction
90 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030091 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030092 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030093 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030094 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030095 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030096 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
97};
Sonika Jindal637a9c62015-05-07 09:52:08 +053098
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070099/**
Jani Nikula1853a9d2017-08-18 12:30:20 +0300100 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700101 * @intel_dp: DP struct
102 *
103 * If a CPU or PCH DP output is attached to an eDP panel, this function
104 * will return true, and false otherwise.
105 */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300106bool intel_dp_is_edp(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700107{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200108 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
109
110 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700111}
112
Imre Deak68b4d822013-05-08 13:14:06 +0300113static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114{
Imre Deak68b4d822013-05-08 13:14:06 +0300115 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
116
117 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700118}
119
Chris Wilsondf0e9242010-09-09 16:20:55 +0100120static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
121{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200122 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100123}
124
Ville Syrjäläadc10302017-10-31 22:51:14 +0200125static void intel_dp_link_down(struct intel_encoder *encoder,
126 const struct intel_crtc_state *old_crtc_state);
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äadc10302017-10-31 22:51:14 +0200129static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
130 const struct intel_crtc_state *crtc_state);
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200131static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300132 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530133static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700134
Jani Nikula68f357c2017-03-28 17:59:05 +0300135/* update sink rates from dpcd */
136static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
137{
Jani Nikula229675d2018-02-27 12:59:11 +0200138 static const int dp_rates[] = {
Manasi Navarec71b53c2018-02-28 14:31:50 -0800139 162000, 270000, 540000, 810000
Jani Nikula229675d2018-02-27 12:59:11 +0200140 };
Jani Nikulaa8a08882017-10-09 12:29:59 +0300141 int i, max_rate;
Jani Nikula68f357c2017-03-28 17:59:05 +0300142
Jani Nikulaa8a08882017-10-09 12:29:59 +0300143 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
Jani Nikula68f357c2017-03-28 17:59:05 +0300144
Jani Nikula229675d2018-02-27 12:59:11 +0200145 for (i = 0; i < ARRAY_SIZE(dp_rates); i++) {
146 if (dp_rates[i] > max_rate)
Jani Nikulaa8a08882017-10-09 12:29:59 +0300147 break;
Jani Nikula229675d2018-02-27 12:59:11 +0200148 intel_dp->sink_rates[i] = dp_rates[i];
Jani Nikulaa8a08882017-10-09 12:29:59 +0300149 }
Jani Nikula68f357c2017-03-28 17:59:05 +0300150
Jani Nikulaa8a08882017-10-09 12:29:59 +0300151 intel_dp->num_sink_rates = i;
Jani Nikula68f357c2017-03-28 17:59:05 +0300152}
153
Jani Nikula10ebb732018-02-01 13:03:41 +0200154/* Get length of rates array potentially limited by max_rate. */
155static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate)
156{
157 int i;
158
159 /* Limit results by potentially reduced max rate */
160 for (i = 0; i < len; i++) {
161 if (rates[len - i - 1] <= max_rate)
162 return len - i;
163 }
164
165 return 0;
166}
167
168/* Get length of common rates array potentially limited by max_rate. */
169static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp,
170 int max_rate)
171{
172 return intel_dp_rate_limit_len(intel_dp->common_rates,
173 intel_dp->num_common_rates, max_rate);
174}
175
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300176/* Theoretical max between source and sink */
177static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700178{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300179 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700180}
181
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300182/* Theoretical max between source and sink */
183static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300184{
185 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300186 int source_max = intel_dig_port->max_lanes;
187 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300188
189 return min(source_max, sink_max);
190}
191
Jani Nikula3d65a732017-04-06 16:44:14 +0300192int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300193{
194 return intel_dp->max_link_lane_count;
195}
196
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800197int
Keith Packardc8982612012-01-25 08:16:25 -0800198intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700199{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800200 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
201 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700202}
203
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800204int
Dave Airliefe27d532010-06-30 11:46:17 +1000205intel_dp_max_data_rate(int max_link_clock, int max_lanes)
206{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800207 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
208 * link rate that is generally expressed in Gbps. Since, 8 bits of data
209 * is transmitted every LS_Clk per lane, there is no need to account for
210 * the channel encoding that is done in the PHY layer here.
211 */
212
213 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000214}
215
Mika Kahola70ec0642016-09-09 14:10:55 +0300216static int
217intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
218{
219 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
220 struct intel_encoder *encoder = &intel_dig_port->base;
221 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
222 int max_dotclk = dev_priv->max_dotclk_freq;
223 int ds_max_dotclk;
224
225 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
226
227 if (type != DP_DS_PORT_TYPE_VGA)
228 return max_dotclk;
229
230 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
231 intel_dp->downstream_ports);
232
233 if (ds_max_dotclk != 0)
234 max_dotclk = min(max_dotclk, ds_max_dotclk);
235
236 return max_dotclk;
237}
238
Jani Nikula4ba285d2018-02-01 13:03:42 +0200239static int cnl_max_source_rate(struct intel_dp *intel_dp)
Rodrigo Vivi53ddb3c2018-01-29 15:22:23 -0800240{
241 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
242 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
243 enum port port = dig_port->base.port;
244
245 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
246
247 /* Low voltage SKUs are limited to max of 5.4G */
248 if (voltage == VOLTAGE_INFO_0_85V)
Jani Nikula4ba285d2018-02-01 13:03:42 +0200249 return 540000;
Rodrigo Vivi53ddb3c2018-01-29 15:22:23 -0800250
251 /* For this SKU 8.1G is supported in all ports */
252 if (IS_CNL_WITH_PORT_F(dev_priv))
Jani Nikula4ba285d2018-02-01 13:03:42 +0200253 return 810000;
Rodrigo Vivi53ddb3c2018-01-29 15:22:23 -0800254
David Weinehall3758d962018-02-09 15:07:55 +0200255 /* For other SKUs, max rate on ports A and D is 5.4G */
Rodrigo Vivi53ddb3c2018-01-29 15:22:23 -0800256 if (port == PORT_A || port == PORT_D)
Jani Nikula4ba285d2018-02-01 13:03:42 +0200257 return 540000;
Rodrigo Vivi53ddb3c2018-01-29 15:22:23 -0800258
Jani Nikula4ba285d2018-02-01 13:03:42 +0200259 return 810000;
Rodrigo Vivi53ddb3c2018-01-29 15:22:23 -0800260}
261
Jani Nikula55cfc582017-03-28 17:59:04 +0300262static void
263intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700264{
Jani Nikula229675d2018-02-27 12:59:11 +0200265 /* The values must be in increasing order */
266 static const int cnl_rates[] = {
267 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000
268 };
269 static const int bxt_rates[] = {
270 162000, 216000, 243000, 270000, 324000, 432000, 540000
271 };
272 static const int skl_rates[] = {
273 162000, 216000, 270000, 324000, 432000, 540000
274 };
275 static const int hsw_rates[] = {
276 162000, 270000, 540000
277 };
278 static const int g4x_rates[] = {
279 162000, 270000
280 };
Navare, Manasi D40dba342016-10-26 16:25:55 -0700281 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
282 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Jani Nikula99b91bd2018-02-01 13:03:43 +0200283 const struct ddi_vbt_port_info *info =
284 &dev_priv->vbt.ddi_port_info[dig_port->base.port];
Jani Nikula55cfc582017-03-28 17:59:04 +0300285 const int *source_rates;
Jani Nikula99b91bd2018-02-01 13:03:43 +0200286 int size, max_rate = 0, vbt_max_rate = info->dp_max_link_rate;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700287
Jani Nikula55cfc582017-03-28 17:59:04 +0300288 /* This should only be done once */
289 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
290
Manasi Navareba1c06a2018-02-26 19:11:15 -0800291 if (IS_CANNONLAKE(dev_priv)) {
Rodrigo Vivid907b662017-08-10 15:40:08 -0700292 source_rates = cnl_rates;
Jani Nikula4ba285d2018-02-01 13:03:42 +0200293 size = ARRAY_SIZE(cnl_rates);
294 max_rate = cnl_max_source_rate(intel_dp);
Manasi Navareba1c06a2018-02-26 19:11:15 -0800295 } else if (IS_GEN9_LP(dev_priv)) {
296 source_rates = bxt_rates;
297 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800298 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300299 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700300 size = ARRAY_SIZE(skl_rates);
Jani Nikulafc603ca2017-10-09 12:29:58 +0300301 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
302 IS_BROADWELL(dev_priv)) {
Jani Nikula229675d2018-02-27 12:59:11 +0200303 source_rates = hsw_rates;
304 size = ARRAY_SIZE(hsw_rates);
Jani Nikulafc603ca2017-10-09 12:29:58 +0300305 } else {
Jani Nikula229675d2018-02-27 12:59:11 +0200306 source_rates = g4x_rates;
307 size = ARRAY_SIZE(g4x_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700308 }
309
Jani Nikula99b91bd2018-02-01 13:03:43 +0200310 if (max_rate && vbt_max_rate)
311 max_rate = min(max_rate, vbt_max_rate);
312 else if (vbt_max_rate)
313 max_rate = vbt_max_rate;
314
Jani Nikula4ba285d2018-02-01 13:03:42 +0200315 if (max_rate)
316 size = intel_dp_rate_limit_len(source_rates, size, max_rate);
317
Jani Nikula55cfc582017-03-28 17:59:04 +0300318 intel_dp->source_rates = source_rates;
319 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700320}
321
322static int intersect_rates(const int *source_rates, int source_len,
323 const int *sink_rates, int sink_len,
324 int *common_rates)
325{
326 int i = 0, j = 0, k = 0;
327
328 while (i < source_len && j < sink_len) {
329 if (source_rates[i] == sink_rates[j]) {
330 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
331 return k;
332 common_rates[k] = source_rates[i];
333 ++k;
334 ++i;
335 ++j;
336 } else if (source_rates[i] < sink_rates[j]) {
337 ++i;
338 } else {
339 ++j;
340 }
341 }
342 return k;
343}
344
Jani Nikula8001b752017-03-28 17:59:03 +0300345/* return index of rate in rates array, or -1 if not found */
346static int intel_dp_rate_index(const int *rates, int len, int rate)
347{
348 int i;
349
350 for (i = 0; i < len; i++)
351 if (rate == rates[i])
352 return i;
353
354 return -1;
355}
356
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300357static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700358{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300359 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700360
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300361 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
362 intel_dp->num_source_rates,
363 intel_dp->sink_rates,
364 intel_dp->num_sink_rates,
365 intel_dp->common_rates);
366
367 /* Paranoia, there should always be something in common. */
368 if (WARN_ON(intel_dp->num_common_rates == 0)) {
Jani Nikula229675d2018-02-27 12:59:11 +0200369 intel_dp->common_rates[0] = 162000;
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300370 intel_dp->num_common_rates = 1;
371 }
372}
373
Manasi Navare1a92c702017-06-08 13:41:02 -0700374static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
375 uint8_t lane_count)
Manasi Navare14c562c2017-04-06 14:00:12 -0700376{
377 /*
378 * FIXME: we need to synchronize the current link parameters with
379 * hardware readout. Currently fast link training doesn't work on
380 * boot-up.
381 */
Manasi Navare1a92c702017-06-08 13:41:02 -0700382 if (link_rate == 0 ||
383 link_rate > intel_dp->max_link_rate)
Manasi Navare14c562c2017-04-06 14:00:12 -0700384 return false;
385
Manasi Navare1a92c702017-06-08 13:41:02 -0700386 if (lane_count == 0 ||
387 lane_count > intel_dp_max_lane_count(intel_dp))
Manasi Navare14c562c2017-04-06 14:00:12 -0700388 return false;
389
390 return true;
391}
392
Manasi Navarefdb14d32016-12-08 19:05:12 -0800393int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
394 int link_rate, uint8_t lane_count)
395{
Jani Nikulab1810a72017-04-06 16:44:11 +0300396 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800397
Jani Nikulab1810a72017-04-06 16:44:11 +0300398 index = intel_dp_rate_index(intel_dp->common_rates,
399 intel_dp->num_common_rates,
400 link_rate);
401 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300402 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
403 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800404 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300405 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300406 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800407 } else {
408 DRM_ERROR("Link Training Unsuccessful\n");
409 return -1;
410 }
411
412 return 0;
413}
414
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000415static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700416intel_dp_mode_valid(struct drm_connector *connector,
417 struct drm_display_mode *mode)
418{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100419 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300420 struct intel_connector *intel_connector = to_intel_connector(connector);
421 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100422 int target_clock = mode->clock;
423 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300424 int max_dotclk;
425
426 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700427
Jani Nikula1853a9d2017-08-18 12:30:20 +0300428 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
Jani Nikuladd06f902012-10-19 14:51:50 +0300429 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100430 return MODE_PANEL;
431
Jani Nikuladd06f902012-10-19 14:51:50 +0300432 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100433 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200434
435 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100436 }
437
Ville Syrjälä50fec212015-03-12 17:10:34 +0200438 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300439 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100440
441 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
442 mode_rate = intel_dp_link_required(target_clock, 18);
443
Mika Kahola799487f2016-02-02 15:16:38 +0200444 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200445 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700446
447 if (mode->clock < 10000)
448 return MODE_CLOCK_LOW;
449
Daniel Vetter0af78a22012-05-23 11:30:55 +0200450 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
451 return MODE_H_ILLEGAL;
452
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700453 return MODE_OK;
454}
455
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800456uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700457{
458 int i;
459 uint32_t v = 0;
460
461 if (src_bytes > 4)
462 src_bytes = 4;
463 for (i = 0; i < src_bytes; i++)
464 v |= ((uint32_t) src[i]) << ((3-i) * 8);
465 return v;
466}
467
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000468static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700469{
470 int i;
471 if (dst_bytes > 4)
472 dst_bytes = 4;
473 for (i = 0; i < dst_bytes; i++)
474 dst[i] = src >> ((3-i) * 8);
475}
476
Jani Nikulabf13e812013-09-06 07:40:05 +0300477static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200478intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300479static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200480intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200481 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300482static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200483intel_dp_pps_init(struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300484
Ville Syrjälä773538e82014-09-04 14:54:56 +0300485static void pps_lock(struct intel_dp *intel_dp)
486{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200487 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä773538e82014-09-04 14:54:56 +0300488
489 /*
Lucas De Marchi40c7ae42017-11-13 16:46:38 -0800490 * See intel_power_sequencer_reset() why we need
Ville Syrjälä773538e82014-09-04 14:54:56 +0300491 * a power domain reference here.
492 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200493 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300494
495 mutex_lock(&dev_priv->pps_mutex);
496}
497
498static void pps_unlock(struct intel_dp *intel_dp)
499{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200500 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä773538e82014-09-04 14:54:56 +0300501
502 mutex_unlock(&dev_priv->pps_mutex);
503
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200504 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300505}
506
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300507static void
508vlv_power_sequencer_kick(struct intel_dp *intel_dp)
509{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200510 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300511 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300512 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300513 bool pll_enabled, release_cl_override = false;
514 enum dpio_phy phy = DPIO_PHY(pipe);
515 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300516 uint32_t DP;
517
518 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
519 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200520 pipe_name(pipe), port_name(intel_dig_port->base.port)))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300521 return;
522
523 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200524 pipe_name(pipe), port_name(intel_dig_port->base.port));
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300525
526 /* Preserve the BIOS-computed detected bit. This is
527 * supposed to be read-only.
528 */
529 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
530 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
531 DP |= DP_PORT_WIDTH(1);
532 DP |= DP_LINK_TRAIN_PAT_1;
533
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100534 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300535 DP |= DP_PIPE_SELECT_CHV(pipe);
536 else if (pipe == PIPE_B)
537 DP |= DP_PIPEB_SELECT;
538
Ville Syrjäläd288f652014-10-28 13:20:22 +0200539 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
540
541 /*
542 * The DPLL for the pipe must be enabled for this to work.
543 * So enable temporarily it if it's not already enabled.
544 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300545 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100546 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300547 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
548
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200549 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000550 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
551 DRM_ERROR("Failed to force on pll for pipe %c!\n",
552 pipe_name(pipe));
553 return;
554 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300555 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200556
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300557 /*
558 * Similar magic as in intel_dp_enable_port().
559 * We _must_ do this port enable + disable trick
560 * to make this power seqeuencer lock onto the port.
561 * Otherwise even VDD force bit won't work.
562 */
563 I915_WRITE(intel_dp->output_reg, DP);
564 POSTING_READ(intel_dp->output_reg);
565
566 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
567 POSTING_READ(intel_dp->output_reg);
568
569 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
570 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200571
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300572 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200573 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300574
575 if (release_cl_override)
576 chv_phy_powergate_ch(dev_priv, phy, ch, false);
577 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300578}
579
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200580static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
581{
582 struct intel_encoder *encoder;
583 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
584
585 /*
586 * We don't have power sequencer currently.
587 * Pick one that's not used by other ports.
588 */
589 for_each_intel_encoder(&dev_priv->drm, encoder) {
590 struct intel_dp *intel_dp;
591
592 if (encoder->type != INTEL_OUTPUT_DP &&
593 encoder->type != INTEL_OUTPUT_EDP)
594 continue;
595
596 intel_dp = enc_to_intel_dp(&encoder->base);
597
598 if (encoder->type == INTEL_OUTPUT_EDP) {
599 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
600 intel_dp->active_pipe != intel_dp->pps_pipe);
601
602 if (intel_dp->pps_pipe != INVALID_PIPE)
603 pipes &= ~(1 << intel_dp->pps_pipe);
604 } else {
605 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
606
607 if (intel_dp->active_pipe != INVALID_PIPE)
608 pipes &= ~(1 << intel_dp->active_pipe);
609 }
610 }
611
612 if (pipes == 0)
613 return INVALID_PIPE;
614
615 return ffs(pipes) - 1;
616}
617
Jani Nikulabf13e812013-09-06 07:40:05 +0300618static enum pipe
619vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
620{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200621 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Jani Nikulabf13e812013-09-06 07:40:05 +0300622 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300623 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300624
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300625 lockdep_assert_held(&dev_priv->pps_mutex);
626
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300627 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300628 WARN_ON(!intel_dp_is_edp(intel_dp));
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300629
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200630 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
631 intel_dp->active_pipe != intel_dp->pps_pipe);
632
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300633 if (intel_dp->pps_pipe != INVALID_PIPE)
634 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300635
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200636 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300637
638 /*
639 * Didn't find one. This should not happen since there
640 * are two power sequencers and up to two eDP ports.
641 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200642 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300643 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300644
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200645 vlv_steal_power_sequencer(dev_priv, pipe);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300646 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300647
648 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
649 pipe_name(intel_dp->pps_pipe),
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200650 port_name(intel_dig_port->base.port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300651
652 /* init power sequencer on this pipe and port */
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200653 intel_dp_init_panel_power_sequencer(intel_dp);
654 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300655
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300656 /*
657 * Even vdd force doesn't work until we've made
658 * the power sequencer lock in on the port.
659 */
660 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300661
662 return intel_dp->pps_pipe;
663}
664
Imre Deak78597992016-06-16 16:37:20 +0300665static int
666bxt_power_sequencer_idx(struct intel_dp *intel_dp)
667{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200668 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Mustamin B Mustaffa73c0fca2018-02-27 11:07:34 +0800669 int backlight_controller = dev_priv->vbt.backlight.controller;
Imre Deak78597992016-06-16 16:37:20 +0300670
671 lockdep_assert_held(&dev_priv->pps_mutex);
672
673 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300674 WARN_ON(!intel_dp_is_edp(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300675
Imre Deak78597992016-06-16 16:37:20 +0300676 if (!intel_dp->pps_reset)
Mustamin B Mustaffa73c0fca2018-02-27 11:07:34 +0800677 return backlight_controller;
Imre Deak78597992016-06-16 16:37:20 +0300678
679 intel_dp->pps_reset = false;
680
681 /*
682 * Only the HW needs to be reprogrammed, the SW state is fixed and
683 * has been setup during connector init.
684 */
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200685 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300686
Mustamin B Mustaffa73c0fca2018-02-27 11:07:34 +0800687 return backlight_controller;
Imre Deak78597992016-06-16 16:37:20 +0300688}
689
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300690typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
691 enum pipe pipe);
692
693static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
694 enum pipe pipe)
695{
Imre Deak44cb7342016-08-10 14:07:29 +0300696 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300697}
698
699static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
700 enum pipe pipe)
701{
Imre Deak44cb7342016-08-10 14:07:29 +0300702 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300703}
704
705static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
706 enum pipe pipe)
707{
708 return true;
709}
710
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300711static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300712vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
713 enum port port,
714 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300715{
Jani Nikulabf13e812013-09-06 07:40:05 +0300716 enum pipe pipe;
717
Jani Nikulabf13e812013-09-06 07:40:05 +0300718 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300719 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300720 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300721
722 if (port_sel != PANEL_PORT_SELECT_VLV(port))
723 continue;
724
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300725 if (!pipe_check(dev_priv, pipe))
726 continue;
727
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300728 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300729 }
730
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300731 return INVALID_PIPE;
732}
733
734static void
735vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
736{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200737 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300738 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200739 enum port port = intel_dig_port->base.port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300740
741 lockdep_assert_held(&dev_priv->pps_mutex);
742
743 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300744 /* first pick one where the panel is on */
745 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
746 vlv_pipe_has_pp_on);
747 /* didn't find one? pick one where vdd is on */
748 if (intel_dp->pps_pipe == INVALID_PIPE)
749 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
750 vlv_pipe_has_vdd_on);
751 /* didn't find one? pick one with just the correct port */
752 if (intel_dp->pps_pipe == INVALID_PIPE)
753 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
754 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300755
756 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
757 if (intel_dp->pps_pipe == INVALID_PIPE) {
758 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
759 port_name(port));
760 return;
761 }
762
763 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
764 port_name(port), pipe_name(intel_dp->pps_pipe));
765
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200766 intel_dp_init_panel_power_sequencer(intel_dp);
767 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300768}
769
Imre Deak78597992016-06-16 16:37:20 +0300770void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300771{
Ville Syrjälä773538e82014-09-04 14:54:56 +0300772 struct intel_encoder *encoder;
773
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100774 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200775 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300776 return;
777
778 /*
779 * We can't grab pps_mutex here due to deadlock with power_domain
780 * mutex when power_domain functions are called while holding pps_mutex.
781 * That also means that in order to use pps_pipe the code needs to
782 * hold both a power domain reference and pps_mutex, and the power domain
783 * reference get/put must be done while _not_ holding pps_mutex.
784 * pps_{lock,unlock}() do these steps in the correct order, so one
785 * should use them always.
786 */
787
Ville Syrjälä2f773472017-11-09 17:27:58 +0200788 for_each_intel_encoder(&dev_priv->drm, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300789 struct intel_dp *intel_dp;
790
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200791 if (encoder->type != INTEL_OUTPUT_DP &&
Ville Syrjälä7e732ca2017-10-27 22:31:24 +0300792 encoder->type != INTEL_OUTPUT_EDP &&
793 encoder->type != INTEL_OUTPUT_DDI)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300794 continue;
795
796 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200797
Ville Syrjälä7e732ca2017-10-27 22:31:24 +0300798 /* Skip pure DVI/HDMI DDI encoders */
799 if (!i915_mmio_reg_valid(intel_dp->output_reg))
800 continue;
801
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200802 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
803
804 if (encoder->type != INTEL_OUTPUT_EDP)
805 continue;
806
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200807 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300808 intel_dp->pps_reset = true;
809 else
810 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300811 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300812}
813
Imre Deak8e8232d2016-06-16 16:37:21 +0300814struct pps_registers {
815 i915_reg_t pp_ctrl;
816 i915_reg_t pp_stat;
817 i915_reg_t pp_on;
818 i915_reg_t pp_off;
819 i915_reg_t pp_div;
820};
821
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200822static void intel_pps_get_registers(struct intel_dp *intel_dp,
Imre Deak8e8232d2016-06-16 16:37:21 +0300823 struct pps_registers *regs)
824{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200825 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak44cb7342016-08-10 14:07:29 +0300826 int pps_idx = 0;
827
Imre Deak8e8232d2016-06-16 16:37:21 +0300828 memset(regs, 0, sizeof(*regs));
829
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200830 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300831 pps_idx = bxt_power_sequencer_idx(intel_dp);
832 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
833 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300834
Imre Deak44cb7342016-08-10 14:07:29 +0300835 regs->pp_ctrl = PP_CONTROL(pps_idx);
836 regs->pp_stat = PP_STATUS(pps_idx);
837 regs->pp_on = PP_ON_DELAYS(pps_idx);
838 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Anusha Srivatsab0d6a0f2018-01-11 16:00:07 -0200839 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) &&
840 !HAS_PCH_ICP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300841 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300842}
843
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200844static i915_reg_t
845_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300846{
Imre Deak8e8232d2016-06-16 16:37:21 +0300847 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300848
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200849 intel_pps_get_registers(intel_dp, &regs);
Imre Deak8e8232d2016-06-16 16:37:21 +0300850
851 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300852}
853
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200854static i915_reg_t
855_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300856{
Imre Deak8e8232d2016-06-16 16:37:21 +0300857 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300858
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200859 intel_pps_get_registers(intel_dp, &regs);
Imre Deak8e8232d2016-06-16 16:37:21 +0300860
861 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300862}
863
Clint Taylor01527b32014-07-07 13:01:46 -0700864/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
865 This function only applicable when panel PM state is not to be tracked */
866static int edp_notify_handler(struct notifier_block *this, unsigned long code,
867 void *unused)
868{
869 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
870 edp_notifier);
Ville Syrjälä2f773472017-11-09 17:27:58 +0200871 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Clint Taylor01527b32014-07-07 13:01:46 -0700872
Jani Nikula1853a9d2017-08-18 12:30:20 +0300873 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
Clint Taylor01527b32014-07-07 13:01:46 -0700874 return 0;
875
Ville Syrjälä773538e82014-09-04 14:54:56 +0300876 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300877
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100878 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300879 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200880 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300881 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300882
Imre Deak44cb7342016-08-10 14:07:29 +0300883 pp_ctrl_reg = PP_CONTROL(pipe);
884 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700885 pp_div = I915_READ(pp_div_reg);
886 pp_div &= PP_REFERENCE_DIVIDER_MASK;
887
888 /* 0x1F write to PP_DIV_REG sets max cycle delay */
889 I915_WRITE(pp_div_reg, pp_div | 0x1F);
890 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
891 msleep(intel_dp->panel_power_cycle_delay);
892 }
893
Ville Syrjälä773538e82014-09-04 14:54:56 +0300894 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300895
Clint Taylor01527b32014-07-07 13:01:46 -0700896 return 0;
897}
898
Daniel Vetter4be73782014-01-17 14:39:48 +0100899static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700900{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200901 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Keith Packardebf33b12011-09-29 15:53:27 -0700902
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300903 lockdep_assert_held(&dev_priv->pps_mutex);
904
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100905 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300906 intel_dp->pps_pipe == INVALID_PIPE)
907 return false;
908
Jani Nikulabf13e812013-09-06 07:40:05 +0300909 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700910}
911
Daniel Vetter4be73782014-01-17 14:39:48 +0100912static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700913{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200914 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Keith Packardebf33b12011-09-29 15:53:27 -0700915
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300916 lockdep_assert_held(&dev_priv->pps_mutex);
917
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100918 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300919 intel_dp->pps_pipe == INVALID_PIPE)
920 return false;
921
Ville Syrjälä773538e82014-09-04 14:54:56 +0300922 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700923}
924
Keith Packard9b984da2011-09-19 13:54:47 -0700925static void
926intel_dp_check_edp(struct intel_dp *intel_dp)
927{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200928 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Keith Packardebf33b12011-09-29 15:53:27 -0700929
Jani Nikula1853a9d2017-08-18 12:30:20 +0300930 if (!intel_dp_is_edp(intel_dp))
Keith Packard9b984da2011-09-19 13:54:47 -0700931 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700932
Daniel Vetter4be73782014-01-17 14:39:48 +0100933 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700934 WARN(1, "eDP powered off while attempting aux channel communication.\n");
935 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300936 I915_READ(_pp_stat_reg(intel_dp)),
937 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700938 }
939}
940
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100941static uint32_t
942intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
943{
Ville Syrjälä2f773472017-11-09 17:27:58 +0200944 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä4904fa62018-02-22 20:10:31 +0200945 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100946 uint32_t status;
947 bool done;
948
Daniel Vetteref04f002012-12-01 21:03:59 +0100949#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100950 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300951 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300952 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100953 else
Imre Deak713a6b662016-06-28 13:37:33 +0300954 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100955 if (!done)
956 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
957 has_aux_irq);
958#undef C
959
960 return status;
961}
962
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200963static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000964{
Ville Syrjälä449059a2018-02-22 20:10:33 +0200965 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000966
Ville Syrjäläa457f542016-03-02 17:22:17 +0200967 if (index)
968 return 0;
969
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000970 /*
971 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200972 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000973 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200974 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000975}
976
977static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
978{
Ville Syrjälä449059a2018-02-22 20:10:33 +0200979 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000980
981 if (index)
982 return 0;
983
Ville Syrjäläa457f542016-03-02 17:22:17 +0200984 /*
985 * The clock divider is based off the cdclk or PCH rawclk, and would
986 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
987 * divide by 2000 and use that
988 */
Ville Syrjälä449059a2018-02-22 20:10:33 +0200989 if (intel_dp->aux_ch == AUX_CH_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200990 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200991 else
992 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000993}
994
995static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300996{
Ville Syrjälä449059a2018-02-22 20:10:33 +0200997 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300998
Ville Syrjälä449059a2018-02-22 20:10:33 +0200999 if (intel_dp->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -03001000 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +01001001 switch (index) {
1002 case 0: return 63;
1003 case 1: return 72;
1004 default: return 0;
1005 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -03001006 }
Ville Syrjäläa457f542016-03-02 17:22:17 +02001007
1008 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -03001009}
1010
Damien Lespiaub6b5e382014-01-20 16:00:59 +00001011static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1012{
1013 /*
1014 * SKL doesn't need us to program the AUX clock divider (Hardware will
1015 * derive the clock from CDCLK automatically). We still implement the
1016 * get_aux_clock_divider vfunc to plug-in into the existing code.
1017 */
1018 return index ? 0 : 1;
1019}
1020
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02001021static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1022 bool has_aux_irq,
1023 int send_bytes,
1024 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001025{
1026 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001027 struct drm_i915_private *dev_priv =
1028 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001029 uint32_t precharge, timeout;
1030
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001031 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001032 precharge = 3;
1033 else
1034 precharge = 5;
1035
James Ausmus8f5f63d2017-10-12 14:30:37 -07001036 if (IS_BROADWELL(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001037 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1038 else
1039 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1040
1041 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001042 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001043 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001044 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001045 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001046 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001047 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1048 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001049 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001050}
1051
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001052static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1053 bool has_aux_irq,
1054 int send_bytes,
1055 uint32_t unused)
1056{
1057 return DP_AUX_CH_CTL_SEND_BUSY |
1058 DP_AUX_CH_CTL_DONE |
1059 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1060 DP_AUX_CH_CTL_TIME_OUT_ERROR |
James Ausmus6fa228b2017-10-12 14:30:36 -07001061 DP_AUX_CH_CTL_TIME_OUT_MAX |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001062 DP_AUX_CH_CTL_RECEIVE_ERROR |
1063 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001064 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001065 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1066}
1067
Sean Paul20f24d72018-01-08 14:55:43 -05001068static uint32_t intel_dp_get_aux_send_ctl(struct intel_dp *intel_dp,
1069 bool has_aux_irq,
1070 int send_bytes,
1071 uint32_t aux_clock_divider,
1072 bool aksv_write)
1073{
1074 uint32_t val = 0;
1075
1076 if (aksv_write) {
1077 send_bytes += 5;
1078 val |= DP_AUX_CH_CTL_AUX_AKSV_SELECT;
1079 }
1080
1081 return val | intel_dp->get_aux_send_ctl(intel_dp,
1082 has_aux_irq,
1083 send_bytes,
1084 aux_clock_divider);
1085}
1086
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001087static int
Ville Syrjäläf7606262018-02-22 20:10:34 +02001088intel_dp_aux_xfer(struct intel_dp *intel_dp,
1089 const uint8_t *send, int send_bytes,
1090 uint8_t *recv, int recv_size, bool aksv_write)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001091{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001092 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001093 struct drm_i915_private *dev_priv =
1094 to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001095 i915_reg_t ch_ctl, ch_data[5];
Chris Wilsonbc866252013-07-21 16:00:03 +01001096 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001097 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001098 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001099 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001100 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001101 bool vdd;
1102
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001103 ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
1104 for (i = 0; i < ARRAY_SIZE(ch_data); i++)
1105 ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
1106
Ville Syrjälä773538e82014-09-04 14:54:56 +03001107 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001108
Ville Syrjälä72c35002014-08-18 22:16:00 +03001109 /*
1110 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1111 * In such cases we want to leave VDD enabled and it's up to upper layers
1112 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1113 * ourselves.
1114 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001115 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001116
1117 /* dp aux is extremely sensitive to irq latency, hence request the
1118 * lowest possible wakeup latency and so prevent the cpu from going into
1119 * deep sleep states.
1120 */
1121 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001122
Keith Packard9b984da2011-09-19 13:54:47 -07001123 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001124
Jesse Barnes11bee432011-08-01 15:02:20 -07001125 /* Try to wait for any previous AUX channel activity */
1126 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001127 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001128 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1129 break;
1130 msleep(1);
1131 }
1132
1133 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001134 static u32 last_status = -1;
1135 const u32 status = I915_READ(ch_ctl);
1136
1137 if (status != last_status) {
1138 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1139 status);
1140 last_status = status;
1141 }
1142
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001143 ret = -EBUSY;
1144 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001145 }
1146
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001147 /* Only 5 data registers! */
1148 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1149 ret = -E2BIG;
1150 goto out;
1151 }
1152
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001153 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Sean Paul20f24d72018-01-08 14:55:43 -05001154 u32 send_ctl = intel_dp_get_aux_send_ctl(intel_dp,
1155 has_aux_irq,
1156 send_bytes,
1157 aux_clock_divider,
1158 aksv_write);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001159
Chris Wilsonbc866252013-07-21 16:00:03 +01001160 /* Must try at least 3 times according to DP spec */
1161 for (try = 0; try < 5; try++) {
1162 /* Load the send data into the aux channel data registers */
1163 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001164 I915_WRITE(ch_data[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001165 intel_dp_pack_aux(send + i,
1166 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001167
Chris Wilsonbc866252013-07-21 16:00:03 +01001168 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001169 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001170
Chris Wilsonbc866252013-07-21 16:00:03 +01001171 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001172
Chris Wilsonbc866252013-07-21 16:00:03 +01001173 /* Clear done status and any errors */
1174 I915_WRITE(ch_ctl,
1175 status |
1176 DP_AUX_CH_CTL_DONE |
1177 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1178 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001179
Todd Previte74ebf292015-04-15 08:38:41 -07001180 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1181 * 400us delay required for errors and timeouts
1182 * Timeout errors from the HW already meet this
1183 * requirement so skip to next iteration
1184 */
Dhinakaran Pandiyan3975f0a2018-02-23 14:15:20 -08001185 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
1186 continue;
1187
Todd Previte74ebf292015-04-15 08:38:41 -07001188 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1189 usleep_range(400, 500);
1190 continue;
1191 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001192 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001193 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001194 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001195 }
1196
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001197 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001198 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001199 ret = -EBUSY;
1200 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001201 }
1202
Jim Bridee058c942015-05-27 10:21:48 -07001203done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001204 /* Check for timeout or receive error.
1205 * Timeouts occur when the sink is not connected
1206 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001207 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001208 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001209 ret = -EIO;
1210 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001211 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001212
1213 /* Timeouts occur when the device isn't connected, so they're
1214 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001215 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001216 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001217 ret = -ETIMEDOUT;
1218 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001219 }
1220
1221 /* Unload any bytes sent back from the other side */
1222 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1223 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001224
1225 /*
1226 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1227 * We have no idea of what happened so we return -EBUSY so
1228 * drm layer takes care for the necessary retries.
1229 */
1230 if (recv_bytes == 0 || recv_bytes > 20) {
1231 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1232 recv_bytes);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001233 ret = -EBUSY;
1234 goto out;
1235 }
1236
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001237 if (recv_bytes > recv_size)
1238 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001239
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001240 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001241 intel_dp_unpack_aux(I915_READ(ch_data[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001242 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001243
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001244 ret = recv_bytes;
1245out:
1246 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1247
Jani Nikula884f19e2014-03-14 16:51:14 +02001248 if (vdd)
1249 edp_panel_vdd_off(intel_dp, false);
1250
Ville Syrjälä773538e82014-09-04 14:54:56 +03001251 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001252
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001253 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001254}
1255
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001256#define BARE_ADDRESS_SIZE 3
1257#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001258static ssize_t
1259intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001260{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001261 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1262 uint8_t txbuf[20], rxbuf[20];
1263 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001264 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001265
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001266 txbuf[0] = (msg->request << 4) |
1267 ((msg->address >> 16) & 0xf);
1268 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001269 txbuf[2] = msg->address & 0xff;
1270 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001271
Jani Nikula9d1a1032014-03-14 16:51:15 +02001272 switch (msg->request & ~DP_AUX_I2C_MOT) {
1273 case DP_AUX_NATIVE_WRITE:
1274 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001275 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001276 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001277 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001278
Jani Nikula9d1a1032014-03-14 16:51:15 +02001279 if (WARN_ON(txsize > 20))
1280 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001281
Ville Syrjälädd788092016-07-28 17:55:04 +03001282 WARN_ON(!msg->buffer != !msg->size);
1283
Imre Deakd81a67c2016-01-29 14:52:26 +02001284 if (msg->buffer)
1285 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001286
Ville Syrjäläf7606262018-02-22 20:10:34 +02001287 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
1288 rxbuf, rxsize, false);
Jani Nikula9d1a1032014-03-14 16:51:15 +02001289 if (ret > 0) {
1290 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001291
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001292 if (ret > 1) {
1293 /* Number of bytes written in a short write. */
1294 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1295 } else {
1296 /* Return payload size. */
1297 ret = msg->size;
1298 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001299 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001300 break;
1301
1302 case DP_AUX_NATIVE_READ:
1303 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001304 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001305 rxsize = msg->size + 1;
1306
1307 if (WARN_ON(rxsize > 20))
1308 return -E2BIG;
1309
Ville Syrjäläf7606262018-02-22 20:10:34 +02001310 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
1311 rxbuf, rxsize, false);
Jani Nikula9d1a1032014-03-14 16:51:15 +02001312 if (ret > 0) {
1313 msg->reply = rxbuf[0] >> 4;
1314 /*
1315 * Assume happy day, and copy the data. The caller is
1316 * expected to check msg->reply before touching it.
1317 *
1318 * Return payload size.
1319 */
1320 ret--;
1321 memcpy(msg->buffer, rxbuf + 1, ret);
1322 }
1323 break;
1324
1325 default:
1326 ret = -EINVAL;
1327 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001328 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001329
Jani Nikula9d1a1032014-03-14 16:51:15 +02001330 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001331}
1332
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001333static enum aux_ch intel_aux_ch(struct intel_dp *intel_dp)
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001334{
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001335 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1336 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1337 enum port port = encoder->port;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001338 const struct ddi_vbt_port_info *info =
1339 &dev_priv->vbt.ddi_port_info[port];
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001340 enum aux_ch aux_ch;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001341
1342 if (!info->alternate_aux_channel) {
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001343 aux_ch = (enum aux_ch) port;
1344
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001345 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001346 aux_ch_name(aux_ch), port_name(port));
1347 return aux_ch;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001348 }
1349
1350 switch (info->alternate_aux_channel) {
1351 case DP_AUX_A:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001352 aux_ch = AUX_CH_A;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001353 break;
1354 case DP_AUX_B:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001355 aux_ch = AUX_CH_B;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001356 break;
1357 case DP_AUX_C:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001358 aux_ch = AUX_CH_C;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001359 break;
1360 case DP_AUX_D:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001361 aux_ch = AUX_CH_D;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001362 break;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001363 case DP_AUX_F:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001364 aux_ch = AUX_CH_F;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001365 break;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001366 default:
1367 MISSING_CASE(info->alternate_aux_channel);
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001368 aux_ch = AUX_CH_A;
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001369 break;
1370 }
1371
1372 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001373 aux_ch_name(aux_ch), port_name(port));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001374
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001375 return aux_ch;
1376}
1377
1378static enum intel_display_power_domain
1379intel_aux_power_domain(struct intel_dp *intel_dp)
1380{
1381 switch (intel_dp->aux_ch) {
1382 case AUX_CH_A:
1383 return POWER_DOMAIN_AUX_A;
1384 case AUX_CH_B:
1385 return POWER_DOMAIN_AUX_B;
1386 case AUX_CH_C:
1387 return POWER_DOMAIN_AUX_C;
1388 case AUX_CH_D:
1389 return POWER_DOMAIN_AUX_D;
1390 case AUX_CH_F:
1391 return POWER_DOMAIN_AUX_F;
1392 default:
1393 MISSING_CASE(intel_dp->aux_ch);
1394 return POWER_DOMAIN_AUX_A;
1395 }
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001396}
1397
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001398static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001399{
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001400 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1401 enum aux_ch aux_ch = intel_dp->aux_ch;
1402
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001403 switch (aux_ch) {
1404 case AUX_CH_B:
1405 case AUX_CH_C:
1406 case AUX_CH_D:
1407 return DP_AUX_CH_CTL(aux_ch);
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001408 default:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001409 MISSING_CASE(aux_ch);
1410 return DP_AUX_CH_CTL(AUX_CH_B);
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001411 }
1412}
1413
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001414static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001415{
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001416 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1417 enum aux_ch aux_ch = intel_dp->aux_ch;
1418
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001419 switch (aux_ch) {
1420 case AUX_CH_B:
1421 case AUX_CH_C:
1422 case AUX_CH_D:
1423 return DP_AUX_CH_DATA(aux_ch, index);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001424 default:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001425 MISSING_CASE(aux_ch);
1426 return DP_AUX_CH_DATA(AUX_CH_B, index);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001427 }
1428}
1429
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001430static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001431{
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001432 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1433 enum aux_ch aux_ch = intel_dp->aux_ch;
1434
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001435 switch (aux_ch) {
1436 case AUX_CH_A:
1437 return DP_AUX_CH_CTL(aux_ch);
1438 case AUX_CH_B:
1439 case AUX_CH_C:
1440 case AUX_CH_D:
1441 return PCH_DP_AUX_CH_CTL(aux_ch);
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001442 default:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001443 MISSING_CASE(aux_ch);
1444 return DP_AUX_CH_CTL(AUX_CH_A);
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001445 }
1446}
1447
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001448static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001449{
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001450 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1451 enum aux_ch aux_ch = intel_dp->aux_ch;
1452
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001453 switch (aux_ch) {
1454 case AUX_CH_A:
1455 return DP_AUX_CH_DATA(aux_ch, index);
1456 case AUX_CH_B:
1457 case AUX_CH_C:
1458 case AUX_CH_D:
1459 return PCH_DP_AUX_CH_DATA(aux_ch, index);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001460 default:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001461 MISSING_CASE(aux_ch);
1462 return DP_AUX_CH_DATA(AUX_CH_A, index);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001463 }
1464}
1465
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001466static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001467{
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001468 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1469 enum aux_ch aux_ch = intel_dp->aux_ch;
1470
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001471 switch (aux_ch) {
1472 case AUX_CH_A:
1473 case AUX_CH_B:
1474 case AUX_CH_C:
1475 case AUX_CH_D:
1476 case AUX_CH_F:
1477 return DP_AUX_CH_CTL(aux_ch);
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001478 default:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001479 MISSING_CASE(aux_ch);
1480 return DP_AUX_CH_CTL(AUX_CH_A);
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001481 }
1482}
1483
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001484static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001485{
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001486 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1487 enum aux_ch aux_ch = intel_dp->aux_ch;
1488
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001489 switch (aux_ch) {
1490 case AUX_CH_A:
1491 case AUX_CH_B:
1492 case AUX_CH_C:
1493 case AUX_CH_D:
1494 case AUX_CH_F:
1495 return DP_AUX_CH_DATA(aux_ch, index);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001496 default:
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001497 MISSING_CASE(aux_ch);
1498 return DP_AUX_CH_DATA(AUX_CH_A, index);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001499 }
1500}
1501
Ville Syrjälä91e939a2018-02-22 20:10:32 +02001502static void
1503intel_dp_aux_fini(struct intel_dp *intel_dp)
1504{
1505 kfree(intel_dp->aux.name);
1506}
1507
1508static void
1509intel_dp_aux_init(struct intel_dp *intel_dp)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001510{
1511 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä91e939a2018-02-22 20:10:32 +02001512 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1513
1514 intel_dp->aux_ch = intel_aux_ch(intel_dp);
1515 intel_dp->aux_power_domain = intel_aux_power_domain(intel_dp);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001516
Ville Syrjälä4904fa62018-02-22 20:10:31 +02001517 if (INTEL_GEN(dev_priv) >= 9) {
1518 intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
1519 intel_dp->aux_ch_data_reg = skl_aux_data_reg;
1520 } else if (HAS_PCH_SPLIT(dev_priv)) {
1521 intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
1522 intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
1523 } else {
1524 intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
1525 intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
1526 }
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001527
Ville Syrjälä91e939a2018-02-22 20:10:32 +02001528 if (INTEL_GEN(dev_priv) >= 9)
1529 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
1530 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
1531 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
1532 else if (HAS_PCH_SPLIT(dev_priv))
1533 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
1534 else
1535 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001536
Ville Syrjälä91e939a2018-02-22 20:10:32 +02001537 if (INTEL_GEN(dev_priv) >= 9)
1538 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
1539 else
1540 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001541
Chris Wilson7a418e32016-06-24 14:00:14 +01001542 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001543
Chris Wilson7a418e32016-06-24 14:00:14 +01001544 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02001545 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c",
1546 port_name(encoder->port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001547 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001548}
1549
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001550bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301551{
Jani Nikulafc603ca2017-10-09 12:29:58 +03001552 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001553
Jani Nikulafc603ca2017-10-09 12:29:58 +03001554 return max_rate >= 540000;
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301555}
1556
Daniel Vetter0e503382014-07-04 11:26:04 -03001557static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001558intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001559 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001560{
Ville Syrjälä2f773472017-11-09 17:27:58 +02001561 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001562 const struct dp_link_dpll *divisor = NULL;
1563 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001564
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001565 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001566 divisor = gen4_dpll;
1567 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001568 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001569 divisor = pch_dpll;
1570 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001571 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001572 divisor = chv_dpll;
1573 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001574 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001575 divisor = vlv_dpll;
1576 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001577 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001578
1579 if (divisor && count) {
1580 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001581 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001582 pipe_config->dpll = divisor[i].dpll;
1583 pipe_config->clock_set = true;
1584 break;
1585 }
1586 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001587 }
1588}
1589
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001590static void snprintf_int_array(char *str, size_t len,
1591 const int *array, int nelem)
1592{
1593 int i;
1594
1595 str[0] = '\0';
1596
1597 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001598 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001599 if (r >= len)
1600 return;
1601 str += r;
1602 len -= r;
1603 }
1604}
1605
1606static void intel_dp_print_rates(struct intel_dp *intel_dp)
1607{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001608 char str[128]; /* FIXME: too big for stack? */
1609
1610 if ((drm_debug & DRM_UT_KMS) == 0)
1611 return;
1612
Jani Nikula55cfc582017-03-28 17:59:04 +03001613 snprintf_int_array(str, sizeof(str),
1614 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001615 DRM_DEBUG_KMS("source rates: %s\n", str);
1616
Jani Nikula68f357c2017-03-28 17:59:05 +03001617 snprintf_int_array(str, sizeof(str),
1618 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001619 DRM_DEBUG_KMS("sink rates: %s\n", str);
1620
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001621 snprintf_int_array(str, sizeof(str),
1622 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001623 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001624}
1625
Ville Syrjälä50fec212015-03-12 17:10:34 +02001626int
1627intel_dp_max_link_rate(struct intel_dp *intel_dp)
1628{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001629 int len;
1630
Jani Nikulae6c0c642017-04-06 16:44:12 +03001631 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001632 if (WARN_ON(len <= 0))
1633 return 162000;
1634
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001635 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001636}
1637
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001638int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1639{
Jani Nikula8001b752017-03-28 17:59:03 +03001640 int i = intel_dp_rate_index(intel_dp->sink_rates,
1641 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001642
1643 if (WARN_ON(i < 0))
1644 i = 0;
1645
1646 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001647}
1648
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001649void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1650 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001651{
Jani Nikula68f357c2017-03-28 17:59:05 +03001652 /* eDP 1.4 rate select method. */
1653 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001654 *link_bw = 0;
1655 *rate_select =
1656 intel_dp_rate_select(intel_dp, port_clock);
1657 } else {
1658 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1659 *rate_select = 0;
1660 }
1661}
1662
Jani Nikulaf580bea2016-09-15 16:28:52 +03001663static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1664 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001665{
1666 int bpp, bpc;
1667
1668 bpp = pipe_config->pipe_bpp;
1669 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1670
1671 if (bpc > 0)
1672 bpp = min(bpp, 3*bpc);
1673
Manasi Navare611032b2017-01-24 08:21:49 -08001674 /* For DP Compliance we override the computed bpp for the pipe */
1675 if (intel_dp->compliance.test_data.bpc != 0) {
1676 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1677 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1678 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1679 pipe_config->pipe_bpp);
1680 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001681 return bpp;
1682}
1683
Jim Bridedc911f52017-08-09 12:48:53 -07001684static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1685 struct drm_display_mode *m2)
1686{
1687 bool bres = false;
1688
1689 if (m1 && m2)
1690 bres = (m1->hdisplay == m2->hdisplay &&
1691 m1->hsync_start == m2->hsync_start &&
1692 m1->hsync_end == m2->hsync_end &&
1693 m1->htotal == m2->htotal &&
1694 m1->vdisplay == m2->vdisplay &&
1695 m1->vsync_start == m2->vsync_start &&
1696 m1->vsync_end == m2->vsync_end &&
1697 m1->vtotal == m2->vtotal);
1698 return bres;
1699}
1700
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001701bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001702intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001703 struct intel_crtc_state *pipe_config,
1704 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001705{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001706 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001707 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001708 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001709 enum port port = encoder->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001710 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001711 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001712 struct intel_digital_connector_state *intel_conn_state =
1713 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001714 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001715 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001716 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001717 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001718 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301719 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001720 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001721 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001722 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001723 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001724 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1725 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301726
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001727 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001728 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301729
1730 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001731 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301732
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001733 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001734
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001735 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001736 pipe_config->has_pch_encoder = true;
1737
Vandana Kannanf769cd22014-08-05 07:51:22 -07001738 pipe_config->has_drrs = false;
Ville Syrjälä20ff39f2017-11-29 18:43:01 +02001739 if (IS_G4X(dev_priv) || port == PORT_A)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001740 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001741 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001742 pipe_config->has_audio = intel_dp->has_audio;
1743 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001744 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001745
Jani Nikula1853a9d2017-08-18 12:30:20 +03001746 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jim Bridedc911f52017-08-09 12:48:53 -07001747 struct drm_display_mode *panel_mode =
1748 intel_connector->panel.alt_fixed_mode;
1749 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1750
1751 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1752 panel_mode = intel_connector->panel.fixed_mode;
1753
1754 drm_mode_debug_printmodeline(panel_mode);
1755
1756 intel_fixed_panel_mode(panel_mode, adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001757
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001758 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001759 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001760 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001761 if (ret)
1762 return ret;
1763 }
1764
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001765 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001766 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001767 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001768 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001769 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001770 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001771 }
1772
Ville Syrjälä050213892017-11-29 20:08:47 +02001773 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1774 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
1775 return false;
1776
Daniel Vettercb1793c2012-06-04 18:39:21 +02001777 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001778 return false;
1779
Manasi Navareda15f7c2017-01-24 08:16:34 -08001780 /* Use values requested by Compliance Test Request */
1781 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001782 int index;
1783
Manasi Navare140ef132017-06-08 13:41:03 -07001784 /* Validate the compliance test data since max values
1785 * might have changed due to link train fallback.
1786 */
1787 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1788 intel_dp->compliance.test_lane_count)) {
1789 index = intel_dp_rate_index(intel_dp->common_rates,
1790 intel_dp->num_common_rates,
1791 intel_dp->compliance.test_link_rate);
1792 if (index >= 0)
1793 min_clock = max_clock = index;
1794 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1795 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08001796 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001797 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301798 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001799 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001800 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001801
Daniel Vetter36008362013-03-27 00:44:59 +01001802 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1803 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001804 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula1853a9d2017-08-18 12:30:20 +03001805 if (intel_dp_is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301806
1807 /* Get bpp from vbt only for panels that dont have bpp in edid */
1808 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001809 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001810 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001811 dev_priv->vbt.edp.bpp);
1812 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001813 }
1814
Jani Nikula344c5bb2014-09-09 11:25:13 +03001815 /*
1816 * Use the maximum clock and number of lanes the eDP panel
1817 * advertizes being capable of. The panels are generally
1818 * designed to support only a single clock and lane
1819 * configuration, and typically these values correspond to the
1820 * native resolution of the panel.
1821 */
1822 min_lane_count = max_lane_count;
1823 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001824 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001825
Daniel Vetter36008362013-03-27 00:44:59 +01001826 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001827 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1828 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001829
Dave Airliec6930992014-07-14 11:04:39 +10001830 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301831 for (lane_count = min_lane_count;
1832 lane_count <= max_lane_count;
1833 lane_count <<= 1) {
1834
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001835 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001836 link_avail = intel_dp_max_data_rate(link_clock,
1837 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001838
Daniel Vetter36008362013-03-27 00:44:59 +01001839 if (mode_rate <= link_avail) {
1840 goto found;
1841 }
1842 }
1843 }
1844 }
1845
1846 return false;
1847
1848found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001849 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001850 /*
1851 * See:
1852 * CEA-861-E - 5.1 Default Encoding Parameters
1853 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1854 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001855 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001856 bpp != 18 &&
1857 drm_default_rgb_quant_range(adjusted_mode) ==
1858 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001859 } else {
1860 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001861 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001862 }
1863
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001864 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301865
Daniel Vetter657445f2013-05-04 10:09:18 +02001866 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001867 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001868
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001869 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1870 &link_bw, &rate_select);
1871
1872 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1873 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001874 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001875 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1876 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001877
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001878 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001879 adjusted_mode->crtc_clock,
1880 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001881 &pipe_config->dp_m_n,
1882 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001883
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301884 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301885 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001886 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301887 intel_link_compute_m_n(bpp, lane_count,
1888 intel_connector->panel.downclock_mode->clock,
1889 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001890 &pipe_config->dp_m2_n2,
1891 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301892 }
1893
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001894 /*
1895 * DPLL0 VCO may need to be adjusted to get the correct
1896 * clock for eDP. This will affect cdclk as well.
1897 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03001898 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001899 int vco;
1900
1901 switch (pipe_config->port_clock / 2) {
1902 case 108000:
1903 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001904 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001905 break;
1906 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001907 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001908 break;
1909 }
1910
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001911 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001912 }
1913
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001914 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001915 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001916
Ville Syrjälä4d90f2d2017-10-12 16:02:01 +03001917 intel_psr_compute_config(intel_dp, pipe_config);
1918
Daniel Vetter36008362013-03-27 00:44:59 +01001919 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001920}
1921
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001922void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001923 int link_rate, uint8_t lane_count,
1924 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001925{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001926 intel_dp->link_rate = link_rate;
1927 intel_dp->lane_count = lane_count;
1928 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001929}
1930
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001931static void intel_dp_prepare(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03001932 const struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001933{
Ville Syrjälä2f773472017-11-09 17:27:58 +02001934 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001935 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001936 enum port port = encoder->port;
Ville Syrjäläadc10302017-10-31 22:51:14 +02001937 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001938 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001939
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001940 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1941 pipe_config->lane_count,
1942 intel_crtc_has_type(pipe_config,
1943 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001944
Keith Packard417e8222011-11-01 19:54:11 -07001945 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001946 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001947 *
1948 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001949 * SNB CPU
1950 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001951 * CPT PCH
1952 *
1953 * IBX PCH and CPU are the same for almost everything,
1954 * except that the CPU DP PLL is configured in this
1955 * register
1956 *
1957 * CPT PCH is quite different, having many bits moved
1958 * to the TRANS_DP_CTL register instead. That
1959 * configuration happens (oddly) in ironlake_pch_enable
1960 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001961
Keith Packard417e8222011-11-01 19:54:11 -07001962 /* Preserve the BIOS-computed detected bit. This is
1963 * supposed to be read-only.
1964 */
1965 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001966
Keith Packard417e8222011-11-01 19:54:11 -07001967 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001968 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001969 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001970
Keith Packard417e8222011-11-01 19:54:11 -07001971 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001972
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001973 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001974 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1975 intel_dp->DP |= DP_SYNC_HS_HIGH;
1976 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1977 intel_dp->DP |= DP_SYNC_VS_HIGH;
1978 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1979
Jani Nikula6aba5b62013-10-04 15:08:10 +03001980 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001981 intel_dp->DP |= DP_ENHANCED_FRAMING;
1982
Daniel Vetter7c62a162013-06-01 17:16:20 +02001983 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001984 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001985 u32 trans_dp;
1986
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001987 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001988
1989 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1990 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1991 trans_dp |= TRANS_DP_ENH_FRAMING;
1992 else
1993 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1994 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001995 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001996 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001997 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001998
1999 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2000 intel_dp->DP |= DP_SYNC_HS_HIGH;
2001 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2002 intel_dp->DP |= DP_SYNC_VS_HIGH;
2003 intel_dp->DP |= DP_LINK_TRAIN_OFF;
2004
Jani Nikula6aba5b62013-10-04 15:08:10 +03002005 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07002006 intel_dp->DP |= DP_ENHANCED_FRAMING;
2007
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002008 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03002009 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002010 else if (crtc->pipe == PIPE_B)
2011 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002012 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002013}
2014
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02002015#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
2016#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07002017
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02002018#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
2019#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07002020
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02002021#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
2022#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07002023
Ville Syrjälä46bd8382017-10-31 22:51:22 +02002024static void intel_pps_verify_state(struct intel_dp *intel_dp);
Imre Deakde9c1b62016-06-16 20:01:46 +03002025
Daniel Vetter4be73782014-01-17 14:39:48 +01002026static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07002027 u32 mask,
2028 u32 value)
2029{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002030 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002031 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07002032
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002033 lockdep_assert_held(&dev_priv->pps_mutex);
2034
Ville Syrjälä46bd8382017-10-31 22:51:22 +02002035 intel_pps_verify_state(intel_dp);
Imre Deakde9c1b62016-06-16 20:01:46 +03002036
Jani Nikulabf13e812013-09-06 07:40:05 +03002037 pp_stat_reg = _pp_stat_reg(intel_dp);
2038 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002039
2040 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07002041 mask, value,
2042 I915_READ(pp_stat_reg),
2043 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07002044
Chris Wilson9036ff02016-06-30 15:33:09 +01002045 if (intel_wait_for_register(dev_priv,
2046 pp_stat_reg, mask, value,
2047 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07002048 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07002049 I915_READ(pp_stat_reg),
2050 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00002051
2052 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07002053}
2054
Daniel Vetter4be73782014-01-17 14:39:48 +01002055static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07002056{
2057 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01002058 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002059}
2060
Daniel Vetter4be73782014-01-17 14:39:48 +01002061static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07002062{
Keith Packardbd943152011-09-18 23:09:52 -07002063 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01002064 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07002065}
Keith Packardbd943152011-09-18 23:09:52 -07002066
Daniel Vetter4be73782014-01-17 14:39:48 +01002067static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07002068{
Abhay Kumard28d4732016-01-22 17:39:04 -08002069 ktime_t panel_power_on_time;
2070 s64 panel_power_off_duration;
2071
Keith Packard99ea7122011-11-01 19:57:50 -07002072 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02002073
Abhay Kumard28d4732016-01-22 17:39:04 -08002074 /* take the difference of currrent time and panel power off time
2075 * and then make panel wait for t11_t12 if needed. */
2076 panel_power_on_time = ktime_get_boottime();
2077 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2078
Paulo Zanonidce56b32013-12-19 14:29:40 -02002079 /* When we disable the VDD override bit last we have to do the manual
2080 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08002081 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2082 wait_remaining_ms_from_jiffies(jiffies,
2083 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002084
Daniel Vetter4be73782014-01-17 14:39:48 +01002085 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002086}
Keith Packardbd943152011-09-18 23:09:52 -07002087
Daniel Vetter4be73782014-01-17 14:39:48 +01002088static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002089{
2090 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2091 intel_dp->backlight_on_delay);
2092}
2093
Daniel Vetter4be73782014-01-17 14:39:48 +01002094static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002095{
2096 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2097 intel_dp->backlight_off_delay);
2098}
Keith Packard99ea7122011-11-01 19:57:50 -07002099
Keith Packard832dd3c2011-11-01 19:34:06 -07002100/* Read the current pp_control value, unlocking the register if it
2101 * is locked
2102 */
2103
Jesse Barnes453c5422013-03-28 09:55:41 -07002104static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002105{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002106 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Jesse Barnes453c5422013-03-28 09:55:41 -07002107 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002108
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002109 lockdep_assert_held(&dev_priv->pps_mutex);
2110
Jani Nikulabf13e812013-09-06 07:40:05 +03002111 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002112 if (WARN_ON(!HAS_DDI(dev_priv) &&
2113 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302114 control &= ~PANEL_UNLOCK_MASK;
2115 control |= PANEL_UNLOCK_REGS;
2116 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002117 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002118}
2119
Ville Syrjälä951468f2014-09-04 14:55:31 +03002120/*
2121 * Must be paired with edp_panel_vdd_off().
2122 * Must hold pps_mutex around the whole on/off sequence.
2123 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2124 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002125static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002126{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002127 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak4e6e1a52014-03-27 17:45:11 +02002128 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002129 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002130 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002131 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002132
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002133 lockdep_assert_held(&dev_priv->pps_mutex);
2134
Jani Nikula1853a9d2017-08-18 12:30:20 +03002135 if (!intel_dp_is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002136 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002137
Egbert Eich2c623c12014-11-25 12:54:57 +01002138 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002139 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002140
Daniel Vetter4be73782014-01-17 14:39:48 +01002141 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002142 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002143
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002144 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002145
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002146 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002147 port_name(intel_dig_port->base.port));
Keith Packardbd943152011-09-18 23:09:52 -07002148
Daniel Vetter4be73782014-01-17 14:39:48 +01002149 if (!edp_have_panel_power(intel_dp))
2150 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002151
Jesse Barnes453c5422013-03-28 09:55:41 -07002152 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002153 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002154
Jani Nikulabf13e812013-09-06 07:40:05 +03002155 pp_stat_reg = _pp_stat_reg(intel_dp);
2156 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002157
2158 I915_WRITE(pp_ctrl_reg, pp);
2159 POSTING_READ(pp_ctrl_reg);
2160 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2161 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002162 /*
2163 * If the panel wasn't on, delay before accessing aux channel
2164 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002165 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002166 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002167 port_name(intel_dig_port->base.port));
Keith Packardf01eca22011-09-28 16:48:10 -07002168 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002169 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002170
2171 return need_to_disable;
2172}
2173
Ville Syrjälä951468f2014-09-04 14:55:31 +03002174/*
2175 * Must be paired with intel_edp_panel_vdd_off() or
2176 * intel_edp_panel_off().
2177 * Nested calls to these functions are not allowed since
2178 * we drop the lock. Caller must use some higher level
2179 * locking to prevent nested calls from other threads.
2180 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002181void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002182{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002183 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002184
Jani Nikula1853a9d2017-08-18 12:30:20 +03002185 if (!intel_dp_is_edp(intel_dp))
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002186 return;
2187
Ville Syrjälä773538e82014-09-04 14:54:56 +03002188 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002189 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002190 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002191
Rob Clarke2c719b2014-12-15 13:56:32 -05002192 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002193 port_name(dp_to_dig_port(intel_dp)->base.port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002194}
2195
Daniel Vetter4be73782014-01-17 14:39:48 +01002196static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002197{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002198 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002199 struct intel_digital_port *intel_dig_port =
2200 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002201 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002202 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002203
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002204 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002205
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002206 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002207
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002208 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002209 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002210
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002211 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002212 port_name(intel_dig_port->base.port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002213
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002214 pp = ironlake_get_pp_control(intel_dp);
2215 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002216
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002217 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2218 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002219
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002220 I915_WRITE(pp_ctrl_reg, pp);
2221 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002222
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002223 /* Make sure sequencer is idle before allowing subsequent activity */
2224 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2225 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002226
Imre Deak5a162e22016-08-10 14:07:30 +03002227 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002228 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002229
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002230 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002231}
2232
Daniel Vetter4be73782014-01-17 14:39:48 +01002233static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002234{
2235 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2236 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002237
Ville Syrjälä773538e82014-09-04 14:54:56 +03002238 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002239 if (!intel_dp->want_panel_vdd)
2240 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002241 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002242}
2243
Imre Deakaba86892014-07-30 15:57:31 +03002244static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2245{
2246 unsigned long delay;
2247
2248 /*
2249 * Queue the timer to fire a long time from now (relative to the power
2250 * down delay) to keep the panel power up across a sequence of
2251 * operations.
2252 */
2253 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2254 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2255}
2256
Ville Syrjälä951468f2014-09-04 14:55:31 +03002257/*
2258 * Must be paired with edp_panel_vdd_on().
2259 * Must hold pps_mutex around the whole on/off sequence.
2260 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2261 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002262static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002263{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002264 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002265
2266 lockdep_assert_held(&dev_priv->pps_mutex);
2267
Jani Nikula1853a9d2017-08-18 12:30:20 +03002268 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002269 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002270
Rob Clarke2c719b2014-12-15 13:56:32 -05002271 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002272 port_name(dp_to_dig_port(intel_dp)->base.port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002273
Keith Packardbd943152011-09-18 23:09:52 -07002274 intel_dp->want_panel_vdd = false;
2275
Imre Deakaba86892014-07-30 15:57:31 +03002276 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002277 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002278 else
2279 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002280}
2281
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002282static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002283{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002284 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Keith Packard99ea7122011-11-01 19:57:50 -07002285 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002286 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002287
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002288 lockdep_assert_held(&dev_priv->pps_mutex);
2289
Jani Nikula1853a9d2017-08-18 12:30:20 +03002290 if (!intel_dp_is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002291 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002292
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002293 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002294 port_name(dp_to_dig_port(intel_dp)->base.port));
Keith Packard99ea7122011-11-01 19:57:50 -07002295
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002296 if (WARN(edp_have_panel_power(intel_dp),
2297 "eDP port %c panel power already on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002298 port_name(dp_to_dig_port(intel_dp)->base.port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002299 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002300
Daniel Vetter4be73782014-01-17 14:39:48 +01002301 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002302
Jani Nikulabf13e812013-09-06 07:40:05 +03002303 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002304 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002305 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002306 /* ILK workaround: disable reset around power sequence */
2307 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002308 I915_WRITE(pp_ctrl_reg, pp);
2309 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002310 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002311
Imre Deak5a162e22016-08-10 14:07:30 +03002312 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002313 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002314 pp |= PANEL_POWER_RESET;
2315
Jesse Barnes453c5422013-03-28 09:55:41 -07002316 I915_WRITE(pp_ctrl_reg, pp);
2317 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002318
Daniel Vetter4be73782014-01-17 14:39:48 +01002319 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002320 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002321
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002322 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002323 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002324 I915_WRITE(pp_ctrl_reg, pp);
2325 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002326 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002327}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002328
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002329void intel_edp_panel_on(struct intel_dp *intel_dp)
2330{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002331 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002332 return;
2333
2334 pps_lock(intel_dp);
2335 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002336 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002337}
2338
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002339
2340static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002341{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002342 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Keith Packard99ea7122011-11-01 19:57:50 -07002343 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002344 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002345
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002346 lockdep_assert_held(&dev_priv->pps_mutex);
2347
Jani Nikula1853a9d2017-08-18 12:30:20 +03002348 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002349 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002350
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002351 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002352 port_name(dp_to_dig_port(intel_dp)->base.port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002353
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002354 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002355 port_name(dp_to_dig_port(intel_dp)->base.port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002356
Jesse Barnes453c5422013-03-28 09:55:41 -07002357 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002358 /* We need to switch off panel power _and_ force vdd, for otherwise some
2359 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002360 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002361 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002362
Jani Nikulabf13e812013-09-06 07:40:05 +03002363 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002364
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002365 intel_dp->want_panel_vdd = false;
2366
Jesse Barnes453c5422013-03-28 09:55:41 -07002367 I915_WRITE(pp_ctrl_reg, pp);
2368 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002369
Daniel Vetter4be73782014-01-17 14:39:48 +01002370 wait_panel_off(intel_dp);
Manasi Navared7ba25b2017-10-04 09:48:26 -07002371 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002372
2373 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002374 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002375}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002376
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002377void intel_edp_panel_off(struct intel_dp *intel_dp)
2378{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002379 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002380 return;
2381
2382 pps_lock(intel_dp);
2383 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002384 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002385}
2386
Jani Nikula1250d102014-08-12 17:11:39 +03002387/* Enable backlight in the panel power control. */
2388static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002389{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002390 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002391 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002392 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002393
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002394 /*
2395 * If we enable the backlight right away following a panel power
2396 * on, we may see slight flicker as the panel syncs with the eDP
2397 * link. So delay a bit to make sure the image is solid before
2398 * allowing it to appear.
2399 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002400 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002401
Ville Syrjälä773538e82014-09-04 14:54:56 +03002402 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002403
Jesse Barnes453c5422013-03-28 09:55:41 -07002404 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002405 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002406
Jani Nikulabf13e812013-09-06 07:40:05 +03002407 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002408
2409 I915_WRITE(pp_ctrl_reg, pp);
2410 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002411
Ville Syrjälä773538e82014-09-04 14:54:56 +03002412 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002413}
2414
Jani Nikula1250d102014-08-12 17:11:39 +03002415/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002416void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2417 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002418{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002419 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2420
Jani Nikula1853a9d2017-08-18 12:30:20 +03002421 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002422 return;
2423
2424 DRM_DEBUG_KMS("\n");
2425
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002426 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002427 _intel_edp_backlight_on(intel_dp);
2428}
2429
2430/* Disable backlight in the panel power control. */
2431static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002432{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002433 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002434 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002435 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002436
Jani Nikula1853a9d2017-08-18 12:30:20 +03002437 if (!intel_dp_is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07002438 return;
2439
Ville Syrjälä773538e82014-09-04 14:54:56 +03002440 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002441
Jesse Barnes453c5422013-03-28 09:55:41 -07002442 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002443 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002444
Jani Nikulabf13e812013-09-06 07:40:05 +03002445 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002446
2447 I915_WRITE(pp_ctrl_reg, pp);
2448 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002449
Ville Syrjälä773538e82014-09-04 14:54:56 +03002450 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002451
Paulo Zanonidce56b32013-12-19 14:29:40 -02002452 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002453 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002454}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002455
Jani Nikula1250d102014-08-12 17:11:39 +03002456/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002457void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002458{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002459 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2460
Jani Nikula1853a9d2017-08-18 12:30:20 +03002461 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002462 return;
2463
2464 DRM_DEBUG_KMS("\n");
2465
2466 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002467 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002468}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002469
Jani Nikula73580fb72014-08-12 17:11:41 +03002470/*
2471 * Hook for controlling the panel power control backlight through the bl_power
2472 * sysfs attribute. Take care to handle multiple calls.
2473 */
2474static void intel_edp_backlight_power(struct intel_connector *connector,
2475 bool enable)
2476{
2477 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002478 bool is_enabled;
2479
Ville Syrjälä773538e82014-09-04 14:54:56 +03002480 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002481 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002482 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002483
2484 if (is_enabled == enable)
2485 return;
2486
Jani Nikula23ba9372014-08-27 14:08:43 +03002487 DRM_DEBUG_KMS("panel power control backlight %s\n",
2488 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002489
2490 if (enable)
2491 _intel_edp_backlight_on(intel_dp);
2492 else
2493 _intel_edp_backlight_off(intel_dp);
2494}
2495
Ville Syrjälä64e10772015-10-29 21:26:01 +02002496static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2497{
2498 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2499 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2500 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2501
2502 I915_STATE_WARN(cur_state != state,
2503 "DP port %c state assertion failure (expected %s, current %s)\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002504 port_name(dig_port->base.port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002505 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002506}
2507#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2508
2509static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2510{
2511 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2512
2513 I915_STATE_WARN(cur_state != state,
2514 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002515 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002516}
2517#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2518#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2519
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002520static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002521 const struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002522{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002523 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002524 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002525
Ville Syrjälä64e10772015-10-29 21:26:01 +02002526 assert_pipe_disabled(dev_priv, crtc->pipe);
2527 assert_dp_port_disabled(intel_dp);
2528 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002529
Ville Syrjäläabfce942015-10-29 21:26:03 +02002530 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002531 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002532
2533 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2534
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002535 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002536 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2537 else
2538 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2539
2540 I915_WRITE(DP_A, intel_dp->DP);
2541 POSTING_READ(DP_A);
2542 udelay(500);
2543
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002544 /*
2545 * [DevILK] Work around required when enabling DP PLL
2546 * while a pipe is enabled going to FDI:
2547 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2548 * 2. Program DP PLL enable
2549 */
2550 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002551 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002552
Daniel Vetter07679352012-09-06 22:15:42 +02002553 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002554
Daniel Vetter07679352012-09-06 22:15:42 +02002555 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002556 POSTING_READ(DP_A);
2557 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002558}
2559
Ville Syrjäläadc10302017-10-31 22:51:14 +02002560static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2561 const struct intel_crtc_state *old_crtc_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002562{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002563 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002564 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002565
Ville Syrjälä64e10772015-10-29 21:26:01 +02002566 assert_pipe_disabled(dev_priv, crtc->pipe);
2567 assert_dp_port_disabled(intel_dp);
2568 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002569
Ville Syrjäläabfce942015-10-29 21:26:03 +02002570 DRM_DEBUG_KMS("disabling eDP PLL\n");
2571
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002572 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002573
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002574 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002575 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002576 udelay(200);
2577}
2578
Ville Syrjälä857c4162017-10-27 12:45:23 +03002579static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2580{
2581 /*
2582 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2583 * be capable of signalling downstream hpd with a long pulse.
2584 * Whether or not that means D3 is safe to use is not clear,
2585 * but let's assume so until proven otherwise.
2586 *
2587 * FIXME should really check all downstream ports...
2588 */
2589 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2590 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2591 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2592}
2593
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002594/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002595void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002596{
2597 int ret, i;
2598
2599 /* Should have a valid DPCD by this point */
2600 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2601 return;
2602
2603 if (mode != DRM_MODE_DPMS_ON) {
Ville Syrjälä857c4162017-10-27 12:45:23 +03002604 if (downstream_hpd_needs_d0(intel_dp))
2605 return;
2606
Jani Nikula9d1a1032014-03-14 16:51:15 +02002607 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2608 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002609 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002610 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2611
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002612 /*
2613 * When turning on, we need to retry for 1ms to give the sink
2614 * time to wake up.
2615 */
2616 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002617 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2618 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002619 if (ret == 1)
2620 break;
2621 msleep(1);
2622 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002623
2624 if (ret == 1 && lspcon->active)
2625 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002626 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002627
2628 if (ret != 1)
2629 DRM_DEBUG_KMS("failed to %s sink power state\n",
2630 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002631}
2632
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002633static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2634 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002635{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002636 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002637 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002638 enum port port = encoder->port;
Imre Deak6d129be2014-03-05 16:20:54 +02002639 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002640 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002641
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002642 if (!intel_display_power_get_if_enabled(dev_priv,
2643 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002644 return false;
2645
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002646 ret = false;
2647
Imre Deak6d129be2014-03-05 16:20:54 +02002648 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002649
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002650 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002651 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002652
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002653 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002654 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002655 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002656 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002657
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002658 for_each_pipe(dev_priv, p) {
2659 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2660 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2661 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002662 ret = true;
2663
2664 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002665 }
2666 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002667
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002668 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002669 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002670 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002671 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2672 } else {
2673 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002674 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002675
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002676 ret = true;
2677
2678out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002679 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002680
2681 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002682}
2683
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002684static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002685 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002686{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002687 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002688 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002689 u32 tmp, flags = 0;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002690 enum port port = encoder->port;
Ville Syrjäläadc10302017-10-31 22:51:14 +02002691 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002692
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002693 if (encoder->type == INTEL_OUTPUT_EDP)
2694 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2695 else
2696 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002697
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002698 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002699
2700 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002701
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002702 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002703 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2704
2705 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002706 flags |= DRM_MODE_FLAG_PHSYNC;
2707 else
2708 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002709
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002710 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002711 flags |= DRM_MODE_FLAG_PVSYNC;
2712 else
2713 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002714 } else {
2715 if (tmp & DP_SYNC_HS_HIGH)
2716 flags |= DRM_MODE_FLAG_PHSYNC;
2717 else
2718 flags |= DRM_MODE_FLAG_NHSYNC;
2719
2720 if (tmp & DP_SYNC_VS_HIGH)
2721 flags |= DRM_MODE_FLAG_PVSYNC;
2722 else
2723 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002724 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002725
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002726 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002727
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002728 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002729 pipe_config->limited_color_range = true;
2730
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002731 pipe_config->lane_count =
2732 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2733
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002734 intel_dp_get_m_n(crtc, pipe_config);
2735
Ville Syrjälä18442d02013-09-13 16:00:08 +03002736 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002737 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002738 pipe_config->port_clock = 162000;
2739 else
2740 pipe_config->port_clock = 270000;
2741 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002742
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002743 pipe_config->base.adjusted_mode.crtc_clock =
2744 intel_dotclock_calculate(pipe_config->port_clock,
2745 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002746
Jani Nikula1853a9d2017-08-18 12:30:20 +03002747 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02002748 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002749 /*
2750 * This is a big fat ugly hack.
2751 *
2752 * Some machines in UEFI boot mode provide us a VBT that has 18
2753 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2754 * unknown we fail to light up. Yet the same BIOS boots up with
2755 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2756 * max, not what it tells us to use.
2757 *
2758 * Note: This will still be broken if the eDP panel is not lit
2759 * up by the BIOS, and thus we can't get the mode at module
2760 * load.
2761 */
2762 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002763 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2764 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002765 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002766}
2767
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002768static void intel_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002769 const struct intel_crtc_state *old_crtc_state,
2770 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002771{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002772 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002773
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002774 if (old_crtc_state->has_audio)
Ville Syrjälä8ec47de2017-10-30 20:46:53 +02002775 intel_audio_codec_disable(encoder,
2776 old_crtc_state, old_conn_state);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002777
2778 /* Make sure the panel is off before trying to change the mode. But also
2779 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002780 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002781 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002782 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002783 intel_edp_panel_off(intel_dp);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002784}
2785
2786static void g4x_disable_dp(struct intel_encoder *encoder,
2787 const struct intel_crtc_state *old_crtc_state,
2788 const struct drm_connector_state *old_conn_state)
2789{
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002790 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Daniel Vetter37398502012-09-06 22:15:44 +02002791
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002792 /* disable the port before the pipe on g4x */
Ville Syrjäläadc10302017-10-31 22:51:14 +02002793 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002794}
2795
2796static void ilk_disable_dp(struct intel_encoder *encoder,
2797 const struct intel_crtc_state *old_crtc_state,
2798 const struct drm_connector_state *old_conn_state)
2799{
2800 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2801}
2802
2803static void vlv_disable_dp(struct intel_encoder *encoder,
2804 const struct intel_crtc_state *old_crtc_state,
2805 const struct drm_connector_state *old_conn_state)
2806{
2807 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2808
2809 intel_psr_disable(intel_dp, old_crtc_state);
2810
2811 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Jesse Barnesd240f202010-08-13 15:43:26 -07002812}
2813
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002814static void ilk_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002815 const struct intel_crtc_state *old_crtc_state,
2816 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002817{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002818 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläadc10302017-10-31 22:51:14 +02002819 enum port port = encoder->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002820
Ville Syrjäläadc10302017-10-31 22:51:14 +02002821 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002822
2823 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002824 if (port == PORT_A)
Ville Syrjäläadc10302017-10-31 22:51:14 +02002825 ironlake_edp_pll_off(intel_dp, old_crtc_state);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002826}
2827
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002828static void vlv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002829 const struct intel_crtc_state *old_crtc_state,
2830 const struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002831{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002832 intel_dp_link_down(encoder, old_crtc_state);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002833}
2834
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002835static void chv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002836 const struct intel_crtc_state *old_crtc_state,
2837 const struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002838{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002839 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002840
Ville Syrjäläadc10302017-10-31 22:51:14 +02002841 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002842
Ville Syrjäläa5805162015-05-26 20:42:30 +03002843 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002844
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002845 /* Assert data lane reset */
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02002846 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002847
Ville Syrjäläa5805162015-05-26 20:42:30 +03002848 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002849}
2850
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002851static void
2852_intel_dp_set_link_train(struct intel_dp *intel_dp,
2853 uint32_t *DP,
2854 uint8_t dp_train_pat)
2855{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002856 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002857 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002858 enum port port = intel_dig_port->base.port;
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002859
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002860 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2861 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2862 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2863
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002864 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002865 uint32_t temp = I915_READ(DP_TP_CTL(port));
2866
2867 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2868 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2869 else
2870 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2871
2872 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2873 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2874 case DP_TRAINING_PATTERN_DISABLE:
2875 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2876
2877 break;
2878 case DP_TRAINING_PATTERN_1:
2879 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2880 break;
2881 case DP_TRAINING_PATTERN_2:
2882 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2883 break;
2884 case DP_TRAINING_PATTERN_3:
2885 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2886 break;
2887 }
2888 I915_WRITE(DP_TP_CTL(port), temp);
2889
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002890 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002891 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002892 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2893
2894 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2895 case DP_TRAINING_PATTERN_DISABLE:
2896 *DP |= DP_LINK_TRAIN_OFF_CPT;
2897 break;
2898 case DP_TRAINING_PATTERN_1:
2899 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2900 break;
2901 case DP_TRAINING_PATTERN_2:
2902 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2903 break;
2904 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002905 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002906 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2907 break;
2908 }
2909
2910 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002911 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002912 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2913 else
2914 *DP &= ~DP_LINK_TRAIN_MASK;
2915
2916 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2917 case DP_TRAINING_PATTERN_DISABLE:
2918 *DP |= DP_LINK_TRAIN_OFF;
2919 break;
2920 case DP_TRAINING_PATTERN_1:
2921 *DP |= DP_LINK_TRAIN_PAT_1;
2922 break;
2923 case DP_TRAINING_PATTERN_2:
2924 *DP |= DP_LINK_TRAIN_PAT_2;
2925 break;
2926 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002927 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002928 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2929 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002930 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002931 *DP |= DP_LINK_TRAIN_PAT_2;
2932 }
2933 break;
2934 }
2935 }
2936}
2937
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002938static void intel_dp_enable_port(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002939 const struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002940{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002941 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002942
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002943 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002944
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002945 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002946
2947 /*
2948 * Magic for VLV/CHV. We _must_ first set up the register
2949 * without actually enabling the port, and then do another
2950 * write to enable the port. Otherwise link training will
2951 * fail when the power sequencer is freshly used for this port.
2952 */
2953 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002954 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002955 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002956
2957 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2958 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002959}
2960
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002961static void intel_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002962 const struct intel_crtc_state *pipe_config,
2963 const struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002964{
Ville Syrjälä2f773472017-11-09 17:27:58 +02002965 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vettere8cb4552012-07-01 13:05:48 +02002966 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläadc10302017-10-31 22:51:14 +02002967 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002968 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002969 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002970
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002971 if (WARN_ON(dp_reg & DP_PORT_EN))
2972 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002973
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002974 pps_lock(intel_dp);
2975
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002976 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläadc10302017-10-31 22:51:14 +02002977 vlv_init_panel_power_sequencer(encoder, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002978
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002979 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002980
2981 edp_panel_vdd_on(intel_dp);
2982 edp_panel_on(intel_dp);
2983 edp_panel_vdd_off(intel_dp, true);
2984
2985 pps_unlock(intel_dp);
2986
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002987 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002988 unsigned int lane_mask = 0x0;
2989
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002990 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002991 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002992
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002993 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2994 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002995 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002996
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002997 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2998 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002999 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02003000
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003001 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02003002 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02003003 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003004 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02003005 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003006}
Jesse Barnes89b667f2013-04-18 14:51:36 -07003007
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003008static void g4x_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003009 const struct intel_crtc_state *pipe_config,
3010 const struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03003011{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003012 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02003013 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003014}
Jesse Barnes89b667f2013-04-18 14:51:36 -07003015
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003016static void vlv_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003017 const struct intel_crtc_state *pipe_config,
3018 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003019{
Jani Nikula828f5c62013-09-05 16:44:45 +03003020 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3021
Maarten Lankhorstb037d582017-06-12 12:21:13 +02003022 intel_edp_backlight_on(pipe_config, conn_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03003023 intel_psr_enable(intel_dp, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003024}
3025
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003026static void g4x_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003027 const struct intel_crtc_state *pipe_config,
3028 const struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003029{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02003030 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003031 enum port port = encoder->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003032
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003033 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003034
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02003035 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02003036 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003037 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003038}
3039
Ville Syrjälä83b84592014-10-16 21:29:51 +03003040static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
3041{
3042 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01003043 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03003044 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03003045 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03003046
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003047 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
3048
Ville Syrjäläd1586942017-02-08 19:52:54 +02003049 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
3050 return;
3051
Ville Syrjälä83b84592014-10-16 21:29:51 +03003052 edp_panel_vdd_off_sync(intel_dp);
3053
3054 /*
3055 * VLV seems to get confused when multiple power seqeuencers
3056 * have the same port selected (even if only one has power/vdd
3057 * enabled). The failure manifests as vlv_wait_port_ready() failing
3058 * CHV on the other hand doesn't seem to mind having the same port
3059 * selected in multiple power seqeuencers, but let's clear the
3060 * port select always when logically disconnecting a power sequencer
3061 * from a port.
3062 */
3063 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003064 pipe_name(pipe), port_name(intel_dig_port->base.port));
Ville Syrjälä83b84592014-10-16 21:29:51 +03003065 I915_WRITE(pp_on_reg, 0);
3066 POSTING_READ(pp_on_reg);
3067
3068 intel_dp->pps_pipe = INVALID_PIPE;
3069}
3070
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003071static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003072 enum pipe pipe)
3073{
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003074 struct intel_encoder *encoder;
3075
3076 lockdep_assert_held(&dev_priv->pps_mutex);
3077
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003078 for_each_intel_encoder(&dev_priv->drm, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003079 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03003080 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003081
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003082 if (encoder->type != INTEL_OUTPUT_DP &&
3083 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003084 continue;
3085
3086 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003087 port = dp_to_dig_port(intel_dp)->base.port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003088
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003089 WARN(intel_dp->active_pipe == pipe,
3090 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3091 pipe_name(pipe), port_name(port));
3092
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003093 if (intel_dp->pps_pipe != pipe)
3094 continue;
3095
3096 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03003097 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003098
3099 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003100 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003101 }
3102}
3103
Ville Syrjäläadc10302017-10-31 22:51:14 +02003104static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3105 const struct intel_crtc_state *crtc_state)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003106{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003107 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjäläadc10302017-10-31 22:51:14 +02003108 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläadc10302017-10-31 22:51:14 +02003109 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003110
3111 lockdep_assert_held(&dev_priv->pps_mutex);
3112
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003113 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003114
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003115 if (intel_dp->pps_pipe != INVALID_PIPE &&
3116 intel_dp->pps_pipe != crtc->pipe) {
3117 /*
3118 * If another power sequencer was being used on this
3119 * port previously make sure to turn off vdd there while
3120 * we still have control of it.
3121 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003122 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003123 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003124
3125 /*
3126 * We may be stealing the power
3127 * sequencer from another port.
3128 */
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003129 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003130
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003131 intel_dp->active_pipe = crtc->pipe;
3132
Jani Nikula1853a9d2017-08-18 12:30:20 +03003133 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003134 return;
3135
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003136 /* now it's all ours */
3137 intel_dp->pps_pipe = crtc->pipe;
3138
3139 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
Ville Syrjäläadc10302017-10-31 22:51:14 +02003140 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003141
3142 /* init power sequencer on this pipe and port */
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003143 intel_dp_init_panel_power_sequencer(intel_dp);
3144 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003145}
3146
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003147static void vlv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003148 const struct intel_crtc_state *pipe_config,
3149 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003150{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003151 vlv_phy_pre_encoder_enable(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003152
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003153 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003154}
3155
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003156static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003157 const struct intel_crtc_state *pipe_config,
3158 const struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003159{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003160 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003161
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003162 vlv_phy_pre_pll_enable(encoder, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003163}
3164
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003165static void chv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003166 const struct intel_crtc_state *pipe_config,
3167 const struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003168{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003169 chv_phy_pre_encoder_enable(encoder, pipe_config);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003170
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003171 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003172
3173 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003174 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003175}
3176
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003177static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003178 const struct intel_crtc_state *pipe_config,
3179 const struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003180{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003181 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003182
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003183 chv_phy_pre_pll_enable(encoder, pipe_config);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003184}
3185
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003186static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003187 const struct intel_crtc_state *old_crtc_state,
3188 const struct drm_connector_state *old_conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003189{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003190 chv_phy_post_pll_disable(encoder, old_crtc_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003191}
3192
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003193/*
3194 * Fetch AUX CH registers 0x202 - 0x207 which contain
3195 * link status information
3196 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003197bool
Keith Packard93f62da2011-11-01 19:45:03 -07003198intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003199{
Lyude9f085eb2016-04-13 10:58:33 -04003200 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3201 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003202}
3203
Paulo Zanoni11002442014-06-13 18:45:41 -03003204/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003205uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003206intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003207{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003208 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003209 enum port port = dp_to_dig_port(intel_dp)->base.port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003210
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03003211 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003212 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3213 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003214 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003216 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303217 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003218 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003220 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303221 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003222}
3223
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003224uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003225intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3226{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003227 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003228 enum port port = dp_to_dig_port(intel_dp)->base.port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003229
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003230 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003231 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3232 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3233 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3234 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3235 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3236 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3237 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303238 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3239 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003240 default:
3241 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3242 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003243 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003244 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303245 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3246 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3247 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3248 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3249 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3250 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3251 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003252 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003254 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003255 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003256 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3258 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3259 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3260 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3261 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3262 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3263 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003264 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303265 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003266 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003267 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003268 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3270 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3273 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003274 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003276 }
3277 } else {
3278 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303279 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3280 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3282 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3284 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003286 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003288 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003289 }
3290}
3291
Daniel Vetter5829975c2015-04-16 11:36:52 +02003292static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003293{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003294 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003295 unsigned long demph_reg_value, preemph_reg_value,
3296 uniqtranscale_reg_value;
3297 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003298
3299 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303300 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003301 preemph_reg_value = 0x0004000;
3302 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003304 demph_reg_value = 0x2B405555;
3305 uniqtranscale_reg_value = 0x552AB83A;
3306 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003308 demph_reg_value = 0x2B404040;
3309 uniqtranscale_reg_value = 0x5548B83A;
3310 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303311 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003312 demph_reg_value = 0x2B245555;
3313 uniqtranscale_reg_value = 0x5560B83A;
3314 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303315 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003316 demph_reg_value = 0x2B405555;
3317 uniqtranscale_reg_value = 0x5598DA3A;
3318 break;
3319 default:
3320 return 0;
3321 }
3322 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303323 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003324 preemph_reg_value = 0x0002000;
3325 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303326 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003327 demph_reg_value = 0x2B404040;
3328 uniqtranscale_reg_value = 0x5552B83A;
3329 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303330 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003331 demph_reg_value = 0x2B404848;
3332 uniqtranscale_reg_value = 0x5580B83A;
3333 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303334 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003335 demph_reg_value = 0x2B404040;
3336 uniqtranscale_reg_value = 0x55ADDA3A;
3337 break;
3338 default:
3339 return 0;
3340 }
3341 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303342 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003343 preemph_reg_value = 0x0000000;
3344 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303345 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003346 demph_reg_value = 0x2B305555;
3347 uniqtranscale_reg_value = 0x5570B83A;
3348 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303349 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003350 demph_reg_value = 0x2B2B4040;
3351 uniqtranscale_reg_value = 0x55ADDA3A;
3352 break;
3353 default:
3354 return 0;
3355 }
3356 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303357 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003358 preemph_reg_value = 0x0006000;
3359 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003361 demph_reg_value = 0x1B405555;
3362 uniqtranscale_reg_value = 0x55ADDA3A;
3363 break;
3364 default:
3365 return 0;
3366 }
3367 break;
3368 default:
3369 return 0;
3370 }
3371
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003372 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3373 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003374
3375 return 0;
3376}
3377
Daniel Vetter5829975c2015-04-16 11:36:52 +02003378static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003379{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003380 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3381 u32 deemph_reg_value, margin_reg_value;
3382 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003383 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003384
3385 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303386 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003387 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303388 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003389 deemph_reg_value = 128;
3390 margin_reg_value = 52;
3391 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303392 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003393 deemph_reg_value = 128;
3394 margin_reg_value = 77;
3395 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303396 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003397 deemph_reg_value = 128;
3398 margin_reg_value = 102;
3399 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303400 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003401 deemph_reg_value = 128;
3402 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003403 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003404 break;
3405 default:
3406 return 0;
3407 }
3408 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303409 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003410 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303411 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003412 deemph_reg_value = 85;
3413 margin_reg_value = 78;
3414 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003416 deemph_reg_value = 85;
3417 margin_reg_value = 116;
3418 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303419 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003420 deemph_reg_value = 85;
3421 margin_reg_value = 154;
3422 break;
3423 default:
3424 return 0;
3425 }
3426 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303427 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003428 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003430 deemph_reg_value = 64;
3431 margin_reg_value = 104;
3432 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303433 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003434 deemph_reg_value = 64;
3435 margin_reg_value = 154;
3436 break;
3437 default:
3438 return 0;
3439 }
3440 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303441 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003442 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303443 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003444 deemph_reg_value = 43;
3445 margin_reg_value = 154;
3446 break;
3447 default:
3448 return 0;
3449 }
3450 break;
3451 default:
3452 return 0;
3453 }
3454
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003455 chv_set_phy_signal_level(encoder, deemph_reg_value,
3456 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003457
3458 return 0;
3459}
3460
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003461static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003462gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003463{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003464 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003465
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003466 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303467 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003468 default:
3469 signal_levels |= DP_VOLTAGE_0_4;
3470 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303471 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003472 signal_levels |= DP_VOLTAGE_0_6;
3473 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303474 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003475 signal_levels |= DP_VOLTAGE_0_8;
3476 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303477 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003478 signal_levels |= DP_VOLTAGE_1_2;
3479 break;
3480 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003481 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303482 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003483 default:
3484 signal_levels |= DP_PRE_EMPHASIS_0;
3485 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303486 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003487 signal_levels |= DP_PRE_EMPHASIS_3_5;
3488 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303489 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003490 signal_levels |= DP_PRE_EMPHASIS_6;
3491 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303492 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003493 signal_levels |= DP_PRE_EMPHASIS_9_5;
3494 break;
3495 }
3496 return signal_levels;
3497}
3498
Zhenyu Wange3421a12010-04-08 09:43:27 +08003499/* Gen6's DP voltage swing and pre-emphasis control */
3500static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003501gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003502{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003503 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3504 DP_TRAIN_PRE_EMPHASIS_MASK);
3505 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303506 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3507 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003508 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303509 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003510 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303511 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3512 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003513 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303514 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3515 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003516 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303517 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3518 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003519 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003520 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003521 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3522 "0x%x\n", signal_levels);
3523 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003524 }
3525}
3526
Keith Packard1a2eb462011-11-16 16:26:07 -08003527/* Gen7's DP voltage swing and pre-emphasis control */
3528static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003529gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003530{
3531 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3532 DP_TRAIN_PRE_EMPHASIS_MASK);
3533 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303534 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003535 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303536 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003537 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303538 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003539 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3540
Sonika Jindalbd600182014-08-08 16:23:41 +05303541 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003542 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303543 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003544 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3545
Sonika Jindalbd600182014-08-08 16:23:41 +05303546 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003547 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303548 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003549 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3550
3551 default:
3552 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3553 "0x%x\n", signal_levels);
3554 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3555 }
3556}
3557
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003558void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003559intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003560{
Ville Syrjälä2f773472017-11-09 17:27:58 +02003561 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Paulo Zanonif0a34242012-12-06 16:51:50 -02003562 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003563 enum port port = intel_dig_port->base.port;
David Weinehallf8896f52015-06-25 11:11:03 +03003564 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003565 uint8_t train_set = intel_dp->train_set[0];
3566
Rodrigo Vivid509af62017-08-29 16:22:24 -07003567 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3568 signal_levels = bxt_signal_levels(intel_dp);
3569 } else if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003570 signal_levels = ddi_signal_levels(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07003571 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003572 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003573 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003574 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003575 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003576 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003577 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003578 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003579 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003580 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003581 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3582 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003583 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003584 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3585 }
3586
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303587 if (mask)
3588 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3589
3590 DRM_DEBUG_KMS("Using vswing level %d\n",
3591 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3592 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3593 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3594 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003595
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003596 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003597
3598 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3599 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003600}
3601
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003602void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003603intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3604 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003605{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003606 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003607 struct drm_i915_private *dev_priv =
3608 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003609
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003610 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003611
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003612 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003613 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003614}
3615
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003616void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003617{
Ville Syrjälä2f773472017-11-09 17:27:58 +02003618 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak3ab9c632013-05-03 12:57:41 +03003619 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003620 enum port port = intel_dig_port->base.port;
Imre Deak3ab9c632013-05-03 12:57:41 +03003621 uint32_t val;
3622
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003623 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003624 return;
3625
3626 val = I915_READ(DP_TP_CTL(port));
3627 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3628 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3629 I915_WRITE(DP_TP_CTL(port), val);
3630
3631 /*
3632 * On PORT_A we can have only eDP in SST mode. There the only reason
3633 * we need to set idle transmission mode is to work around a HW issue
3634 * where we enable the pipe while not in idle link-training mode.
3635 * In this case there is requirement to wait for a minimum number of
3636 * idle patterns to be sent.
3637 */
3638 if (port == PORT_A)
3639 return;
3640
Chris Wilsona7670172016-06-30 15:33:10 +01003641 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3642 DP_TP_STATUS_IDLE_DONE,
3643 DP_TP_STATUS_IDLE_DONE,
3644 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003645 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3646}
3647
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003648static void
Ville Syrjäläadc10302017-10-31 22:51:14 +02003649intel_dp_link_down(struct intel_encoder *encoder,
3650 const struct intel_crtc_state *old_crtc_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003651{
Ville Syrjäläadc10302017-10-31 22:51:14 +02003652 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3653 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3654 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3655 enum port port = encoder->port;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003656 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003657
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003658 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003659 return;
3660
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003661 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003662 return;
3663
Zhao Yakui28c97732009-10-09 11:39:41 +08003664 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003665
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003666 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003667 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003668 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003669 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003670 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003671 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003672 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3673 else
3674 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003675 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003676 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003677 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003678 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003679
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003680 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3681 I915_WRITE(intel_dp->output_reg, DP);
3682 POSTING_READ(intel_dp->output_reg);
3683
3684 /*
3685 * HW workaround for IBX, we need to move the port
3686 * to transcoder A after disabling it to allow the
3687 * matching HDMI port to be enabled on transcoder A.
3688 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003689 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003690 /*
3691 * We get CPU/PCH FIFO underruns on the other pipe when
3692 * doing the workaround. Sweep them under the rug.
3693 */
3694 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3695 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3696
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003697 /* always enable with pattern 1 (as per spec) */
3698 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3699 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3700 I915_WRITE(intel_dp->output_reg, DP);
3701 POSTING_READ(intel_dp->output_reg);
3702
3703 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003704 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003705 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003706
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003707 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003708 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3709 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003710 }
3711
Keith Packardf01eca22011-09-28 16:48:10 -07003712 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003713
3714 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003715
3716 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3717 pps_lock(intel_dp);
3718 intel_dp->active_pipe = INVALID_PIPE;
3719 pps_unlock(intel_dp);
3720 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003721}
3722
Imre Deak24e807e2016-10-24 19:33:28 +03003723bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003724intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003725{
Lyude9f085eb2016-04-13 10:58:33 -04003726 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3727 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003728 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003729
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003730 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003731
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003732 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3733}
3734
3735static bool
3736intel_edp_init_dpcd(struct intel_dp *intel_dp)
3737{
3738 struct drm_i915_private *dev_priv =
3739 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3740
3741 /* this function is meant to be called only once */
3742 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3743
3744 if (!intel_dp_read_dpcd(intel_dp))
3745 return false;
3746
Jani Nikula84c36752017-05-18 14:10:23 +03003747 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3748 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003749
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003750 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3751 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3752 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3753
Dhinakaran Pandiyan77fe36f2018-02-23 14:15:17 -08003754 intel_psr_init_dpcd(intel_dp);
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003755
Jani Nikula7c838e22017-10-26 17:29:31 +03003756 /*
3757 * Read the eDP display control registers.
3758 *
3759 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3760 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3761 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3762 * method). The display control registers should read zero if they're
3763 * not supported anyway.
3764 */
3765 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003766 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3767 sizeof(intel_dp->edp_dpcd))
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003768 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003769 intel_dp->edp_dpcd);
3770
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003771 /* Read the eDP 1.4+ supported link rates. */
3772 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003773 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3774 int i;
3775
3776 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3777 sink_rates, sizeof(sink_rates));
3778
3779 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3780 int val = le16_to_cpu(sink_rates[i]);
3781
3782 if (val == 0)
3783 break;
3784
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003785 /* Value read multiplied by 200kHz gives the per-lane
3786 * link rate in kHz. The source rates are, however,
3787 * stored in terms of LS_Clk kHz. The full conversion
3788 * back to symbols is
3789 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3790 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003791 intel_dp->sink_rates[i] = (val * 200) / 10;
3792 }
3793 intel_dp->num_sink_rates = i;
3794 }
3795
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003796 /*
3797 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3798 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3799 */
Jani Nikula68f357c2017-03-28 17:59:05 +03003800 if (intel_dp->num_sink_rates)
3801 intel_dp->use_rate_select = true;
3802 else
3803 intel_dp_set_sink_rates(intel_dp);
3804
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003805 intel_dp_set_common_rates(intel_dp);
3806
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003807 return true;
3808}
3809
3810
3811static bool
3812intel_dp_get_dpcd(struct intel_dp *intel_dp)
3813{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003814 u8 sink_count;
3815
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003816 if (!intel_dp_read_dpcd(intel_dp))
3817 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003818
Jani Nikula68f357c2017-03-28 17:59:05 +03003819 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003820 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003821 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003822 intel_dp_set_common_rates(intel_dp);
3823 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003824
Jani Nikula27dbefb2017-04-06 16:44:17 +03003825 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303826 return false;
3827
3828 /*
3829 * Sink count can change between short pulse hpd hence
3830 * a member variable in intel_dp will track any changes
3831 * between short pulse interrupts.
3832 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003833 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303834
3835 /*
3836 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3837 * a dongle is present but no display. Unless we require to know
3838 * if a dongle is present or not, we don't need to update
3839 * downstream port information. So, an early return here saves
3840 * time from performing other operations which are not required.
3841 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003842 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303843 return false;
3844
Imre Deakc726ad02016-10-24 19:33:24 +03003845 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003846 return true; /* native DP sink */
3847
3848 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3849 return true; /* no per-port downstream info */
3850
Lyude9f085eb2016-04-13 10:58:33 -04003851 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3852 intel_dp->downstream_ports,
3853 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003854 return false; /* downstream port status fetch failed */
3855
3856 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003857}
3858
Dave Airlie0e32b392014-05-02 14:02:48 +10003859static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003860intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003861{
Jani Nikula010b9b32017-04-06 16:44:16 +03003862 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003863
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003864 if (!i915_modparams.enable_dp_mst)
Nathan Schulte7cc96132016-03-15 10:14:05 -05003865 return false;
3866
Dave Airlie0e32b392014-05-02 14:02:48 +10003867 if (!intel_dp->can_mst)
3868 return false;
3869
3870 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3871 return false;
3872
Jani Nikula010b9b32017-04-06 16:44:16 +03003873 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003874 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003875
Jani Nikula010b9b32017-04-06 16:44:16 +03003876 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003877}
3878
3879static void
3880intel_dp_configure_mst(struct intel_dp *intel_dp)
3881{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003882 if (!i915_modparams.enable_dp_mst)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003883 return;
3884
3885 if (!intel_dp->can_mst)
3886 return;
3887
3888 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3889
3890 if (intel_dp->is_mst)
3891 DRM_DEBUG_KMS("Sink is MST capable\n");
3892 else
3893 DRM_DEBUG_KMS("Sink is not MST capable\n");
3894
3895 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3896 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003897}
3898
Maarten Lankhorst93313532017-11-10 12:34:59 +01003899static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp,
3900 struct intel_crtc_state *crtc_state, bool disable_wa)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003901{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003902 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003903 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Maarten Lankhorst93313532017-11-10 12:34:59 +01003904 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003905 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003906 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003907 int count = 0;
3908 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003909
3910 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003911 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003912 ret = -EIO;
3913 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003914 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003915
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003916 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003917 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003918 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003919 ret = -EIO;
3920 goto out;
3921 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003922
Rodrigo Vivic6297842015-11-05 10:50:20 -08003923 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003924 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003925
3926 if (drm_dp_dpcd_readb(&intel_dp->aux,
3927 DP_TEST_SINK_MISC, &buf) < 0) {
3928 ret = -EIO;
3929 goto out;
3930 }
3931 count = buf & DP_TEST_COUNT_MASK;
3932 } while (--attempts && count);
3933
3934 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003935 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003936 ret = -ETIMEDOUT;
3937 }
3938
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003939 out:
Maarten Lankhorst93313532017-11-10 12:34:59 +01003940 if (disable_wa)
Maarten Lankhorst199ea382017-11-10 12:35:00 +01003941 hsw_enable_ips(crtc_state);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003942 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003943}
3944
Maarten Lankhorst93313532017-11-10 12:34:59 +01003945static int intel_dp_sink_crc_start(struct intel_dp *intel_dp,
3946 struct intel_crtc_state *crtc_state)
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003947{
3948 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003949 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Maarten Lankhorst93313532017-11-10 12:34:59 +01003950 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003951 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003952 int ret;
3953
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003954 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3955 return -EIO;
3956
3957 if (!(buf & DP_TEST_CRC_SUPPORTED))
3958 return -ENOTTY;
3959
3960 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3961 return -EIO;
3962
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003963 if (buf & DP_TEST_SINK_START) {
Maarten Lankhorst93313532017-11-10 12:34:59 +01003964 ret = intel_dp_sink_crc_stop(intel_dp, crtc_state, false);
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003965 if (ret)
3966 return ret;
3967 }
3968
Maarten Lankhorst199ea382017-11-10 12:35:00 +01003969 hsw_disable_ips(crtc_state);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003970
3971 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3972 buf | DP_TEST_SINK_START) < 0) {
Maarten Lankhorst199ea382017-11-10 12:35:00 +01003973 hsw_enable_ips(crtc_state);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003974 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003975 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003976
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003977 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003978 return 0;
3979}
3980
Maarten Lankhorst93313532017-11-10 12:34:59 +01003981int intel_dp_sink_crc(struct intel_dp *intel_dp, struct intel_crtc_state *crtc_state, u8 *crc)
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003982{
3983 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003984 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Maarten Lankhorst93313532017-11-10 12:34:59 +01003985 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003986 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003987 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003988 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003989
Maarten Lankhorst93313532017-11-10 12:34:59 +01003990 ret = intel_dp_sink_crc_start(intel_dp, crtc_state);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003991 if (ret)
3992 return ret;
3993
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003994 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003995 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003996
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003997 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003998 DP_TEST_SINK_MISC, &buf) < 0) {
3999 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004000 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004001 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004002 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07004003
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004004 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004005
4006 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004007 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4008 ret = -ETIMEDOUT;
4009 goto stop;
4010 }
4011
4012 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4013 ret = -EIO;
4014 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004015 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004016
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004017stop:
Maarten Lankhorst93313532017-11-10 12:34:59 +01004018 intel_dp_sink_crc_stop(intel_dp, crtc_state, true);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004019 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004020}
4021
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004022static bool
4023intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4024{
Jani Nikula010b9b32017-04-06 16:44:16 +03004025 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4026 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004027}
4028
Dave Airlie0e32b392014-05-02 14:02:48 +10004029static bool
4030intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4031{
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004032 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4033 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4034 DP_DPRX_ESI_LEN;
Dave Airlie0e32b392014-05-02 14:02:48 +10004035}
4036
Todd Previtec5d5ab72015-04-15 08:38:38 -07004037static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004038{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004039 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004040 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004041 uint8_t test_lane_count, test_link_bw;
4042 /* (DP CTS 1.2)
4043 * 4.3.1.11
4044 */
4045 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4046 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4047 &test_lane_count);
4048
4049 if (status <= 0) {
4050 DRM_DEBUG_KMS("Lane count read failed\n");
4051 return DP_TEST_NAK;
4052 }
4053 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004054
4055 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4056 &test_link_bw);
4057 if (status <= 0) {
4058 DRM_DEBUG_KMS("Link Rate read failed\n");
4059 return DP_TEST_NAK;
4060 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004061 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004062
4063 /* Validate the requested link rate and lane count */
4064 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4065 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004066 return DP_TEST_NAK;
4067
4068 intel_dp->compliance.test_lane_count = test_lane_count;
4069 intel_dp->compliance.test_link_rate = test_link_rate;
4070
4071 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004072}
4073
4074static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4075{
Manasi Navare611032b2017-01-24 08:21:49 -08004076 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004077 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004078 __be16 h_width, v_height;
4079 int status = 0;
4080
4081 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004082 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4083 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004084 if (status <= 0) {
4085 DRM_DEBUG_KMS("Test pattern read failed\n");
4086 return DP_TEST_NAK;
4087 }
4088 if (test_pattern != DP_COLOR_RAMP)
4089 return DP_TEST_NAK;
4090
4091 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4092 &h_width, 2);
4093 if (status <= 0) {
4094 DRM_DEBUG_KMS("H Width read failed\n");
4095 return DP_TEST_NAK;
4096 }
4097
4098 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4099 &v_height, 2);
4100 if (status <= 0) {
4101 DRM_DEBUG_KMS("V Height read failed\n");
4102 return DP_TEST_NAK;
4103 }
4104
Jani Nikula010b9b32017-04-06 16:44:16 +03004105 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4106 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004107 if (status <= 0) {
4108 DRM_DEBUG_KMS("TEST MISC read failed\n");
4109 return DP_TEST_NAK;
4110 }
4111 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4112 return DP_TEST_NAK;
4113 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4114 return DP_TEST_NAK;
4115 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4116 case DP_TEST_BIT_DEPTH_6:
4117 intel_dp->compliance.test_data.bpc = 6;
4118 break;
4119 case DP_TEST_BIT_DEPTH_8:
4120 intel_dp->compliance.test_data.bpc = 8;
4121 break;
4122 default:
4123 return DP_TEST_NAK;
4124 }
4125
4126 intel_dp->compliance.test_data.video_pattern = test_pattern;
4127 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4128 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4129 /* Set test active flag here so userspace doesn't interrupt things */
4130 intel_dp->compliance.test_active = 1;
4131
4132 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004133}
4134
4135static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4136{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004137 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004138 struct intel_connector *intel_connector = intel_dp->attached_connector;
4139 struct drm_connector *connector = &intel_connector->base;
4140
4141 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004142 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004143 intel_dp->aux.i2c_defer_count > 6) {
4144 /* Check EDID read for NACKs, DEFERs and corruption
4145 * (DP CTS 1.2 Core r1.1)
4146 * 4.2.2.4 : Failed EDID read, I2C_NAK
4147 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4148 * 4.2.2.6 : EDID corruption detected
4149 * Use failsafe mode for all cases
4150 */
4151 if (intel_dp->aux.i2c_nack_count > 0 ||
4152 intel_dp->aux.i2c_defer_count > 0)
4153 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4154 intel_dp->aux.i2c_nack_count,
4155 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004156 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004157 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304158 struct edid *block = intel_connector->detect_edid;
4159
4160 /* We have to write the checksum
4161 * of the last block read
4162 */
4163 block += intel_connector->detect_edid->extensions;
4164
Jani Nikula010b9b32017-04-06 16:44:16 +03004165 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4166 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004167 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4168
4169 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004170 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004171 }
4172
4173 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004174 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004175
Todd Previtec5d5ab72015-04-15 08:38:38 -07004176 return test_result;
4177}
4178
4179static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4180{
4181 uint8_t test_result = DP_TEST_NAK;
4182 return test_result;
4183}
4184
4185static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4186{
4187 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004188 uint8_t request = 0;
4189 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004190
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004191 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004192 if (status <= 0) {
4193 DRM_DEBUG_KMS("Could not read test request from sink\n");
4194 goto update_status;
4195 }
4196
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004197 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004198 case DP_TEST_LINK_TRAINING:
4199 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004200 response = intel_dp_autotest_link_training(intel_dp);
4201 break;
4202 case DP_TEST_LINK_VIDEO_PATTERN:
4203 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004204 response = intel_dp_autotest_video_pattern(intel_dp);
4205 break;
4206 case DP_TEST_LINK_EDID_READ:
4207 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004208 response = intel_dp_autotest_edid(intel_dp);
4209 break;
4210 case DP_TEST_LINK_PHY_TEST_PATTERN:
4211 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004212 response = intel_dp_autotest_phy_pattern(intel_dp);
4213 break;
4214 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004215 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004216 break;
4217 }
4218
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004219 if (response & DP_TEST_ACK)
4220 intel_dp->compliance.test_type = request;
4221
Todd Previtec5d5ab72015-04-15 08:38:38 -07004222update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004223 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004224 if (status <= 0)
4225 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004226}
4227
Dave Airlie0e32b392014-05-02 14:02:48 +10004228static int
4229intel_dp_check_mst_status(struct intel_dp *intel_dp)
4230{
4231 bool bret;
4232
4233 if (intel_dp->is_mst) {
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004234 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
Dave Airlie0e32b392014-05-02 14:02:48 +10004235 int ret = 0;
4236 int retry;
4237 bool handled;
4238 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4239go_again:
4240 if (bret == true) {
4241
4242 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004243 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004244 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004245 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4246 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004247 intel_dp_stop_link_train(intel_dp);
4248 }
4249
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004250 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004251 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4252
4253 if (handled) {
4254 for (retry = 0; retry < 3; retry++) {
4255 int wret;
4256 wret = drm_dp_dpcd_write(&intel_dp->aux,
4257 DP_SINK_COUNT_ESI+1,
4258 &esi[1], 3);
4259 if (wret == 3) {
4260 break;
4261 }
4262 }
4263
4264 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4265 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004266 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004267 goto go_again;
4268 }
4269 } else
4270 ret = 0;
4271
4272 return ret;
4273 } else {
4274 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4275 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4276 intel_dp->is_mst = false;
4277 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4278 /* send a hotplug event */
4279 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4280 }
4281 }
4282 return -EINVAL;
4283}
4284
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304285static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004286intel_dp_retrain_link(struct intel_dp *intel_dp)
4287{
4288 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4289 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4290 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4291
4292 /* Suppress underruns caused by re-training */
4293 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4294 if (crtc->config->has_pch_encoder)
4295 intel_set_pch_fifo_underrun_reporting(dev_priv,
4296 intel_crtc_pch_transcoder(crtc), false);
4297
4298 intel_dp_start_link_train(intel_dp);
4299 intel_dp_stop_link_train(intel_dp);
4300
4301 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004302 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004303
4304 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4305 if (crtc->config->has_pch_encoder)
4306 intel_set_pch_fifo_underrun_reporting(dev_priv,
4307 intel_crtc_pch_transcoder(crtc), true);
4308}
4309
4310static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304311intel_dp_check_link_status(struct intel_dp *intel_dp)
4312{
Ville Syrjälä2f773472017-11-09 17:27:58 +02004313 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304314 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Daniel Vetter42e5e652017-11-13 17:01:40 +01004315 struct drm_connector_state *conn_state =
4316 intel_dp->attached_connector->base.state;
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304317 u8 link_status[DP_LINK_STATUS_SIZE];
4318
Ville Syrjälä2f773472017-11-09 17:27:58 +02004319 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304320
4321 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4322 DRM_ERROR("Failed to get link status\n");
4323 return;
4324 }
4325
Daniel Vetter42e5e652017-11-13 17:01:40 +01004326 if (!conn_state->crtc)
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304327 return;
4328
Daniel Vetter42e5e652017-11-13 17:01:40 +01004329 WARN_ON(!drm_modeset_is_locked(&conn_state->crtc->mutex));
4330
4331 if (!conn_state->crtc->state->active)
4332 return;
4333
4334 if (conn_state->commit &&
4335 !try_wait_for_completion(&conn_state->commit->hw_done))
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304336 return;
4337
Manasi Navare14c562c2017-04-06 14:00:12 -07004338 /*
4339 * Validate the cached values of intel_dp->link_rate and
4340 * intel_dp->lane_count before attempting to retrain.
4341 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004342 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4343 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004344 return;
4345
Manasi Navareda15f7c2017-01-24 08:16:34 -08004346 /* Retrain if Channel EQ or CR not ok */
4347 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304348 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4349 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004350
4351 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304352 }
4353}
4354
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004355/*
4356 * According to DP spec
4357 * 5.1.2:
4358 * 1. Read DPCD
4359 * 2. Configure link according to Receiver Capabilities
4360 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4361 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304362 *
4363 * intel_dp_short_pulse - handles short pulse interrupts
4364 * when full detection is not required.
4365 * Returns %true if short pulse is handled and full detection
4366 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004367 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304368static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304369intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004370{
Ville Syrjälä2f773472017-11-09 17:27:58 +02004371 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004372 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304373 u8 old_sink_count = intel_dp->sink_count;
4374 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004375
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304376 /*
4377 * Clearing compliance test variables to allow capturing
4378 * of values for next automated test request.
4379 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004380 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304381
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304382 /*
4383 * Now read the DPCD to see if it's actually running
4384 * If the current value of sink count doesn't match with
4385 * the value that was stored earlier or dpcd read failed
4386 * we need to do full detection
4387 */
4388 ret = intel_dp_get_dpcd(intel_dp);
4389
4390 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4391 /* No need to proceed if we are going to do full detect */
4392 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004393 }
4394
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004395 /* Try to read the source of the interrupt */
4396 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004397 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4398 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004399 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004400 drm_dp_dpcd_writeb(&intel_dp->aux,
4401 DP_DEVICE_SERVICE_IRQ_VECTOR,
4402 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004403
4404 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004405 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004406 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4407 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4408 }
4409
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304410 intel_dp_check_link_status(intel_dp);
Daniel Vetter42e5e652017-11-13 17:01:40 +01004411
Manasi Navareda15f7c2017-01-24 08:16:34 -08004412 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4413 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4414 /* Send a Hotplug Uevent to userspace to start modeset */
Ville Syrjälä2f773472017-11-09 17:27:58 +02004415 drm_kms_helper_hotplug_event(&dev_priv->drm);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004416 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304417
4418 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004419}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004420
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004421/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004422static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004423intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004424{
Imre Deake393d0d2017-02-22 17:10:52 +02004425 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004426 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004427 uint8_t type;
4428
Imre Deake393d0d2017-02-22 17:10:52 +02004429 if (lspcon->active)
4430 lspcon_resume(lspcon);
4431
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004432 if (!intel_dp_get_dpcd(intel_dp))
4433 return connector_status_disconnected;
4434
Jani Nikula1853a9d2017-08-18 12:30:20 +03004435 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304436 return connector_status_connected;
4437
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004438 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004439 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004440 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004441
4442 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004443 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4444 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004445
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304446 return intel_dp->sink_count ?
4447 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004448 }
4449
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004450 if (intel_dp_can_mst(intel_dp))
4451 return connector_status_connected;
4452
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004453 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004454 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004455 return connector_status_connected;
4456
4457 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004458 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4459 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4460 if (type == DP_DS_PORT_TYPE_VGA ||
4461 type == DP_DS_PORT_TYPE_NON_EDID)
4462 return connector_status_unknown;
4463 } else {
4464 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4465 DP_DWN_STRM_PORT_TYPE_MASK;
4466 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4467 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4468 return connector_status_unknown;
4469 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004470
4471 /* Anything else is out of spec, warn and ignore */
4472 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004473 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004474}
4475
4476static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004477edp_detect(struct intel_dp *intel_dp)
4478{
Ville Syrjälä2f773472017-11-09 17:27:58 +02004479 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Chris Wilsond410b562014-09-02 20:03:59 +01004480 enum drm_connector_status status;
4481
Mika Kahola1650be72016-12-13 10:02:47 +02004482 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004483 if (status == connector_status_unknown)
4484 status = connector_status_connected;
4485
4486 return status;
4487}
4488
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004489static bool ibx_digital_port_connected(struct intel_encoder *encoder)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004490{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004491 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikulab93433c2015-08-20 10:47:36 +03004492 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004493
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004494 switch (encoder->hpd_pin) {
4495 case HPD_PORT_B:
Jani Nikula0df53b72015-08-20 10:47:40 +03004496 bit = SDE_PORTB_HOTPLUG;
4497 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004498 case HPD_PORT_C:
Jani Nikula0df53b72015-08-20 10:47:40 +03004499 bit = SDE_PORTC_HOTPLUG;
4500 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004501 case HPD_PORT_D:
Jani Nikula0df53b72015-08-20 10:47:40 +03004502 bit = SDE_PORTD_HOTPLUG;
4503 break;
4504 default:
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004505 MISSING_CASE(encoder->hpd_pin);
Jani Nikula0df53b72015-08-20 10:47:40 +03004506 return false;
4507 }
4508
4509 return I915_READ(SDEISR) & bit;
4510}
4511
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004512static bool cpt_digital_port_connected(struct intel_encoder *encoder)
Jani Nikula0df53b72015-08-20 10:47:40 +03004513{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004514 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula0df53b72015-08-20 10:47:40 +03004515 u32 bit;
4516
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004517 switch (encoder->hpd_pin) {
4518 case HPD_PORT_B:
Jani Nikula0df53b72015-08-20 10:47:40 +03004519 bit = SDE_PORTB_HOTPLUG_CPT;
4520 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004521 case HPD_PORT_C:
Jani Nikula0df53b72015-08-20 10:47:40 +03004522 bit = SDE_PORTC_HOTPLUG_CPT;
4523 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004524 case HPD_PORT_D:
Jani Nikula0df53b72015-08-20 10:47:40 +03004525 bit = SDE_PORTD_HOTPLUG_CPT;
4526 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004527 default:
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004528 MISSING_CASE(encoder->hpd_pin);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004529 return false;
4530 }
4531
4532 return I915_READ(SDEISR) & bit;
4533}
4534
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004535static bool spt_digital_port_connected(struct intel_encoder *encoder)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004536{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004537 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004538 u32 bit;
4539
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004540 switch (encoder->hpd_pin) {
4541 case HPD_PORT_A:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004542 bit = SDE_PORTA_HOTPLUG_SPT;
4543 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004544 case HPD_PORT_E:
Jani Nikulaa78695d2015-09-18 15:54:50 +03004545 bit = SDE_PORTE_HOTPLUG_SPT;
4546 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004547 default:
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004548 return cpt_digital_port_connected(encoder);
Jani Nikulab93433c2015-08-20 10:47:36 +03004549 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004550
Jani Nikulab93433c2015-08-20 10:47:36 +03004551 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004552}
4553
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004554static bool g4x_digital_port_connected(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004555{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004556 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula9642c812015-08-20 10:47:41 +03004557 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004558
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004559 switch (encoder->hpd_pin) {
4560 case HPD_PORT_B:
Jani Nikula9642c812015-08-20 10:47:41 +03004561 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4562 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004563 case HPD_PORT_C:
Jani Nikula9642c812015-08-20 10:47:41 +03004564 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4565 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004566 case HPD_PORT_D:
Jani Nikula9642c812015-08-20 10:47:41 +03004567 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4568 break;
4569 default:
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004570 MISSING_CASE(encoder->hpd_pin);
Jani Nikula9642c812015-08-20 10:47:41 +03004571 return false;
4572 }
4573
4574 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4575}
4576
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004577static bool gm45_digital_port_connected(struct intel_encoder *encoder)
Jani Nikula9642c812015-08-20 10:47:41 +03004578{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004579 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula9642c812015-08-20 10:47:41 +03004580 u32 bit;
4581
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004582 switch (encoder->hpd_pin) {
4583 case HPD_PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004584 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004585 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004586 case HPD_PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004587 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004588 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004589 case HPD_PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004590 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004591 break;
4592 default:
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004593 MISSING_CASE(encoder->hpd_pin);
Jani Nikula9642c812015-08-20 10:47:41 +03004594 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004595 }
4596
Jani Nikula1d245982015-08-20 10:47:37 +03004597 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004598}
4599
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004600static bool ilk_digital_port_connected(struct intel_encoder *encoder)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004601{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004602 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4603
4604 if (encoder->hpd_pin == HPD_PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004605 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4606 else
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004607 return ibx_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004608}
4609
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004610static bool snb_digital_port_connected(struct intel_encoder *encoder)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004611{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004612 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4613
4614 if (encoder->hpd_pin == HPD_PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004615 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4616 else
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004617 return cpt_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004618}
4619
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004620static bool ivb_digital_port_connected(struct intel_encoder *encoder)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004621{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004622 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4623
4624 if (encoder->hpd_pin == HPD_PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004625 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4626 else
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004627 return cpt_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004628}
4629
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004630static bool bdw_digital_port_connected(struct intel_encoder *encoder)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004631{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004632 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4633
4634 if (encoder->hpd_pin == HPD_PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004635 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4636 else
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004637 return cpt_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004638}
4639
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004640static bool bxt_digital_port_connected(struct intel_encoder *encoder)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004641{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004642 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004643 u32 bit;
4644
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004645 switch (encoder->hpd_pin) {
4646 case HPD_PORT_A:
Jani Nikulae464bfd2015-08-20 10:47:42 +03004647 bit = BXT_DE_PORT_HP_DDIA;
4648 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004649 case HPD_PORT_B:
Jani Nikulae464bfd2015-08-20 10:47:42 +03004650 bit = BXT_DE_PORT_HP_DDIB;
4651 break;
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004652 case HPD_PORT_C:
Jani Nikulae464bfd2015-08-20 10:47:42 +03004653 bit = BXT_DE_PORT_HP_DDIC;
4654 break;
4655 default:
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004656 MISSING_CASE(encoder->hpd_pin);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004657 return false;
4658 }
4659
4660 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4661}
4662
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004663/*
4664 * intel_digital_port_connected - is the specified port connected?
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004665 * @encoder: intel_encoder
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004666 *
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004667 * Return %true if port is connected, %false otherwise.
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004668 */
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004669bool intel_digital_port_connected(struct intel_encoder *encoder)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004670{
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004671 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4672
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004673 if (HAS_GMCH_DISPLAY(dev_priv)) {
4674 if (IS_GM45(dev_priv))
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004675 return gm45_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004676 else
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004677 return g4x_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004678 }
4679
4680 if (IS_GEN5(dev_priv))
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004681 return ilk_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004682 else if (IS_GEN6(dev_priv))
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004683 return snb_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004684 else if (IS_GEN7(dev_priv))
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004685 return ivb_digital_port_connected(encoder);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004686 else if (IS_GEN8(dev_priv))
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004687 return bdw_digital_port_connected(encoder);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004688 else if (IS_GEN9_LP(dev_priv))
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004689 return bxt_digital_port_connected(encoder);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004690 else
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004691 return spt_digital_port_connected(encoder);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004692}
4693
Keith Packard8c241fe2011-09-28 16:38:44 -07004694static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004695intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004696{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004697 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004698
Jani Nikula9cd300e2012-10-19 14:51:52 +03004699 /* use cached edid if we have one */
4700 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004701 /* invalid edid */
4702 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004703 return NULL;
4704
Jani Nikula55e9ede2013-10-01 10:38:54 +03004705 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004706 } else
4707 return drm_get_edid(&intel_connector->base,
4708 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004709}
4710
Chris Wilsonbeb60602014-09-02 20:04:00 +01004711static void
4712intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004713{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004714 struct intel_connector *intel_connector = intel_dp->attached_connector;
4715 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004716
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304717 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004718 edid = intel_dp_get_edid(intel_dp);
4719 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004720
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004721 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004722}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004723
Chris Wilsonbeb60602014-09-02 20:04:00 +01004724static void
4725intel_dp_unset_edid(struct intel_dp *intel_dp)
4726{
4727 struct intel_connector *intel_connector = intel_dp->attached_connector;
4728
4729 kfree(intel_connector->detect_edid);
4730 intel_connector->detect_edid = NULL;
4731
4732 intel_dp->has_audio = false;
4733}
4734
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004735static int
Ville Syrjälä2f773472017-11-09 17:27:58 +02004736intel_dp_long_pulse(struct intel_connector *connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004737{
Ville Syrjälä2f773472017-11-09 17:27:58 +02004738 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
4739 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004740 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004741 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004742
Ville Syrjälä2f773472017-11-09 17:27:58 +02004743 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004744
Ville Syrjälä2f773472017-11-09 17:27:58 +02004745 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004746
Chris Wilsond410b562014-09-02 20:03:59 +01004747 /* Can't disconnect eDP, but you can close the lid... */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004748 if (intel_dp_is_edp(intel_dp))
Chris Wilsond410b562014-09-02 20:03:59 +01004749 status = edp_detect(intel_dp);
Rodrigo Vivi7533eb42018-01-29 15:22:20 -08004750 else if (intel_digital_port_connected(&dp_to_dig_port(intel_dp)->base))
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004751 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004752 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004753 status = connector_status_disconnected;
4754
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004755 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004756 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304757
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004758 if (intel_dp->is_mst) {
4759 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4760 intel_dp->is_mst,
4761 intel_dp->mst_mgr.mst_state);
4762 intel_dp->is_mst = false;
4763 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4764 intel_dp->is_mst);
4765 }
4766
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004767 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304768 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004769
Manasi Navared7e8ef02017-02-07 16:54:11 -08004770 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004771 /* Initial max link lane count */
4772 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004773
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004774 /* Initial max link rate */
4775 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004776
4777 intel_dp->reset_link_params = false;
4778 }
Manasi Navaref4829842016-12-05 16:27:36 -08004779
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004780 intel_dp_print_rates(intel_dp);
4781
Jani Nikula84c36752017-05-18 14:10:23 +03004782 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4783 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004784
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004785 intel_dp_configure_mst(intel_dp);
4786
4787 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304788 /*
4789 * If we are in MST mode then this connector
4790 * won't appear connected or have anything
4791 * with EDID on it
4792 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004793 status = connector_status_disconnected;
4794 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004795 } else {
4796 /*
4797 * If display is now connected check links status,
4798 * there has been known issues of link loss triggerring
4799 * long pulse.
4800 *
4801 * Some sinks (eg. ASUS PB287Q) seem to perform some
4802 * weird HPD ping pong during modesets. So we can apparently
4803 * end up with HPD going low during a modeset, and then
4804 * going back up soon after. And once that happens we must
4805 * retrain the link to get a picture. That's in case no
4806 * userspace component reacted to intermittent HPD dip.
4807 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304808 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004809 }
4810
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304811 /*
4812 * Clearing NACK and defer counts to get their exact values
4813 * while reading EDID which are required by Compliance tests
4814 * 4.2.2.4 and 4.2.2.5
4815 */
4816 intel_dp->aux.i2c_nack_count = 0;
4817 intel_dp->aux.i2c_defer_count = 0;
4818
Chris Wilsonbeb60602014-09-02 20:04:00 +01004819 intel_dp_set_edid(intel_dp);
Ville Syrjälä2f773472017-11-09 17:27:58 +02004820 if (intel_dp_is_edp(intel_dp) || connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004821 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304822 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004823
Todd Previte09b1eb12015-04-20 15:27:34 -07004824 /* Try to read the source of the interrupt */
4825 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004826 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4827 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004828 /* Clear interrupt source */
4829 drm_dp_dpcd_writeb(&intel_dp->aux,
4830 DP_DEVICE_SERVICE_IRQ_VECTOR,
4831 sink_irq_vector);
4832
4833 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4834 intel_dp_handle_test_request(intel_dp);
4835 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4836 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4837 }
4838
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004839out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004840 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304841 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304842
Ville Syrjälä2f773472017-11-09 17:27:58 +02004843 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004844 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304845}
4846
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004847static int
4848intel_dp_detect(struct drm_connector *connector,
4849 struct drm_modeset_acquire_ctx *ctx,
4850 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304851{
4852 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004853 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304854
4855 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4856 connector->base.id, connector->name);
4857
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304858 /* If full detect is not performed yet, do a full detect */
Daniel Vetter42e5e652017-11-13 17:01:40 +01004859 if (!intel_dp->detect_done) {
4860 struct drm_crtc *crtc;
4861 int ret;
4862
4863 crtc = connector->state->crtc;
4864 if (crtc) {
4865 ret = drm_modeset_lock(&crtc->mutex, ctx);
4866 if (ret)
4867 return ret;
4868 }
4869
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004870 status = intel_dp_long_pulse(intel_dp->attached_connector);
Daniel Vetter42e5e652017-11-13 17:01:40 +01004871 }
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304872
4873 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304874
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004875 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004876}
4877
Chris Wilsonbeb60602014-09-02 20:04:00 +01004878static void
4879intel_dp_force(struct drm_connector *connector)
4880{
4881 struct intel_dp *intel_dp = intel_attached_dp(connector);
4882 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004883 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004884
4885 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4886 connector->base.id, connector->name);
4887 intel_dp_unset_edid(intel_dp);
4888
4889 if (connector->status != connector_status_connected)
4890 return;
4891
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004892 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004893
4894 intel_dp_set_edid(intel_dp);
4895
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004896 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004897}
4898
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004899static int intel_dp_get_modes(struct drm_connector *connector)
4900{
Jani Nikuladd06f902012-10-19 14:51:50 +03004901 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004902 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004903
Chris Wilsonbeb60602014-09-02 20:04:00 +01004904 edid = intel_connector->detect_edid;
4905 if (edid) {
4906 int ret = intel_connector_update_modes(connector, edid);
4907 if (ret)
4908 return ret;
4909 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004910
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004911 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004912 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004913 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004914 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004915
4916 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004917 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004918 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004919 drm_mode_probed_add(connector, mode);
4920 return 1;
4921 }
4922 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004923
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004924 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004925}
4926
Chris Wilsonf6849602010-09-19 09:29:33 +01004927static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004928intel_dp_connector_register(struct drm_connector *connector)
4929{
4930 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004931 int ret;
4932
4933 ret = intel_connector_register(connector);
4934 if (ret)
4935 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004936
4937 i915_debugfs_connector_add(connector);
4938
4939 DRM_DEBUG_KMS("registering %s bus for %s\n",
4940 intel_dp->aux.name, connector->kdev->kobj.name);
4941
4942 intel_dp->aux.dev = connector->kdev;
4943 return drm_dp_aux_register(&intel_dp->aux);
4944}
4945
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004946static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004947intel_dp_connector_unregister(struct drm_connector *connector)
4948{
4949 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4950 intel_connector_unregister(connector);
4951}
4952
4953static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004954intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004955{
Jani Nikula1d508702012-10-19 14:51:49 +03004956 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004957
Chris Wilson10e972d2014-09-04 21:43:45 +01004958 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004959
Jani Nikula9cd300e2012-10-19 14:51:52 +03004960 if (!IS_ERR_OR_NULL(intel_connector->edid))
4961 kfree(intel_connector->edid);
4962
Jani Nikula1853a9d2017-08-18 12:30:20 +03004963 /*
4964 * Can't call intel_dp_is_edp() since the encoder may have been
4965 * destroyed already.
4966 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004967 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004968 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004969
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004970 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004971 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004972}
4973
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004974void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004975{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004976 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4977 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004978
Dave Airlie0e32b392014-05-02 14:02:48 +10004979 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004980 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004981 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004982 /*
4983 * vdd might still be enabled do to the delayed vdd off.
4984 * Make sure vdd is actually turned off here.
4985 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004986 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004987 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004988 pps_unlock(intel_dp);
4989
Clint Taylor01527b32014-07-07 13:01:46 -07004990 if (intel_dp->edp_notifier.notifier_call) {
4991 unregister_reboot_notifier(&intel_dp->edp_notifier);
4992 intel_dp->edp_notifier.notifier_call = NULL;
4993 }
Keith Packardbd943152011-09-18 23:09:52 -07004994 }
Chris Wilson99681882016-06-20 09:29:17 +01004995
4996 intel_dp_aux_fini(intel_dp);
4997
Imre Deakc8bd0e42014-12-12 17:57:38 +02004998 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004999 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02005000}
5001
Imre Deakbf93ba62016-04-18 10:04:21 +03005002void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03005003{
5004 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
5005
Jani Nikula1853a9d2017-08-18 12:30:20 +03005006 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03005007 return;
5008
Ville Syrjälä951468f2014-09-04 14:55:31 +03005009 /*
5010 * vdd might still be enabled do to the delayed vdd off.
5011 * Make sure vdd is actually turned off here.
5012 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02005013 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005014 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03005015 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005016 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03005017}
5018
Sean Paul20f24d72018-01-08 14:55:43 -05005019static
5020int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *intel_dig_port,
5021 u8 *an)
5022{
5023 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_dig_port->base.base);
5024 uint8_t txbuf[4], rxbuf[2], reply = 0;
5025 ssize_t dpcd_ret;
5026 int ret;
5027
5028 /* Output An first, that's easy */
5029 dpcd_ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux, DP_AUX_HDCP_AN,
5030 an, DRM_HDCP_AN_LEN);
5031 if (dpcd_ret != DRM_HDCP_AN_LEN) {
5032 DRM_ERROR("Failed to write An over DP/AUX (%zd)\n", dpcd_ret);
5033 return dpcd_ret >= 0 ? -EIO : dpcd_ret;
5034 }
5035
5036 /*
5037 * Since Aksv is Oh-So-Secret, we can't access it in software. So in
5038 * order to get it on the wire, we need to create the AUX header as if
5039 * we were writing the data, and then tickle the hardware to output the
5040 * data once the header is sent out.
5041 */
5042 txbuf[0] = (DP_AUX_NATIVE_WRITE << 4) |
5043 ((DP_AUX_HDCP_AKSV >> 16) & 0xf);
5044 txbuf[1] = (DP_AUX_HDCP_AKSV >> 8) & 0xff;
5045 txbuf[2] = DP_AUX_HDCP_AKSV & 0xff;
5046 txbuf[3] = DRM_HDCP_KSV_LEN - 1;
5047
Ville Syrjäläf7606262018-02-22 20:10:34 +02005048 ret = intel_dp_aux_xfer(intel_dp, txbuf, sizeof(txbuf),
5049 rxbuf, sizeof(rxbuf), true);
Sean Paul20f24d72018-01-08 14:55:43 -05005050 if (ret < 0) {
5051 DRM_ERROR("Write Aksv over DP/AUX failed (%d)\n", ret);
5052 return ret;
5053 } else if (ret == 0) {
5054 DRM_ERROR("Aksv write over DP/AUX was empty\n");
5055 return -EIO;
5056 }
5057
5058 reply = (rxbuf[0] >> 4) & DP_AUX_NATIVE_REPLY_MASK;
5059 return reply == DP_AUX_NATIVE_REPLY_ACK ? 0 : -EIO;
5060}
5061
5062static int intel_dp_hdcp_read_bksv(struct intel_digital_port *intel_dig_port,
5063 u8 *bksv)
5064{
5065 ssize_t ret;
5066 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BKSV, bksv,
5067 DRM_HDCP_KSV_LEN);
5068 if (ret != DRM_HDCP_KSV_LEN) {
5069 DRM_ERROR("Read Bksv from DP/AUX failed (%zd)\n", ret);
5070 return ret >= 0 ? -EIO : ret;
5071 }
5072 return 0;
5073}
5074
5075static int intel_dp_hdcp_read_bstatus(struct intel_digital_port *intel_dig_port,
5076 u8 *bstatus)
5077{
5078 ssize_t ret;
5079 /*
5080 * For some reason the HDMI and DP HDCP specs call this register
5081 * definition by different names. In the HDMI spec, it's called BSTATUS,
5082 * but in DP it's called BINFO.
5083 */
5084 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BINFO,
5085 bstatus, DRM_HDCP_BSTATUS_LEN);
5086 if (ret != DRM_HDCP_BSTATUS_LEN) {
5087 DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret);
5088 return ret >= 0 ? -EIO : ret;
5089 }
5090 return 0;
5091}
5092
5093static
Ramalingam C791a98d2018-02-03 03:39:08 +05305094int intel_dp_hdcp_read_bcaps(struct intel_digital_port *intel_dig_port,
5095 u8 *bcaps)
5096{
5097 ssize_t ret;
5098
5099 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BCAPS,
5100 bcaps, 1);
5101 if (ret != 1) {
5102 DRM_ERROR("Read bcaps from DP/AUX failed (%zd)\n", ret);
5103 return ret >= 0 ? -EIO : ret;
5104 }
5105
5106 return 0;
5107}
5108
5109static
Sean Paul20f24d72018-01-08 14:55:43 -05005110int intel_dp_hdcp_repeater_present(struct intel_digital_port *intel_dig_port,
5111 bool *repeater_present)
5112{
5113 ssize_t ret;
5114 u8 bcaps;
Ramalingam C791a98d2018-02-03 03:39:08 +05305115
5116 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
5117 if (ret)
5118 return ret;
5119
Sean Paul20f24d72018-01-08 14:55:43 -05005120 *repeater_present = bcaps & DP_BCAPS_REPEATER_PRESENT;
5121 return 0;
5122}
5123
5124static
5125int intel_dp_hdcp_read_ri_prime(struct intel_digital_port *intel_dig_port,
5126 u8 *ri_prime)
5127{
5128 ssize_t ret;
5129 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_RI_PRIME,
5130 ri_prime, DRM_HDCP_RI_LEN);
5131 if (ret != DRM_HDCP_RI_LEN) {
5132 DRM_ERROR("Read Ri' from DP/AUX failed (%zd)\n", ret);
5133 return ret >= 0 ? -EIO : ret;
5134 }
5135 return 0;
5136}
5137
5138static
5139int intel_dp_hdcp_read_ksv_ready(struct intel_digital_port *intel_dig_port,
5140 bool *ksv_ready)
5141{
5142 ssize_t ret;
5143 u8 bstatus;
5144 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
5145 &bstatus, 1);
5146 if (ret != 1) {
5147 DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret);
5148 return ret >= 0 ? -EIO : ret;
5149 }
5150 *ksv_ready = bstatus & DP_BSTATUS_READY;
5151 return 0;
5152}
5153
5154static
5155int intel_dp_hdcp_read_ksv_fifo(struct intel_digital_port *intel_dig_port,
5156 int num_downstream, u8 *ksv_fifo)
5157{
5158 ssize_t ret;
5159 int i;
5160
5161 /* KSV list is read via 15 byte window (3 entries @ 5 bytes each) */
5162 for (i = 0; i < num_downstream; i += 3) {
5163 size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN;
5164 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5165 DP_AUX_HDCP_KSV_FIFO,
5166 ksv_fifo + i * DRM_HDCP_KSV_LEN,
5167 len);
5168 if (ret != len) {
5169 DRM_ERROR("Read ksv[%d] from DP/AUX failed (%zd)\n", i,
5170 ret);
5171 return ret >= 0 ? -EIO : ret;
5172 }
5173 }
5174 return 0;
5175}
5176
5177static
5178int intel_dp_hdcp_read_v_prime_part(struct intel_digital_port *intel_dig_port,
5179 int i, u32 *part)
5180{
5181 ssize_t ret;
5182
5183 if (i >= DRM_HDCP_V_PRIME_NUM_PARTS)
5184 return -EINVAL;
5185
5186 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5187 DP_AUX_HDCP_V_PRIME(i), part,
5188 DRM_HDCP_V_PRIME_PART_LEN);
5189 if (ret != DRM_HDCP_V_PRIME_PART_LEN) {
5190 DRM_ERROR("Read v'[%d] from DP/AUX failed (%zd)\n", i, ret);
5191 return ret >= 0 ? -EIO : ret;
5192 }
5193 return 0;
5194}
5195
5196static
5197int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *intel_dig_port,
5198 bool enable)
5199{
5200 /* Not used for single stream DisplayPort setups */
5201 return 0;
5202}
5203
5204static
5205bool intel_dp_hdcp_check_link(struct intel_digital_port *intel_dig_port)
5206{
5207 ssize_t ret;
5208 u8 bstatus;
Chris Wilsonb7fc1a92018-01-18 16:10:25 +00005209
Sean Paul20f24d72018-01-08 14:55:43 -05005210 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
5211 &bstatus, 1);
5212 if (ret != 1) {
5213 DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret);
Chris Wilsonb7fc1a92018-01-18 16:10:25 +00005214 return false;
Sean Paul20f24d72018-01-08 14:55:43 -05005215 }
Chris Wilsonb7fc1a92018-01-18 16:10:25 +00005216
Sean Paul20f24d72018-01-08 14:55:43 -05005217 return !(bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ));
5218}
5219
Ramalingam C791a98d2018-02-03 03:39:08 +05305220static
5221int intel_dp_hdcp_capable(struct intel_digital_port *intel_dig_port,
5222 bool *hdcp_capable)
5223{
5224 ssize_t ret;
5225 u8 bcaps;
5226
5227 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
5228 if (ret)
5229 return ret;
5230
5231 *hdcp_capable = bcaps & DP_BCAPS_HDCP_CAPABLE;
5232 return 0;
5233}
5234
Sean Paul20f24d72018-01-08 14:55:43 -05005235static const struct intel_hdcp_shim intel_dp_hdcp_shim = {
5236 .write_an_aksv = intel_dp_hdcp_write_an_aksv,
5237 .read_bksv = intel_dp_hdcp_read_bksv,
5238 .read_bstatus = intel_dp_hdcp_read_bstatus,
5239 .repeater_present = intel_dp_hdcp_repeater_present,
5240 .read_ri_prime = intel_dp_hdcp_read_ri_prime,
5241 .read_ksv_ready = intel_dp_hdcp_read_ksv_ready,
5242 .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo,
5243 .read_v_prime_part = intel_dp_hdcp_read_v_prime_part,
5244 .toggle_signalling = intel_dp_hdcp_toggle_signalling,
5245 .check_link = intel_dp_hdcp_check_link,
Ramalingam C791a98d2018-02-03 03:39:08 +05305246 .hdcp_capable = intel_dp_hdcp_capable,
Sean Paul20f24d72018-01-08 14:55:43 -05005247};
5248
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005249static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
5250{
Ville Syrjälä2f773472017-11-09 17:27:58 +02005251 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005252
5253 lockdep_assert_held(&dev_priv->pps_mutex);
5254
5255 if (!edp_have_panel_vdd(intel_dp))
5256 return;
5257
5258 /*
5259 * The VDD bit needs a power domain reference, so if the bit is
5260 * already enabled when we boot or resume, grab this reference and
5261 * schedule a vdd off, so we don't hold on to the reference
5262 * indefinitely.
5263 */
5264 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005265 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005266
5267 edp_panel_vdd_schedule_off(intel_dp);
5268}
5269
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005270static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5271{
5272 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5273
5274 if ((intel_dp->DP & DP_PORT_EN) == 0)
5275 return INVALID_PIPE;
5276
5277 if (IS_CHERRYVIEW(dev_priv))
5278 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5279 else
5280 return PORT_TO_PIPE(intel_dp->DP);
5281}
5282
Imre Deakbf93ba62016-04-18 10:04:21 +03005283void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005284{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005285 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005286 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5287 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005288
5289 if (!HAS_DDI(dev_priv))
5290 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005291
Imre Deakdd75f6d2016-11-21 21:15:05 +02005292 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305293 lspcon_resume(lspcon);
5294
Manasi Navared7e8ef02017-02-07 16:54:11 -08005295 intel_dp->reset_link_params = true;
5296
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005297 pps_lock(intel_dp);
5298
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005299 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5300 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5301
Jani Nikula1853a9d2017-08-18 12:30:20 +03005302 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005303 /* Reinit the power sequencer, in case BIOS did something with it. */
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005304 intel_dp_pps_init(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005305 intel_edp_panel_vdd_sanitize(intel_dp);
5306 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005307
5308 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005309}
5310
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005311static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005312 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005313 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005314 .atomic_get_property = intel_digital_connector_atomic_get_property,
5315 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005316 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005317 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005318 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005319 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005320 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005321};
5322
5323static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005324 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005325 .get_modes = intel_dp_get_modes,
5326 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005327 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005328};
5329
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005330static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005331 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005332 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005333};
5334
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005335enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005336intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5337{
5338 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ville Syrjälä2f773472017-11-09 17:27:58 +02005339 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005340 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005341
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005342 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5343 /*
5344 * vdd off can generate a long pulse on eDP which
5345 * would require vdd on to handle it, and thus we
5346 * would end up in an endless cycle of
5347 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5348 */
5349 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005350 port_name(intel_dig_port->base.port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005351 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005352 }
5353
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005354 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005355 port_name(intel_dig_port->base.port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005356 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005357
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005358 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005359 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005360 intel_dp->detect_done = false;
5361 return IRQ_NONE;
5362 }
5363
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005364 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005365
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005366 if (intel_dp->is_mst) {
5367 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5368 /*
5369 * If we were in MST mode, and device is not
5370 * there, get out of MST mode
5371 */
5372 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5373 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5374 intel_dp->is_mst = false;
5375 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5376 intel_dp->is_mst);
5377 intel_dp->detect_done = false;
5378 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005379 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005380 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005381
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005382 if (!intel_dp->is_mst) {
Daniel Vetter42e5e652017-11-13 17:01:40 +01005383 struct drm_modeset_acquire_ctx ctx;
5384 struct drm_connector *connector = &intel_dp->attached_connector->base;
5385 struct drm_crtc *crtc;
5386 int iret;
5387 bool handled = false;
5388
5389 drm_modeset_acquire_init(&ctx, 0);
5390retry:
5391 iret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, &ctx);
5392 if (iret)
5393 goto err;
5394
5395 crtc = connector->state->crtc;
5396 if (crtc) {
5397 iret = drm_modeset_lock(&crtc->mutex, &ctx);
5398 if (iret)
5399 goto err;
5400 }
5401
5402 handled = intel_dp_short_pulse(intel_dp);
5403
5404err:
5405 if (iret == -EDEADLK) {
5406 drm_modeset_backoff(&ctx);
5407 goto retry;
5408 }
5409
5410 drm_modeset_drop_locks(&ctx);
5411 drm_modeset_acquire_fini(&ctx);
5412 WARN(iret, "Acquiring modeset locks failed with %i\n", iret);
5413
Sean Paul20f24d72018-01-08 14:55:43 -05005414 /* Short pulse can signify loss of hdcp authentication */
5415 intel_hdcp_check_link(intel_dp->attached_connector);
5416
Daniel Vetter42e5e652017-11-13 17:01:40 +01005417 if (!handled) {
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005418 intel_dp->detect_done = false;
5419 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305420 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005421 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005422
5423 ret = IRQ_HANDLED;
5424
Imre Deak1c767b32014-08-18 14:42:42 +03005425put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005426 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005427
5428 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005429}
5430
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005431/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005432bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005433{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005434 /*
5435 * eDP not supported on g4x. so bail out early just
5436 * for a bit extra safety in case the VBT is bonkers.
5437 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005438 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005439 return false;
5440
Imre Deaka98d9c12016-12-21 12:17:24 +02005441 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005442 return true;
5443
Jani Nikula951d9ef2016-03-16 12:43:31 +02005444 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005445}
5446
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005447static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005448intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5449{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005450 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Ville Syrjälä68ec0732017-11-29 18:43:02 +02005451 enum port port = dp_to_dig_port(intel_dp)->base.port;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005452
Ville Syrjälä68ec0732017-11-29 18:43:02 +02005453 if (!IS_G4X(dev_priv) && port != PORT_A)
5454 intel_attach_force_audio_property(connector);
5455
Chris Wilsone953fd72011-02-21 22:23:52 +00005456 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005457
Jani Nikula1853a9d2017-08-18 12:30:20 +03005458 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005459 u32 allowed_scalers;
5460
5461 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5462 if (!HAS_GMCH_DISPLAY(dev_priv))
5463 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5464
5465 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5466
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005467 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005468
Yuly Novikov53b41832012-10-26 12:04:00 +03005469 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005470}
5471
Imre Deakdada1a92014-01-29 13:25:41 +02005472static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5473{
Abhay Kumard28d4732016-01-22 17:39:04 -08005474 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005475 intel_dp->last_power_on = jiffies;
5476 intel_dp->last_backlight_off = jiffies;
5477}
5478
Daniel Vetter67a54562012-10-20 20:57:45 +02005479static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005480intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005481{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005482 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305483 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005484 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005485
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005486 intel_pps_get_registers(intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005487
5488 /* Workaround: Need to write PP_CONTROL with the unlock key as
5489 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305490 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005491
Imre Deak8e8232d2016-06-16 16:37:21 +03005492 pp_on = I915_READ(regs.pp_on);
5493 pp_off = I915_READ(regs.pp_off);
Anusha Srivatsab0d6a0f2018-01-11 16:00:07 -02005494 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) &&
5495 !HAS_PCH_ICP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005496 I915_WRITE(regs.pp_ctrl, pp_ctl);
5497 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305498 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005499
5500 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005501 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5502 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005503
Imre Deak54648612016-06-16 16:37:22 +03005504 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5505 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005506
Imre Deak54648612016-06-16 16:37:22 +03005507 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5508 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005509
Imre Deak54648612016-06-16 16:37:22 +03005510 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5511 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005512
Anusha Srivatsab0d6a0f2018-01-11 16:00:07 -02005513 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5514 HAS_PCH_ICP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005515 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5516 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305517 } else {
Imre Deak54648612016-06-16 16:37:22 +03005518 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005519 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305520 }
Imre Deak54648612016-06-16 16:37:22 +03005521}
5522
5523static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005524intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5525{
5526 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5527 state_name,
5528 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5529}
5530
5531static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005532intel_pps_verify_state(struct intel_dp *intel_dp)
Imre Deakde9c1b62016-06-16 20:01:46 +03005533{
5534 struct edp_power_seq hw;
5535 struct edp_power_seq *sw = &intel_dp->pps_delays;
5536
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005537 intel_pps_readout_hw_state(intel_dp, &hw);
Imre Deakde9c1b62016-06-16 20:01:46 +03005538
5539 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5540 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5541 DRM_ERROR("PPS state mismatch\n");
5542 intel_pps_dump_state("sw", sw);
5543 intel_pps_dump_state("hw", &hw);
5544 }
5545}
5546
5547static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005548intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
Imre Deak54648612016-06-16 16:37:22 +03005549{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005550 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak54648612016-06-16 16:37:22 +03005551 struct edp_power_seq cur, vbt, spec,
5552 *final = &intel_dp->pps_delays;
5553
5554 lockdep_assert_held(&dev_priv->pps_mutex);
5555
5556 /* already initialized? */
5557 if (final->t11_t12 != 0)
5558 return;
5559
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005560 intel_pps_readout_hw_state(intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005561
Imre Deakde9c1b62016-06-16 20:01:46 +03005562 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005563
Jani Nikula6aa23e62016-03-24 17:50:20 +02005564 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005565 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5566 * of 500ms appears to be too short. Ocassionally the panel
5567 * just fails to power back on. Increasing the delay to 800ms
5568 * seems sufficient to avoid this problem.
5569 */
5570 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
Manasi Navare7313f5a2017-10-03 16:37:25 -07005571 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
Manasi Navarec99a2592017-06-30 09:33:48 -07005572 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5573 vbt.t11_t12);
5574 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005575 /* T11_T12 delay is special and actually in units of 100ms, but zero
5576 * based in the hw (so we need to add 100 ms). But the sw vbt
5577 * table multiplies it with 1000 to make it in units of 100usec,
5578 * too. */
5579 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005580
5581 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5582 * our hw here, which are all in 100usec. */
5583 spec.t1_t3 = 210 * 10;
5584 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5585 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5586 spec.t10 = 500 * 10;
5587 /* This one is special and actually in units of 100ms, but zero
5588 * based in the hw (so we need to add 100 ms). But the sw vbt
5589 * table multiplies it with 1000 to make it in units of 100usec,
5590 * too. */
5591 spec.t11_t12 = (510 + 100) * 10;
5592
Imre Deakde9c1b62016-06-16 20:01:46 +03005593 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005594
5595 /* Use the max of the register settings and vbt. If both are
5596 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005597#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005598 spec.field : \
5599 max(cur.field, vbt.field))
5600 assign_final(t1_t3);
5601 assign_final(t8);
5602 assign_final(t9);
5603 assign_final(t10);
5604 assign_final(t11_t12);
5605#undef assign_final
5606
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005607#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005608 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5609 intel_dp->backlight_on_delay = get_delay(t8);
5610 intel_dp->backlight_off_delay = get_delay(t9);
5611 intel_dp->panel_power_down_delay = get_delay(t10);
5612 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5613#undef get_delay
5614
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005615 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5616 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5617 intel_dp->panel_power_cycle_delay);
5618
5619 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5620 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005621
5622 /*
5623 * We override the HW backlight delays to 1 because we do manual waits
5624 * on them. For T8, even BSpec recommends doing it. For T9, if we
5625 * don't do this, we'll end up waiting for the backlight off delay
5626 * twice: once when we do the manual sleep, and once when we disable
5627 * the panel and wait for the PP_STATUS bit to become zero.
5628 */
5629 final->t8 = 1;
5630 final->t9 = 1;
Imre Deak56432052017-11-29 19:51:37 +02005631
5632 /*
5633 * HW has only a 100msec granularity for t11_t12 so round it up
5634 * accordingly.
5635 */
5636 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005637}
5638
5639static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005640intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005641 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005642{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005643 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Jesse Barnes453c5422013-03-28 09:55:41 -07005644 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005645 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005646 struct pps_registers regs;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005647 enum port port = dp_to_dig_port(intel_dp)->base.port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005648 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005649
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005650 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005651
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005652 intel_pps_get_registers(intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005653
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005654 /*
5655 * On some VLV machines the BIOS can leave the VDD
5656 * enabled even on power seqeuencers which aren't
5657 * hooked up to any port. This would mess up the
5658 * power domain tracking the first time we pick
5659 * one of these power sequencers for use since
5660 * edp_panel_vdd_on() would notice that the VDD was
5661 * already on and therefore wouldn't grab the power
5662 * domain reference. Disable VDD first to avoid this.
5663 * This also avoids spuriously turning the VDD on as
5664 * soon as the new power seqeuencer gets initialized.
5665 */
5666 if (force_disable_vdd) {
5667 u32 pp = ironlake_get_pp_control(intel_dp);
5668
5669 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5670
5671 if (pp & EDP_FORCE_VDD)
5672 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5673
5674 pp &= ~EDP_FORCE_VDD;
5675
5676 I915_WRITE(regs.pp_ctrl, pp);
5677 }
5678
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005679 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005680 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5681 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005682 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005683 /* Compute the divisor for the pp clock, simply match the Bspec
5684 * formula. */
Anusha Srivatsab0d6a0f2018-01-11 16:00:07 -02005685 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5686 HAS_PCH_ICP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005687 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305688 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005689 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305690 << BXT_POWER_CYCLE_DELAY_SHIFT);
5691 } else {
5692 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5693 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5694 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5695 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005696
5697 /* Haswell doesn't have any port selection bits for the panel
5698 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005699 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005700 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005701 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005702 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005703 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005704 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005705 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005706 }
5707
Jesse Barnes453c5422013-03-28 09:55:41 -07005708 pp_on |= port_sel;
5709
Imre Deak8e8232d2016-06-16 16:37:21 +03005710 I915_WRITE(regs.pp_on, pp_on);
5711 I915_WRITE(regs.pp_off, pp_off);
Anusha Srivatsab0d6a0f2018-01-11 16:00:07 -02005712 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5713 HAS_PCH_ICP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005714 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305715 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005716 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005717
Daniel Vetter67a54562012-10-20 20:57:45 +02005718 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 +03005719 I915_READ(regs.pp_on),
5720 I915_READ(regs.pp_off),
Anusha Srivatsab0d6a0f2018-01-11 16:00:07 -02005721 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5722 HAS_PCH_ICP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005723 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5724 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005725}
5726
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005727static void intel_dp_pps_init(struct intel_dp *intel_dp)
Imre Deak335f7522016-08-10 14:07:32 +03005728{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005729 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005730
5731 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005732 vlv_initial_power_sequencer_setup(intel_dp);
5733 } else {
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005734 intel_dp_init_panel_power_sequencer(intel_dp);
5735 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005736 }
5737}
5738
Vandana Kannanb33a2812015-02-13 15:33:03 +05305739/**
5740 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005741 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005742 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305743 * @refresh_rate: RR to be programmed
5744 *
5745 * This function gets called when refresh rate (RR) has to be changed from
5746 * one frequency to another. Switches can be between high and low RR
5747 * supported by the panel or to any other RR based on media playback (in
5748 * this case, RR value needs to be passed from user space).
5749 *
5750 * The caller of this function needs to take a lock on dev_priv->drrs.
5751 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005752static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005753 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005754 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305755{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305756 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305757 struct intel_digital_port *dig_port = NULL;
5758 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005759 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305760 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305761
5762 if (refresh_rate <= 0) {
5763 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5764 return;
5765 }
5766
Vandana Kannan96178ee2015-01-10 02:25:56 +05305767 if (intel_dp == NULL) {
5768 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305769 return;
5770 }
5771
Vandana Kannan96178ee2015-01-10 02:25:56 +05305772 dig_port = dp_to_dig_port(intel_dp);
5773 encoder = &dig_port->base;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305774
5775 if (!intel_crtc) {
5776 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5777 return;
5778 }
5779
Vandana Kannan96178ee2015-01-10 02:25:56 +05305780 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305781 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5782 return;
5783 }
5784
Vandana Kannan96178ee2015-01-10 02:25:56 +05305785 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5786 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305787 index = DRRS_LOW_RR;
5788
Vandana Kannan96178ee2015-01-10 02:25:56 +05305789 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305790 DRM_DEBUG_KMS(
5791 "DRRS requested for previously set RR...ignoring\n");
5792 return;
5793 }
5794
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005795 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305796 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5797 return;
5798 }
5799
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005800 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305801 switch (index) {
5802 case DRRS_HIGH_RR:
5803 intel_dp_set_m_n(intel_crtc, M1_N1);
5804 break;
5805 case DRRS_LOW_RR:
5806 intel_dp_set_m_n(intel_crtc, M2_N2);
5807 break;
5808 case DRRS_MAX_RR:
5809 default:
5810 DRM_ERROR("Unsupported refreshrate type\n");
5811 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005812 } else if (INTEL_GEN(dev_priv) > 6) {
5813 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005814 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305815
Ville Syrjälä649636e2015-09-22 19:50:01 +03005816 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305817 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005818 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305819 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5820 else
5821 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305822 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005823 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305824 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5825 else
5826 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305827 }
5828 I915_WRITE(reg, val);
5829 }
5830
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305831 dev_priv->drrs.refresh_rate_type = index;
5832
5833 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5834}
5835
Vandana Kannanb33a2812015-02-13 15:33:03 +05305836/**
5837 * intel_edp_drrs_enable - init drrs struct if supported
5838 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005839 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305840 *
5841 * Initializes frontbuffer_bits and drrs.dp
5842 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005843void intel_edp_drrs_enable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005844 const struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305845{
Ville Syrjälä2f773472017-11-09 17:27:58 +02005846 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Vandana Kannanc3955782015-01-22 15:17:40 +05305847
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005848 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305849 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5850 return;
5851 }
5852
Radhakrishna Sripadada83ef82017-09-14 11:16:41 -07005853 if (dev_priv->psr.enabled) {
5854 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5855 return;
5856 }
5857
Vandana Kannanc3955782015-01-22 15:17:40 +05305858 mutex_lock(&dev_priv->drrs.mutex);
5859 if (WARN_ON(dev_priv->drrs.dp)) {
5860 DRM_ERROR("DRRS already enabled\n");
5861 goto unlock;
5862 }
5863
5864 dev_priv->drrs.busy_frontbuffer_bits = 0;
5865
5866 dev_priv->drrs.dp = intel_dp;
5867
5868unlock:
5869 mutex_unlock(&dev_priv->drrs.mutex);
5870}
5871
Vandana Kannanb33a2812015-02-13 15:33:03 +05305872/**
5873 * intel_edp_drrs_disable - Disable DRRS
5874 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005875 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305876 *
5877 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005878void intel_edp_drrs_disable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005879 const struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305880{
Ville Syrjälä2f773472017-11-09 17:27:58 +02005881 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Vandana Kannanc3955782015-01-22 15:17:40 +05305882
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005883 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305884 return;
5885
5886 mutex_lock(&dev_priv->drrs.mutex);
5887 if (!dev_priv->drrs.dp) {
5888 mutex_unlock(&dev_priv->drrs.mutex);
5889 return;
5890 }
5891
5892 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005893 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5894 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305895
5896 dev_priv->drrs.dp = NULL;
5897 mutex_unlock(&dev_priv->drrs.mutex);
5898
5899 cancel_delayed_work_sync(&dev_priv->drrs.work);
5900}
5901
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305902static void intel_edp_drrs_downclock_work(struct work_struct *work)
5903{
5904 struct drm_i915_private *dev_priv =
5905 container_of(work, typeof(*dev_priv), drrs.work.work);
5906 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305907
Vandana Kannan96178ee2015-01-10 02:25:56 +05305908 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305909
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305910 intel_dp = dev_priv->drrs.dp;
5911
5912 if (!intel_dp)
5913 goto unlock;
5914
5915 /*
5916 * The delayed work can race with an invalidate hence we need to
5917 * recheck.
5918 */
5919
5920 if (dev_priv->drrs.busy_frontbuffer_bits)
5921 goto unlock;
5922
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005923 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5924 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5925
5926 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5927 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5928 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305929
5930unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305931 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305932}
5933
Vandana Kannanb33a2812015-02-13 15:33:03 +05305934/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305935 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005936 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305937 * @frontbuffer_bits: frontbuffer plane tracking bits
5938 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305939 * This function gets called everytime rendering on the given planes start.
5940 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305941 *
5942 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5943 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005944void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5945 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305946{
Vandana Kannana93fad02015-01-10 02:25:59 +05305947 struct drm_crtc *crtc;
5948 enum pipe pipe;
5949
Daniel Vetter9da7d692015-04-09 16:44:15 +02005950 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305951 return;
5952
Daniel Vetter88f933a2015-04-09 16:44:16 +02005953 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305954
Vandana Kannana93fad02015-01-10 02:25:59 +05305955 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005956 if (!dev_priv->drrs.dp) {
5957 mutex_unlock(&dev_priv->drrs.mutex);
5958 return;
5959 }
5960
Vandana Kannana93fad02015-01-10 02:25:59 +05305961 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5962 pipe = to_intel_crtc(crtc)->pipe;
5963
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005964 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5965 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5966
Ramalingam C0ddfd202015-06-15 20:50:05 +05305967 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005968 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005969 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5970 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305971
Vandana Kannana93fad02015-01-10 02:25:59 +05305972 mutex_unlock(&dev_priv->drrs.mutex);
5973}
5974
Vandana Kannanb33a2812015-02-13 15:33:03 +05305975/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305976 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005977 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305978 * @frontbuffer_bits: frontbuffer plane tracking bits
5979 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305980 * This function gets called every time rendering on the given planes has
5981 * completed or flip on a crtc is completed. So DRRS should be upclocked
5982 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5983 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305984 *
5985 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5986 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005987void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5988 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305989{
Vandana Kannana93fad02015-01-10 02:25:59 +05305990 struct drm_crtc *crtc;
5991 enum pipe pipe;
5992
Daniel Vetter9da7d692015-04-09 16:44:15 +02005993 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305994 return;
5995
Daniel Vetter88f933a2015-04-09 16:44:16 +02005996 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305997
Vandana Kannana93fad02015-01-10 02:25:59 +05305998 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005999 if (!dev_priv->drrs.dp) {
6000 mutex_unlock(&dev_priv->drrs.mutex);
6001 return;
6002 }
6003
Vandana Kannana93fad02015-01-10 02:25:59 +05306004 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
6005 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02006006
6007 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05306008 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
6009
Ramalingam C0ddfd202015-06-15 20:50:05 +05306010 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02006011 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02006012 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
6013 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05306014
6015 /*
6016 * flush also means no more activity hence schedule downclock, if all
6017 * other fbs are quiescent too
6018 */
6019 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05306020 schedule_delayed_work(&dev_priv->drrs.work,
6021 msecs_to_jiffies(1000));
6022 mutex_unlock(&dev_priv->drrs.mutex);
6023}
6024
Vandana Kannanb33a2812015-02-13 15:33:03 +05306025/**
6026 * DOC: Display Refresh Rate Switching (DRRS)
6027 *
6028 * Display Refresh Rate Switching (DRRS) is a power conservation feature
6029 * which enables swtching between low and high refresh rates,
6030 * dynamically, based on the usage scenario. This feature is applicable
6031 * for internal panels.
6032 *
6033 * Indication that the panel supports DRRS is given by the panel EDID, which
6034 * would list multiple refresh rates for one resolution.
6035 *
6036 * DRRS is of 2 types - static and seamless.
6037 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
6038 * (may appear as a blink on screen) and is used in dock-undock scenario.
6039 * Seamless DRRS involves changing RR without any visual effect to the user
6040 * and can be used during normal system usage. This is done by programming
6041 * certain registers.
6042 *
6043 * Support for static/seamless DRRS may be indicated in the VBT based on
6044 * inputs from the panel spec.
6045 *
6046 * DRRS saves power by switching to low RR based on usage scenarios.
6047 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02006048 * The implementation is based on frontbuffer tracking implementation. When
6049 * there is a disturbance on the screen triggered by user activity or a periodic
6050 * system activity, DRRS is disabled (RR is changed to high RR). When there is
6051 * no movement on screen, after a timeout of 1 second, a switch to low RR is
6052 * made.
6053 *
6054 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
6055 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05306056 *
6057 * DRRS can be further extended to support other internal panels and also
6058 * the scenario of video playback wherein RR is set based on the rate
6059 * requested by userspace.
6060 */
6061
6062/**
6063 * intel_dp_drrs_init - Init basic DRRS work and mutex.
Ville Syrjälä2f773472017-11-09 17:27:58 +02006064 * @connector: eDP connector
Vandana Kannanb33a2812015-02-13 15:33:03 +05306065 * @fixed_mode: preferred mode of panel
6066 *
6067 * This function is called only once at driver load to initialize basic
6068 * DRRS stuff.
6069 *
6070 * Returns:
6071 * Downclock mode if panel supports it, else return NULL.
6072 * DRRS support is determined by the presence of downclock mode (apart
6073 * from VBT setting).
6074 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306075static struct drm_display_mode *
Ville Syrjälä2f773472017-11-09 17:27:58 +02006076intel_dp_drrs_init(struct intel_connector *connector,
6077 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306078{
Ville Syrjälä2f773472017-11-09 17:27:58 +02006079 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306080 struct drm_display_mode *downclock_mode = NULL;
6081
Daniel Vetter9da7d692015-04-09 16:44:15 +02006082 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
6083 mutex_init(&dev_priv->drrs.mutex);
6084
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006085 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306086 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
6087 return NULL;
6088 }
6089
6090 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01006091 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306092 return NULL;
6093 }
6094
Ville Syrjälä2f773472017-11-09 17:27:58 +02006095 downclock_mode = intel_find_panel_downclock(dev_priv, fixed_mode,
6096 &connector->base);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306097
6098 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05306099 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306100 return NULL;
6101 }
6102
Vandana Kannan96178ee2015-01-10 02:25:56 +05306103 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05306104
Vandana Kannan96178ee2015-01-10 02:25:56 +05306105 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01006106 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306107 return downclock_mode;
6108}
6109
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006110static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006111 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006112{
Ville Syrjälä2f773472017-11-09 17:27:58 +02006113 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01006114 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2f773472017-11-09 17:27:58 +02006115 struct drm_connector *connector = &intel_connector->base;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006116 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07006117 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306118 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006119 bool has_dpcd;
6120 struct drm_display_mode *scan;
6121 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02006122 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006123
Jani Nikula1853a9d2017-08-18 12:30:20 +03006124 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006125 return true;
6126
Imre Deak97a824e12016-06-21 11:51:47 +03006127 /*
6128 * On IBX/CPT we may get here with LVDS already registered. Since the
6129 * driver uses the only internal power sequencer available for both
6130 * eDP and LVDS bail out early in this case to prevent interfering
6131 * with an already powered-on LVDS power sequencer.
6132 */
Ville Syrjälä2f773472017-11-09 17:27:58 +02006133 if (intel_get_lvds_encoder(&dev_priv->drm)) {
Imre Deak97a824e12016-06-21 11:51:47 +03006134 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
6135 DRM_INFO("LVDS was detected, not registering eDP\n");
6136
6137 return false;
6138 }
6139
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02006140 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03006141
6142 intel_dp_init_panel_power_timestamps(intel_dp);
Ville Syrjälä46bd8382017-10-31 22:51:22 +02006143 intel_dp_pps_init(intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02006144 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03006145
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02006146 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03006147
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006148 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03006149 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006150
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03006151 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006152 /* if this fails, presume the device is a ghost */
6153 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03006154 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006155 }
6156
Daniel Vetter060c8772014-03-21 23:22:35 +01006157 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02006158 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006159 if (edid) {
6160 if (drm_add_edid_modes(connector, edid)) {
6161 drm_mode_connector_update_edid_property(connector,
6162 edid);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006163 } else {
6164 kfree(edid);
6165 edid = ERR_PTR(-EINVAL);
6166 }
6167 } else {
6168 edid = ERR_PTR(-ENOENT);
6169 }
6170 intel_connector->edid = edid;
6171
Jim Bridedc911f52017-08-09 12:48:53 -07006172 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006173 list_for_each_entry(scan, &connector->probed_modes, head) {
6174 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
6175 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306176 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05306177 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07006178 } else if (!alt_fixed_mode) {
6179 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006180 }
6181 }
6182
6183 /* fallback to VBT if available for eDP */
6184 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
6185 fixed_mode = drm_mode_duplicate(dev,
6186 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03006187 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006188 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03006189 connector->display_info.width_mm = fixed_mode->width_mm;
6190 connector->display_info.height_mm = fixed_mode->height_mm;
6191 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006192 }
Daniel Vetter060c8772014-03-21 23:22:35 +01006193 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006194
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006195 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07006196 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
6197 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02006198
6199 /*
6200 * Figure out the current pipe for the initial backlight setup.
6201 * If the current pipe isn't valid, try the PPS pipe, and if that
6202 * fails just assume pipe A.
6203 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006204 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02006205
6206 if (pipe != PIPE_A && pipe != PIPE_B)
6207 pipe = intel_dp->pps_pipe;
6208
6209 if (pipe != PIPE_A && pipe != PIPE_B)
6210 pipe = PIPE_A;
6211
6212 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
6213 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07006214 }
6215
Jim Bridedc911f52017-08-09 12:48:53 -07006216 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
6217 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03006218 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02006219 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006220
6221 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03006222
6223out_vdd_off:
6224 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
6225 /*
6226 * vdd might still be enabled do to the delayed vdd off.
6227 * Make sure vdd is actually turned off here.
6228 */
6229 pps_lock(intel_dp);
6230 edp_panel_vdd_off_sync(intel_dp);
6231 pps_unlock(intel_dp);
6232
6233 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03006234}
6235
Manasi Navare93013972017-04-06 16:44:19 +03006236static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
6237{
6238 struct intel_connector *intel_connector;
6239 struct drm_connector *connector;
6240
6241 intel_connector = container_of(work, typeof(*intel_connector),
6242 modeset_retry_work);
6243 connector = &intel_connector->base;
6244 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
6245 connector->name);
6246
6247 /* Grab the locks before changing connector property*/
6248 mutex_lock(&connector->dev->mode_config.mutex);
6249 /* Set connector link status to BAD and send a Uevent to notify
6250 * userspace to do a modeset.
6251 */
6252 drm_mode_connector_set_link_status_property(connector,
6253 DRM_MODE_LINK_STATUS_BAD);
6254 mutex_unlock(&connector->dev->mode_config.mutex);
6255 /* Send Hotplug uevent so userspace can reprobe */
6256 drm_kms_helper_hotplug_event(connector->dev);
6257}
6258
Paulo Zanoni16c25532013-06-12 17:27:25 -03006259bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006260intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6261 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006262{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006263 struct drm_connector *connector = &intel_connector->base;
6264 struct intel_dp *intel_dp = &intel_dig_port->dp;
6265 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6266 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006267 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02006268 enum port port = intel_encoder->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006269 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006270
Manasi Navare93013972017-04-06 16:44:19 +03006271 /* Initialize the work for modeset in case of link train failure */
6272 INIT_WORK(&intel_connector->modeset_retry_work,
6273 intel_dp_modeset_retry_work_fn);
6274
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006275 if (WARN(intel_dig_port->max_lanes < 1,
6276 "Not enough lanes (%d) for DP on port %c\n",
6277 intel_dig_port->max_lanes, port_name(port)))
6278 return false;
6279
Jani Nikula55cfc582017-03-28 17:59:04 +03006280 intel_dp_set_source_rates(intel_dp);
6281
Manasi Navared7e8ef02017-02-07 16:54:11 -08006282 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006283 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006284 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006285
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006286 /* intel_dp vfuncs */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006287 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006288 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6289
Daniel Vetter07679352012-09-06 22:15:42 +02006290 /* Preserve the current hw state. */
6291 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006292 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006293
Jani Nikula7b91bf72017-08-18 12:30:19 +03006294 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306295 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006296 else
6297 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006298
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006299 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6300 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6301
Imre Deakf7d24902013-05-08 13:14:05 +03006302 /*
6303 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6304 * for DP the encoder type can be set by the caller to
6305 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6306 */
6307 if (type == DRM_MODE_CONNECTOR_eDP)
6308 intel_encoder->type = INTEL_OUTPUT_EDP;
6309
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006310 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006311 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006312 intel_dp_is_edp(intel_dp) &&
6313 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006314 return false;
6315
Imre Deake7281ea2013-05-08 13:14:08 +03006316 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6317 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6318 port_name(port));
6319
Adam Jacksonb3295302010-07-16 14:46:28 -04006320 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006321 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6322
Ville Syrjälä050213892017-11-29 20:08:47 +02006323 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
6324 connector->interlace_allowed = true;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006325 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006326
Ville Syrjäläbdabdb62018-02-22 20:10:30 +02006327 intel_encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006328
Mika Kaholab6339582016-09-09 14:10:52 +03006329 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006330
Daniel Vetter66a92782012-07-12 20:08:18 +02006331 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006332 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006333
Chris Wilsondf0e9242010-09-09 16:20:55 +01006334 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006335
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006336 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006337 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6338 else
6339 intel_connector->get_hw_state = intel_connector_get_hw_state;
6340
Dave Airlie0e32b392014-05-02 14:02:48 +10006341 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006342 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Rodrigo Vivi9787e832018-01-29 15:22:22 -08006343 (port == PORT_B || port == PORT_C ||
6344 port == PORT_D || port == PORT_F))
Jani Nikula0c9b3712015-05-18 17:10:01 +03006345 intel_dp_mst_encoder_init(intel_dig_port,
6346 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006347
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006348 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006349 intel_dp_aux_fini(intel_dp);
6350 intel_dp_mst_encoder_cleanup(intel_dig_port);
6351 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006352 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006353
Chris Wilsonf6849602010-09-19 09:29:33 +01006354 intel_dp_add_properties(intel_dp, connector);
6355
Ramalingam Cfdddd082018-01-18 11:18:05 +05306356 if (is_hdcp_supported(dev_priv, port) && !intel_dp_is_edp(intel_dp)) {
Sean Paul20f24d72018-01-08 14:55:43 -05006357 int ret = intel_hdcp_init(intel_connector, &intel_dp_hdcp_shim);
6358 if (ret)
6359 DRM_DEBUG_KMS("HDCP init failed, skipping.\n");
6360 }
6361
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006362 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6363 * 0xd. Failure to do so will result in spurious interrupts being
6364 * generated on the port when a cable is not attached.
6365 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006366 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006367 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6368 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6369 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006370
6371 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006372
6373fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006374 drm_connector_cleanup(connector);
6375
6376 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006377}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006378
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006379bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006380 i915_reg_t output_reg,
6381 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006382{
6383 struct intel_digital_port *intel_dig_port;
6384 struct intel_encoder *intel_encoder;
6385 struct drm_encoder *encoder;
6386 struct intel_connector *intel_connector;
6387
Daniel Vetterb14c5672013-09-19 12:18:32 +02006388 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006389 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006390 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006391
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006392 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306393 if (!intel_connector)
6394 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006395
6396 intel_encoder = &intel_dig_port->base;
6397 encoder = &intel_encoder->base;
6398
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006399 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6400 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6401 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306402 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006403
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006404 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006405 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006406 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006407 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006408 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006409 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006410 intel_encoder->pre_enable = chv_pre_enable_dp;
6411 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006412 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006413 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006414 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006415 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006416 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006417 intel_encoder->pre_enable = vlv_pre_enable_dp;
6418 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006419 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006420 intel_encoder->post_disable = vlv_post_disable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006421 } else if (INTEL_GEN(dev_priv) >= 5) {
6422 intel_encoder->pre_enable = g4x_pre_enable_dp;
6423 intel_encoder->enable = g4x_enable_dp;
6424 intel_encoder->disable = ilk_disable_dp;
6425 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006426 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006427 intel_encoder->pre_enable = g4x_pre_enable_dp;
6428 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006429 intel_encoder->disable = g4x_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006430 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006431
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006432 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006433 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006434
Ville Syrjäläcca05022016-06-22 21:57:06 +03006435 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006436 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006437 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006438 if (port == PORT_D)
6439 intel_encoder->crtc_mask = 1 << 2;
6440 else
6441 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6442 } else {
6443 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6444 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006445 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006446 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006447
Dave Airlie13cf5502014-06-18 11:29:35 +10006448 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006449 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006450
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006451 if (port != PORT_A)
6452 intel_infoframe_init(intel_dig_port);
6453
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306454 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6455 goto err_init_connector;
6456
Chris Wilson457c52d2016-06-01 08:27:50 +01006457 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306458
6459err_init_connector:
6460 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306461err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306462 kfree(intel_connector);
6463err_connector_alloc:
6464 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006465 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006466}
Dave Airlie0e32b392014-05-02 14:02:48 +10006467
6468void intel_dp_mst_suspend(struct drm_device *dev)
6469{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006470 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006471 int i;
6472
6473 /* disable MST */
6474 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006475 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006476
6477 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006478 continue;
6479
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006480 if (intel_dig_port->dp.is_mst)
6481 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006482 }
6483}
6484
6485void intel_dp_mst_resume(struct drm_device *dev)
6486{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006487 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006488 int i;
6489
6490 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006491 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006492 int ret;
6493
6494 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006495 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006496
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006497 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6498 if (ret)
6499 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006500 }
6501}