blob: 30688a5d680db509ff618f02759e6eac3cca489a [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>
39#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070043
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -070045#define DP_DPRX_ESI_LEN 14
Keith Packarda4fc5ed2009-04-07 16:16:42 -070046
Todd Previte559be302015-05-04 07:48:20 -070047/* Compliance test status bits */
48#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
49#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
52
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080053struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030054 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080055 struct dpll dpll;
56};
57
58static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030059 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080060 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030061 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080062 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
63};
64
65static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030066 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080067 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030068 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080069 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
70};
71
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080072static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030073 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080074 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030075 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080076 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
77};
78
Chon Ming Leeef9348c2014-04-09 13:28:18 +030079/*
80 * CHV supports eDP 1.4 that have more link rates.
81 * Below only provides the fixed rate but exclude variable rate.
82 */
83static const struct dp_link_dpll chv_dpll[] = {
84 /*
85 * CHV requires to program fractional division for m2.
86 * m2 is stored in fixed point format using formula below
87 * (m2_int << 22) | m2_fraction
88 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030089 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030090 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030091 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030092 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030093 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030094 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
95};
Sonika Jindal637a9c62015-05-07 09:52:08 +053096
Sonika Jindal64987fc2015-05-26 17:50:13 +053097static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
98 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053099static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +0200100 324000, 432000, 540000 };
Rodrigo Vivid907b662017-08-10 15:40:08 -0700101static const int cnl_rates[] = { 162000, 216000, 270000,
102 324000, 432000, 540000,
103 648000, 810000 };
Ville Syrjäläf4896f12015-03-12 17:10:27 +0200104static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300105
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700106/**
Jani Nikula1853a9d2017-08-18 12:30:20 +0300107 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700108 * @intel_dp: DP struct
109 *
110 * If a CPU or PCH DP output is attached to an eDP panel, this function
111 * will return true, and false otherwise.
112 */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300113bool intel_dp_is_edp(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200115 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
116
117 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700118}
119
Imre Deak68b4d822013-05-08 13:14:06 +0300120static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121{
Imre Deak68b4d822013-05-08 13:14:06 +0300122 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
123
124 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700125}
126
Chris Wilsondf0e9242010-09-09 16:20:55 +0100127static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
128{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200129 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100130}
131
Chris Wilsonea5b2132010-08-04 13:50:23 +0100132static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300133static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100134static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300135static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300136static void vlv_steal_power_sequencer(struct drm_device *dev,
137 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530138static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700139
Jani Nikula68f357c2017-03-28 17:59:05 +0300140/* update sink rates from dpcd */
141static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
142{
Jani Nikulaa8a08882017-10-09 12:29:59 +0300143 int i, max_rate;
Jani Nikula68f357c2017-03-28 17:59:05 +0300144
Jani Nikulaa8a08882017-10-09 12:29:59 +0300145 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
Jani Nikula68f357c2017-03-28 17:59:05 +0300146
Jani Nikulaa8a08882017-10-09 12:29:59 +0300147 for (i = 0; i < ARRAY_SIZE(default_rates); i++) {
148 if (default_rates[i] > max_rate)
149 break;
Jani Nikula68f357c2017-03-28 17:59:05 +0300150 intel_dp->sink_rates[i] = default_rates[i];
Jani Nikulaa8a08882017-10-09 12:29:59 +0300151 }
Jani Nikula68f357c2017-03-28 17:59:05 +0300152
Jani Nikulaa8a08882017-10-09 12:29:59 +0300153 intel_dp->num_sink_rates = i;
Jani Nikula68f357c2017-03-28 17:59:05 +0300154}
155
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300156/* Theoretical max between source and sink */
157static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700158{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300159 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700160}
161
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300162/* Theoretical max between source and sink */
163static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300164{
165 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300166 int source_max = intel_dig_port->max_lanes;
167 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300168
169 return min(source_max, sink_max);
170}
171
Jani Nikula3d65a732017-04-06 16:44:14 +0300172int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300173{
174 return intel_dp->max_link_lane_count;
175}
176
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800177int
Keith Packardc8982612012-01-25 08:16:25 -0800178intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700179{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800180 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
181 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700182}
183
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800184int
Dave Airliefe27d532010-06-30 11:46:17 +1000185intel_dp_max_data_rate(int max_link_clock, int max_lanes)
186{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800187 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
188 * link rate that is generally expressed in Gbps. Since, 8 bits of data
189 * is transmitted every LS_Clk per lane, there is no need to account for
190 * the channel encoding that is done in the PHY layer here.
191 */
192
193 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000194}
195
Mika Kahola70ec0642016-09-09 14:10:55 +0300196static int
197intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
198{
199 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
200 struct intel_encoder *encoder = &intel_dig_port->base;
201 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
202 int max_dotclk = dev_priv->max_dotclk_freq;
203 int ds_max_dotclk;
204
205 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
206
207 if (type != DP_DS_PORT_TYPE_VGA)
208 return max_dotclk;
209
210 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
211 intel_dp->downstream_ports);
212
213 if (ds_max_dotclk != 0)
214 max_dotclk = min(max_dotclk, ds_max_dotclk);
215
216 return max_dotclk;
217}
218
Jani Nikula55cfc582017-03-28 17:59:04 +0300219static void
220intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700221{
222 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
223 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700224 enum port port = dig_port->port;
Jani Nikula55cfc582017-03-28 17:59:04 +0300225 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700226 int size;
Rodrigo Vivid907b662017-08-10 15:40:08 -0700227 u32 voltage;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700228
Jani Nikula55cfc582017-03-28 17:59:04 +0300229 /* This should only be done once */
230 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
231
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200232 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300233 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700234 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700235 } else if (IS_CANNONLAKE(dev_priv)) {
236 source_rates = cnl_rates;
237 size = ARRAY_SIZE(cnl_rates);
238 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
239 if (port == PORT_A || port == PORT_D ||
240 voltage == VOLTAGE_INFO_0_85V)
241 size -= 2;
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800242 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300243 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700244 size = ARRAY_SIZE(skl_rates);
Jani Nikulafc603ca2017-10-09 12:29:58 +0300245 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
246 IS_BROADWELL(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300247 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700248 size = ARRAY_SIZE(default_rates);
Jani Nikulafc603ca2017-10-09 12:29:58 +0300249 } else {
250 source_rates = default_rates;
251 size = ARRAY_SIZE(default_rates) - 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700252 }
253
Jani Nikula55cfc582017-03-28 17:59:04 +0300254 intel_dp->source_rates = source_rates;
255 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700256}
257
258static int intersect_rates(const int *source_rates, int source_len,
259 const int *sink_rates, int sink_len,
260 int *common_rates)
261{
262 int i = 0, j = 0, k = 0;
263
264 while (i < source_len && j < sink_len) {
265 if (source_rates[i] == sink_rates[j]) {
266 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
267 return k;
268 common_rates[k] = source_rates[i];
269 ++k;
270 ++i;
271 ++j;
272 } else if (source_rates[i] < sink_rates[j]) {
273 ++i;
274 } else {
275 ++j;
276 }
277 }
278 return k;
279}
280
Jani Nikula8001b752017-03-28 17:59:03 +0300281/* return index of rate in rates array, or -1 if not found */
282static int intel_dp_rate_index(const int *rates, int len, int rate)
283{
284 int i;
285
286 for (i = 0; i < len; i++)
287 if (rate == rates[i])
288 return i;
289
290 return -1;
291}
292
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300293static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700294{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300295 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700296
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300297 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
298 intel_dp->num_source_rates,
299 intel_dp->sink_rates,
300 intel_dp->num_sink_rates,
301 intel_dp->common_rates);
302
303 /* Paranoia, there should always be something in common. */
304 if (WARN_ON(intel_dp->num_common_rates == 0)) {
305 intel_dp->common_rates[0] = default_rates[0];
306 intel_dp->num_common_rates = 1;
307 }
308}
309
310/* get length of common rates potentially limited by max_rate */
311static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
312 int max_rate)
313{
314 const int *common_rates = intel_dp->common_rates;
315 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700316
Jani Nikula68f357c2017-03-28 17:59:05 +0300317 /* Limit results by potentially reduced max rate */
318 for (i = 0; i < common_len; i++) {
319 if (common_rates[common_len - i - 1] <= max_rate)
320 return common_len - i;
321 }
322
323 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700324}
325
Manasi Navare1a92c702017-06-08 13:41:02 -0700326static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
327 uint8_t lane_count)
Manasi Navare14c562c2017-04-06 14:00:12 -0700328{
329 /*
330 * FIXME: we need to synchronize the current link parameters with
331 * hardware readout. Currently fast link training doesn't work on
332 * boot-up.
333 */
Manasi Navare1a92c702017-06-08 13:41:02 -0700334 if (link_rate == 0 ||
335 link_rate > intel_dp->max_link_rate)
Manasi Navare14c562c2017-04-06 14:00:12 -0700336 return false;
337
Manasi Navare1a92c702017-06-08 13:41:02 -0700338 if (lane_count == 0 ||
339 lane_count > intel_dp_max_lane_count(intel_dp))
Manasi Navare14c562c2017-04-06 14:00:12 -0700340 return false;
341
342 return true;
343}
344
Manasi Navarefdb14d32016-12-08 19:05:12 -0800345int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
346 int link_rate, uint8_t lane_count)
347{
Jani Nikulab1810a72017-04-06 16:44:11 +0300348 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800349
Jani Nikulab1810a72017-04-06 16:44:11 +0300350 index = intel_dp_rate_index(intel_dp->common_rates,
351 intel_dp->num_common_rates,
352 link_rate);
353 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300354 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
355 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800356 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300357 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300358 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800359 } else {
360 DRM_ERROR("Link Training Unsuccessful\n");
361 return -1;
362 }
363
364 return 0;
365}
366
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000367static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700368intel_dp_mode_valid(struct drm_connector *connector,
369 struct drm_display_mode *mode)
370{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100371 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300372 struct intel_connector *intel_connector = to_intel_connector(connector);
373 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100374 int target_clock = mode->clock;
375 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300376 int max_dotclk;
377
378 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700379
Jani Nikula1853a9d2017-08-18 12:30:20 +0300380 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
Jani Nikuladd06f902012-10-19 14:51:50 +0300381 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100382 return MODE_PANEL;
383
Jani Nikuladd06f902012-10-19 14:51:50 +0300384 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100385 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200386
387 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100388 }
389
Ville Syrjälä50fec212015-03-12 17:10:34 +0200390 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300391 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100392
393 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
394 mode_rate = intel_dp_link_required(target_clock, 18);
395
Mika Kahola799487f2016-02-02 15:16:38 +0200396 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200397 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700398
399 if (mode->clock < 10000)
400 return MODE_CLOCK_LOW;
401
Daniel Vetter0af78a22012-05-23 11:30:55 +0200402 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
403 return MODE_H_ILLEGAL;
404
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700405 return MODE_OK;
406}
407
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800408uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700409{
410 int i;
411 uint32_t v = 0;
412
413 if (src_bytes > 4)
414 src_bytes = 4;
415 for (i = 0; i < src_bytes; i++)
416 v |= ((uint32_t) src[i]) << ((3-i) * 8);
417 return v;
418}
419
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000420static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700421{
422 int i;
423 if (dst_bytes > 4)
424 dst_bytes = 4;
425 for (i = 0; i < dst_bytes; i++)
426 dst[i] = src >> ((3-i) * 8);
427}
428
Jani Nikulabf13e812013-09-06 07:40:05 +0300429static void
430intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300431 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300432static void
433intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200434 struct intel_dp *intel_dp,
435 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300436static void
437intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300438
Ville Syrjälä773538e82014-09-04 14:54:56 +0300439static void pps_lock(struct intel_dp *intel_dp)
440{
441 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
442 struct intel_encoder *encoder = &intel_dig_port->base;
443 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100444 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300445
446 /*
447 * See vlv_power_sequencer_reset() why we need
448 * a power domain reference here.
449 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200450 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300451
452 mutex_lock(&dev_priv->pps_mutex);
453}
454
455static void pps_unlock(struct intel_dp *intel_dp)
456{
457 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
458 struct intel_encoder *encoder = &intel_dig_port->base;
459 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100460 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300461
462 mutex_unlock(&dev_priv->pps_mutex);
463
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200464 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300465}
466
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300467static void
468vlv_power_sequencer_kick(struct intel_dp *intel_dp)
469{
470 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200471 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300472 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300473 bool pll_enabled, release_cl_override = false;
474 enum dpio_phy phy = DPIO_PHY(pipe);
475 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300476 uint32_t DP;
477
478 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
479 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
480 pipe_name(pipe), port_name(intel_dig_port->port)))
481 return;
482
483 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
484 pipe_name(pipe), port_name(intel_dig_port->port));
485
486 /* Preserve the BIOS-computed detected bit. This is
487 * supposed to be read-only.
488 */
489 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
490 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
491 DP |= DP_PORT_WIDTH(1);
492 DP |= DP_LINK_TRAIN_PAT_1;
493
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100494 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300495 DP |= DP_PIPE_SELECT_CHV(pipe);
496 else if (pipe == PIPE_B)
497 DP |= DP_PIPEB_SELECT;
498
Ville Syrjäläd288f652014-10-28 13:20:22 +0200499 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
500
501 /*
502 * The DPLL for the pipe must be enabled for this to work.
503 * So enable temporarily it if it's not already enabled.
504 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300505 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100506 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300507 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
508
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200509 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000510 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
511 DRM_ERROR("Failed to force on pll for pipe %c!\n",
512 pipe_name(pipe));
513 return;
514 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300515 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200516
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300517 /*
518 * Similar magic as in intel_dp_enable_port().
519 * We _must_ do this port enable + disable trick
520 * to make this power seqeuencer lock onto the port.
521 * Otherwise even VDD force bit won't work.
522 */
523 I915_WRITE(intel_dp->output_reg, DP);
524 POSTING_READ(intel_dp->output_reg);
525
526 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
527 POSTING_READ(intel_dp->output_reg);
528
529 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
530 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200531
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300532 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200533 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300534
535 if (release_cl_override)
536 chv_phy_powergate_ch(dev_priv, phy, ch, false);
537 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300538}
539
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200540static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
541{
542 struct intel_encoder *encoder;
543 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
544
545 /*
546 * We don't have power sequencer currently.
547 * Pick one that's not used by other ports.
548 */
549 for_each_intel_encoder(&dev_priv->drm, encoder) {
550 struct intel_dp *intel_dp;
551
552 if (encoder->type != INTEL_OUTPUT_DP &&
553 encoder->type != INTEL_OUTPUT_EDP)
554 continue;
555
556 intel_dp = enc_to_intel_dp(&encoder->base);
557
558 if (encoder->type == INTEL_OUTPUT_EDP) {
559 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
560 intel_dp->active_pipe != intel_dp->pps_pipe);
561
562 if (intel_dp->pps_pipe != INVALID_PIPE)
563 pipes &= ~(1 << intel_dp->pps_pipe);
564 } else {
565 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
566
567 if (intel_dp->active_pipe != INVALID_PIPE)
568 pipes &= ~(1 << intel_dp->active_pipe);
569 }
570 }
571
572 if (pipes == 0)
573 return INVALID_PIPE;
574
575 return ffs(pipes) - 1;
576}
577
Jani Nikulabf13e812013-09-06 07:40:05 +0300578static enum pipe
579vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
580{
581 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300582 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100583 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300584 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300585
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300586 lockdep_assert_held(&dev_priv->pps_mutex);
587
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300588 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300589 WARN_ON(!intel_dp_is_edp(intel_dp));
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300590
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200591 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
592 intel_dp->active_pipe != intel_dp->pps_pipe);
593
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300594 if (intel_dp->pps_pipe != INVALID_PIPE)
595 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300596
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200597 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300598
599 /*
600 * Didn't find one. This should not happen since there
601 * are two power sequencers and up to two eDP ports.
602 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200603 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300604 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300605
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300606 vlv_steal_power_sequencer(dev, pipe);
607 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300608
609 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
610 pipe_name(intel_dp->pps_pipe),
611 port_name(intel_dig_port->port));
612
613 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300614 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200615 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300616
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300617 /*
618 * Even vdd force doesn't work until we've made
619 * the power sequencer lock in on the port.
620 */
621 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300622
623 return intel_dp->pps_pipe;
624}
625
Imre Deak78597992016-06-16 16:37:20 +0300626static int
627bxt_power_sequencer_idx(struct intel_dp *intel_dp)
628{
629 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
630 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100631 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300632
633 lockdep_assert_held(&dev_priv->pps_mutex);
634
635 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300636 WARN_ON(!intel_dp_is_edp(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300637
638 /*
639 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
640 * mapping needs to be retrieved from VBT, for now just hard-code to
641 * use instance #0 always.
642 */
643 if (!intel_dp->pps_reset)
644 return 0;
645
646 intel_dp->pps_reset = false;
647
648 /*
649 * Only the HW needs to be reprogrammed, the SW state is fixed and
650 * has been setup during connector init.
651 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200652 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300653
654 return 0;
655}
656
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300657typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
658 enum pipe pipe);
659
660static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
661 enum pipe pipe)
662{
Imre Deak44cb7342016-08-10 14:07:29 +0300663 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300664}
665
666static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
667 enum pipe pipe)
668{
Imre Deak44cb7342016-08-10 14:07:29 +0300669 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300670}
671
672static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
673 enum pipe pipe)
674{
675 return true;
676}
677
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300678static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300679vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
680 enum port port,
681 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300682{
Jani Nikulabf13e812013-09-06 07:40:05 +0300683 enum pipe pipe;
684
Jani Nikulabf13e812013-09-06 07:40:05 +0300685 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300686 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300687 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300688
689 if (port_sel != PANEL_PORT_SELECT_VLV(port))
690 continue;
691
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300692 if (!pipe_check(dev_priv, pipe))
693 continue;
694
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300695 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300696 }
697
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300698 return INVALID_PIPE;
699}
700
701static void
702vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
703{
704 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
705 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100706 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300707 enum port port = intel_dig_port->port;
708
709 lockdep_assert_held(&dev_priv->pps_mutex);
710
711 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300712 /* first pick one where the panel is on */
713 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
714 vlv_pipe_has_pp_on);
715 /* didn't find one? pick one where vdd is on */
716 if (intel_dp->pps_pipe == INVALID_PIPE)
717 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
718 vlv_pipe_has_vdd_on);
719 /* didn't find one? pick one with just the correct port */
720 if (intel_dp->pps_pipe == INVALID_PIPE)
721 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
722 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300723
724 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
725 if (intel_dp->pps_pipe == INVALID_PIPE) {
726 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
727 port_name(port));
728 return;
729 }
730
731 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
732 port_name(port), pipe_name(intel_dp->pps_pipe));
733
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300734 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200735 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300736}
737
Imre Deak78597992016-06-16 16:37:20 +0300738void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300739{
Chris Wilson91c8a322016-07-05 10:40:23 +0100740 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300741 struct intel_encoder *encoder;
742
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100743 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200744 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300745 return;
746
747 /*
748 * We can't grab pps_mutex here due to deadlock with power_domain
749 * mutex when power_domain functions are called while holding pps_mutex.
750 * That also means that in order to use pps_pipe the code needs to
751 * hold both a power domain reference and pps_mutex, and the power domain
752 * reference get/put must be done while _not_ holding pps_mutex.
753 * pps_{lock,unlock}() do these steps in the correct order, so one
754 * should use them always.
755 */
756
Jani Nikula19c80542015-12-16 12:48:16 +0200757 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300758 struct intel_dp *intel_dp;
759
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200760 if (encoder->type != INTEL_OUTPUT_DP &&
761 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300762 continue;
763
764 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200765
766 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
767
768 if (encoder->type != INTEL_OUTPUT_EDP)
769 continue;
770
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200771 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300772 intel_dp->pps_reset = true;
773 else
774 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300775 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300776}
777
Imre Deak8e8232d2016-06-16 16:37:21 +0300778struct pps_registers {
779 i915_reg_t pp_ctrl;
780 i915_reg_t pp_stat;
781 i915_reg_t pp_on;
782 i915_reg_t pp_off;
783 i915_reg_t pp_div;
784};
785
786static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
787 struct intel_dp *intel_dp,
788 struct pps_registers *regs)
789{
Imre Deak44cb7342016-08-10 14:07:29 +0300790 int pps_idx = 0;
791
Imre Deak8e8232d2016-06-16 16:37:21 +0300792 memset(regs, 0, sizeof(*regs));
793
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200794 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300795 pps_idx = bxt_power_sequencer_idx(intel_dp);
796 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
797 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300798
Imre Deak44cb7342016-08-10 14:07:29 +0300799 regs->pp_ctrl = PP_CONTROL(pps_idx);
800 regs->pp_stat = PP_STATUS(pps_idx);
801 regs->pp_on = PP_ON_DELAYS(pps_idx);
802 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700803 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300804 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300805}
806
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200807static i915_reg_t
808_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300809{
Imre Deak8e8232d2016-06-16 16:37:21 +0300810 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300811
Imre Deak8e8232d2016-06-16 16:37:21 +0300812 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
813 &regs);
814
815 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300816}
817
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200818static i915_reg_t
819_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300820{
Imre Deak8e8232d2016-06-16 16:37:21 +0300821 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300822
Imre Deak8e8232d2016-06-16 16:37:21 +0300823 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
824 &regs);
825
826 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300827}
828
Clint Taylor01527b32014-07-07 13:01:46 -0700829/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
830 This function only applicable when panel PM state is not to be tracked */
831static int edp_notify_handler(struct notifier_block *this, unsigned long code,
832 void *unused)
833{
834 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
835 edp_notifier);
836 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100837 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700838
Jani Nikula1853a9d2017-08-18 12:30:20 +0300839 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
Clint Taylor01527b32014-07-07 13:01:46 -0700840 return 0;
841
Ville Syrjälä773538e82014-09-04 14:54:56 +0300842 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300843
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100844 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300845 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200846 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300847 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300848
Imre Deak44cb7342016-08-10 14:07:29 +0300849 pp_ctrl_reg = PP_CONTROL(pipe);
850 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700851 pp_div = I915_READ(pp_div_reg);
852 pp_div &= PP_REFERENCE_DIVIDER_MASK;
853
854 /* 0x1F write to PP_DIV_REG sets max cycle delay */
855 I915_WRITE(pp_div_reg, pp_div | 0x1F);
856 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
857 msleep(intel_dp->panel_power_cycle_delay);
858 }
859
Ville Syrjälä773538e82014-09-04 14:54:56 +0300860 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300861
Clint Taylor01527b32014-07-07 13:01:46 -0700862 return 0;
863}
864
Daniel Vetter4be73782014-01-17 14:39:48 +0100865static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700866{
Paulo Zanoni30add222012-10-26 19:05:45 -0200867 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100868 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700869
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300870 lockdep_assert_held(&dev_priv->pps_mutex);
871
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100872 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300873 intel_dp->pps_pipe == INVALID_PIPE)
874 return false;
875
Jani Nikulabf13e812013-09-06 07:40:05 +0300876 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700877}
878
Daniel Vetter4be73782014-01-17 14:39:48 +0100879static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700880{
Paulo Zanoni30add222012-10-26 19:05:45 -0200881 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100882 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700883
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300884 lockdep_assert_held(&dev_priv->pps_mutex);
885
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100886 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300887 intel_dp->pps_pipe == INVALID_PIPE)
888 return false;
889
Ville Syrjälä773538e82014-09-04 14:54:56 +0300890 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700891}
892
Keith Packard9b984da2011-09-19 13:54:47 -0700893static void
894intel_dp_check_edp(struct intel_dp *intel_dp)
895{
Paulo Zanoni30add222012-10-26 19:05:45 -0200896 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100897 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700898
Jani Nikula1853a9d2017-08-18 12:30:20 +0300899 if (!intel_dp_is_edp(intel_dp))
Keith Packard9b984da2011-09-19 13:54:47 -0700900 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700901
Daniel Vetter4be73782014-01-17 14:39:48 +0100902 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700903 WARN(1, "eDP powered off while attempting aux channel communication.\n");
904 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300905 I915_READ(_pp_stat_reg(intel_dp)),
906 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700907 }
908}
909
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100910static uint32_t
911intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
912{
913 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
914 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100915 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200916 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100917 uint32_t status;
918 bool done;
919
Daniel Vetteref04f002012-12-01 21:03:59 +0100920#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100921 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300922 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300923 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100924 else
Imre Deak713a6b662016-06-28 13:37:33 +0300925 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100926 if (!done)
927 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
928 has_aux_irq);
929#undef C
930
931 return status;
932}
933
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200934static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000935{
936 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200937 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000938
Ville Syrjäläa457f542016-03-02 17:22:17 +0200939 if (index)
940 return 0;
941
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000942 /*
943 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200944 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000945 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200946 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000947}
948
949static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
950{
951 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200952 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000953
954 if (index)
955 return 0;
956
Ville Syrjäläa457f542016-03-02 17:22:17 +0200957 /*
958 * The clock divider is based off the cdclk or PCH rawclk, and would
959 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
960 * divide by 2000 and use that
961 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200962 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200963 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200964 else
965 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000966}
967
968static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300969{
970 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200971 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300972
Ville Syrjäläa457f542016-03-02 17:22:17 +0200973 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300974 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100975 switch (index) {
976 case 0: return 63;
977 case 1: return 72;
978 default: return 0;
979 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300980 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200981
982 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300983}
984
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000985static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
986{
987 /*
988 * SKL doesn't need us to program the AUX clock divider (Hardware will
989 * derive the clock from CDCLK automatically). We still implement the
990 * get_aux_clock_divider vfunc to plug-in into the existing code.
991 */
992 return index ? 0 : 1;
993}
994
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200995static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
996 bool has_aux_irq,
997 int send_bytes,
998 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000999{
1000 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001001 struct drm_i915_private *dev_priv =
1002 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001003 uint32_t precharge, timeout;
1004
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001005 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001006 precharge = 3;
1007 else
1008 precharge = 5;
1009
James Ausmus8f5f63d2017-10-12 14:30:37 -07001010 if (IS_BROADWELL(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001011 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1012 else
1013 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1014
1015 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001016 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001017 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001018 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001019 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001020 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001021 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1022 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001023 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001024}
1025
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001026static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1027 bool has_aux_irq,
1028 int send_bytes,
1029 uint32_t unused)
1030{
1031 return DP_AUX_CH_CTL_SEND_BUSY |
1032 DP_AUX_CH_CTL_DONE |
1033 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1034 DP_AUX_CH_CTL_TIME_OUT_ERROR |
James Ausmus6fa228b2017-10-12 14:30:36 -07001035 DP_AUX_CH_CTL_TIME_OUT_MAX |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001036 DP_AUX_CH_CTL_RECEIVE_ERROR |
1037 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001038 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001039 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1040}
1041
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001042static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001043intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001044 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001045 uint8_t *recv, int recv_size)
1046{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001047 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001048 struct drm_i915_private *dev_priv =
1049 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001050 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001051 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001052 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001053 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001054 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001055 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001056 bool vdd;
1057
Ville Syrjälä773538e82014-09-04 14:54:56 +03001058 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001059
Ville Syrjälä72c35002014-08-18 22:16:00 +03001060 /*
1061 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1062 * In such cases we want to leave VDD enabled and it's up to upper layers
1063 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1064 * ourselves.
1065 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001066 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001067
1068 /* dp aux is extremely sensitive to irq latency, hence request the
1069 * lowest possible wakeup latency and so prevent the cpu from going into
1070 * deep sleep states.
1071 */
1072 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001073
Keith Packard9b984da2011-09-19 13:54:47 -07001074 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001075
Jesse Barnes11bee432011-08-01 15:02:20 -07001076 /* Try to wait for any previous AUX channel activity */
1077 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001078 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001079 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1080 break;
1081 msleep(1);
1082 }
1083
1084 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001085 static u32 last_status = -1;
1086 const u32 status = I915_READ(ch_ctl);
1087
1088 if (status != last_status) {
1089 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1090 status);
1091 last_status = status;
1092 }
1093
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001094 ret = -EBUSY;
1095 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001096 }
1097
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001098 /* Only 5 data registers! */
1099 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1100 ret = -E2BIG;
1101 goto out;
1102 }
1103
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001104 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001105 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1106 has_aux_irq,
1107 send_bytes,
1108 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001109
Chris Wilsonbc866252013-07-21 16:00:03 +01001110 /* Must try at least 3 times according to DP spec */
1111 for (try = 0; try < 5; try++) {
1112 /* Load the send data into the aux channel data registers */
1113 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001114 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001115 intel_dp_pack_aux(send + i,
1116 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001117
Chris Wilsonbc866252013-07-21 16:00:03 +01001118 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001119 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001120
Chris Wilsonbc866252013-07-21 16:00:03 +01001121 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001122
Chris Wilsonbc866252013-07-21 16:00:03 +01001123 /* Clear done status and any errors */
1124 I915_WRITE(ch_ctl,
1125 status |
1126 DP_AUX_CH_CTL_DONE |
1127 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1128 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001129
Todd Previte74ebf292015-04-15 08:38:41 -07001130 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001131 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001132
1133 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1134 * 400us delay required for errors and timeouts
1135 * Timeout errors from the HW already meet this
1136 * requirement so skip to next iteration
1137 */
1138 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1139 usleep_range(400, 500);
1140 continue;
1141 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001142 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001143 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001144 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001145 }
1146
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001147 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001148 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001149 ret = -EBUSY;
1150 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001151 }
1152
Jim Bridee058c942015-05-27 10:21:48 -07001153done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001154 /* Check for timeout or receive error.
1155 * Timeouts occur when the sink is not connected
1156 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001157 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001158 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001159 ret = -EIO;
1160 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001161 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001162
1163 /* Timeouts occur when the device isn't connected, so they're
1164 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001165 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001166 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001167 ret = -ETIMEDOUT;
1168 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001169 }
1170
1171 /* Unload any bytes sent back from the other side */
1172 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1173 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001174
1175 /*
1176 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1177 * We have no idea of what happened so we return -EBUSY so
1178 * drm layer takes care for the necessary retries.
1179 */
1180 if (recv_bytes == 0 || recv_bytes > 20) {
1181 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1182 recv_bytes);
1183 /*
1184 * FIXME: This patch was created on top of a series that
1185 * organize the retries at drm level. There EBUSY should
1186 * also take care for 1ms wait before retrying.
1187 * That aux retries re-org is still needed and after that is
1188 * merged we remove this sleep from here.
1189 */
1190 usleep_range(1000, 1500);
1191 ret = -EBUSY;
1192 goto out;
1193 }
1194
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001195 if (recv_bytes > recv_size)
1196 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001197
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001198 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001199 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001200 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001201
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001202 ret = recv_bytes;
1203out:
1204 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1205
Jani Nikula884f19e2014-03-14 16:51:14 +02001206 if (vdd)
1207 edp_panel_vdd_off(intel_dp, false);
1208
Ville Syrjälä773538e82014-09-04 14:54:56 +03001209 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001210
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001211 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001212}
1213
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001214#define BARE_ADDRESS_SIZE 3
1215#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001216static ssize_t
1217intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001218{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001219 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1220 uint8_t txbuf[20], rxbuf[20];
1221 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001222 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001223
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001224 txbuf[0] = (msg->request << 4) |
1225 ((msg->address >> 16) & 0xf);
1226 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001227 txbuf[2] = msg->address & 0xff;
1228 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001229
Jani Nikula9d1a1032014-03-14 16:51:15 +02001230 switch (msg->request & ~DP_AUX_I2C_MOT) {
1231 case DP_AUX_NATIVE_WRITE:
1232 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001233 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001234 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001235 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001236
Jani Nikula9d1a1032014-03-14 16:51:15 +02001237 if (WARN_ON(txsize > 20))
1238 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001239
Ville Syrjälädd788092016-07-28 17:55:04 +03001240 WARN_ON(!msg->buffer != !msg->size);
1241
Imre Deakd81a67c2016-01-29 14:52:26 +02001242 if (msg->buffer)
1243 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001244
Jani Nikula9d1a1032014-03-14 16:51:15 +02001245 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1246 if (ret > 0) {
1247 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001248
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001249 if (ret > 1) {
1250 /* Number of bytes written in a short write. */
1251 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1252 } else {
1253 /* Return payload size. */
1254 ret = msg->size;
1255 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001256 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001257 break;
1258
1259 case DP_AUX_NATIVE_READ:
1260 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001261 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001262 rxsize = msg->size + 1;
1263
1264 if (WARN_ON(rxsize > 20))
1265 return -E2BIG;
1266
1267 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1268 if (ret > 0) {
1269 msg->reply = rxbuf[0] >> 4;
1270 /*
1271 * Assume happy day, and copy the data. The caller is
1272 * expected to check msg->reply before touching it.
1273 *
1274 * Return payload size.
1275 */
1276 ret--;
1277 memcpy(msg->buffer, rxbuf + 1, ret);
1278 }
1279 break;
1280
1281 default:
1282 ret = -EINVAL;
1283 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001284 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001285
Jani Nikula9d1a1032014-03-14 16:51:15 +02001286 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001287}
1288
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001289static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1290 enum port port)
1291{
1292 const struct ddi_vbt_port_info *info =
1293 &dev_priv->vbt.ddi_port_info[port];
1294 enum port aux_port;
1295
1296 if (!info->alternate_aux_channel) {
1297 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1298 port_name(port), port_name(port));
1299 return port;
1300 }
1301
1302 switch (info->alternate_aux_channel) {
1303 case DP_AUX_A:
1304 aux_port = PORT_A;
1305 break;
1306 case DP_AUX_B:
1307 aux_port = PORT_B;
1308 break;
1309 case DP_AUX_C:
1310 aux_port = PORT_C;
1311 break;
1312 case DP_AUX_D:
1313 aux_port = PORT_D;
1314 break;
1315 default:
1316 MISSING_CASE(info->alternate_aux_channel);
1317 aux_port = PORT_A;
1318 break;
1319 }
1320
1321 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1322 port_name(aux_port), port_name(port));
1323
1324 return aux_port;
1325}
1326
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001327static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001328 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001329{
1330 switch (port) {
1331 case PORT_B:
1332 case PORT_C:
1333 case PORT_D:
1334 return DP_AUX_CH_CTL(port);
1335 default:
1336 MISSING_CASE(port);
1337 return DP_AUX_CH_CTL(PORT_B);
1338 }
1339}
1340
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001341static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001342 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001343{
1344 switch (port) {
1345 case PORT_B:
1346 case PORT_C:
1347 case PORT_D:
1348 return DP_AUX_CH_DATA(port, index);
1349 default:
1350 MISSING_CASE(port);
1351 return DP_AUX_CH_DATA(PORT_B, index);
1352 }
1353}
1354
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001355static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001356 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001357{
1358 switch (port) {
1359 case PORT_A:
1360 return DP_AUX_CH_CTL(port);
1361 case PORT_B:
1362 case PORT_C:
1363 case PORT_D:
1364 return PCH_DP_AUX_CH_CTL(port);
1365 default:
1366 MISSING_CASE(port);
1367 return DP_AUX_CH_CTL(PORT_A);
1368 }
1369}
1370
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001371static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001372 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001373{
1374 switch (port) {
1375 case PORT_A:
1376 return DP_AUX_CH_DATA(port, index);
1377 case PORT_B:
1378 case PORT_C:
1379 case PORT_D:
1380 return PCH_DP_AUX_CH_DATA(port, index);
1381 default:
1382 MISSING_CASE(port);
1383 return DP_AUX_CH_DATA(PORT_A, index);
1384 }
1385}
1386
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001387static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001388 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001389{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001390 switch (port) {
1391 case PORT_A:
1392 case PORT_B:
1393 case PORT_C:
1394 case PORT_D:
1395 return DP_AUX_CH_CTL(port);
1396 default:
1397 MISSING_CASE(port);
1398 return DP_AUX_CH_CTL(PORT_A);
1399 }
1400}
1401
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001402static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001403 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001404{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001405 switch (port) {
1406 case PORT_A:
1407 case PORT_B:
1408 case PORT_C:
1409 case PORT_D:
1410 return DP_AUX_CH_DATA(port, index);
1411 default:
1412 MISSING_CASE(port);
1413 return DP_AUX_CH_DATA(PORT_A, index);
1414 }
1415}
1416
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001417static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001418 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001419{
1420 if (INTEL_INFO(dev_priv)->gen >= 9)
1421 return skl_aux_ctl_reg(dev_priv, port);
1422 else if (HAS_PCH_SPLIT(dev_priv))
1423 return ilk_aux_ctl_reg(dev_priv, port);
1424 else
1425 return g4x_aux_ctl_reg(dev_priv, port);
1426}
1427
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001428static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001429 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001430{
1431 if (INTEL_INFO(dev_priv)->gen >= 9)
1432 return skl_aux_data_reg(dev_priv, port, index);
1433 else if (HAS_PCH_SPLIT(dev_priv))
1434 return ilk_aux_data_reg(dev_priv, port, index);
1435 else
1436 return g4x_aux_data_reg(dev_priv, port, index);
1437}
1438
1439static void intel_aux_reg_init(struct intel_dp *intel_dp)
1440{
1441 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001442 enum port port = intel_aux_port(dev_priv,
1443 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001444 int i;
1445
1446 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1447 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1448 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1449}
1450
Jani Nikula9d1a1032014-03-14 16:51:15 +02001451static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001452intel_dp_aux_fini(struct intel_dp *intel_dp)
1453{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001454 kfree(intel_dp->aux.name);
1455}
1456
Chris Wilson7a418e32016-06-24 14:00:14 +01001457static void
Mika Kaholab6339582016-09-09 14:10:52 +03001458intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001459{
Jani Nikula33ad6622014-03-14 16:51:16 +02001460 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1461 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001462
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001463 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001464 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001465
Chris Wilson7a418e32016-06-24 14:00:14 +01001466 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001467 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001468 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001469}
1470
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001471bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301472{
Jani Nikulafc603ca2017-10-09 12:29:58 +03001473 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001474
Jani Nikulafc603ca2017-10-09 12:29:58 +03001475 return max_rate >= 540000;
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301476}
1477
Daniel Vetter0e503382014-07-04 11:26:04 -03001478static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001479intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001480 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001481{
1482 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001483 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001484 const struct dp_link_dpll *divisor = NULL;
1485 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001486
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001487 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001488 divisor = gen4_dpll;
1489 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001490 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001491 divisor = pch_dpll;
1492 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001493 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001494 divisor = chv_dpll;
1495 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001496 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001497 divisor = vlv_dpll;
1498 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001499 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001500
1501 if (divisor && count) {
1502 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001503 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001504 pipe_config->dpll = divisor[i].dpll;
1505 pipe_config->clock_set = true;
1506 break;
1507 }
1508 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001509 }
1510}
1511
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001512static void snprintf_int_array(char *str, size_t len,
1513 const int *array, int nelem)
1514{
1515 int i;
1516
1517 str[0] = '\0';
1518
1519 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001520 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001521 if (r >= len)
1522 return;
1523 str += r;
1524 len -= r;
1525 }
1526}
1527
1528static void intel_dp_print_rates(struct intel_dp *intel_dp)
1529{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001530 char str[128]; /* FIXME: too big for stack? */
1531
1532 if ((drm_debug & DRM_UT_KMS) == 0)
1533 return;
1534
Jani Nikula55cfc582017-03-28 17:59:04 +03001535 snprintf_int_array(str, sizeof(str),
1536 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001537 DRM_DEBUG_KMS("source rates: %s\n", str);
1538
Jani Nikula68f357c2017-03-28 17:59:05 +03001539 snprintf_int_array(str, sizeof(str),
1540 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001541 DRM_DEBUG_KMS("sink rates: %s\n", str);
1542
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001543 snprintf_int_array(str, sizeof(str),
1544 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001545 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001546}
1547
Ville Syrjälä50fec212015-03-12 17:10:34 +02001548int
1549intel_dp_max_link_rate(struct intel_dp *intel_dp)
1550{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001551 int len;
1552
Jani Nikulae6c0c642017-04-06 16:44:12 +03001553 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001554 if (WARN_ON(len <= 0))
1555 return 162000;
1556
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001557 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001558}
1559
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001560int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1561{
Jani Nikula8001b752017-03-28 17:59:03 +03001562 int i = intel_dp_rate_index(intel_dp->sink_rates,
1563 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001564
1565 if (WARN_ON(i < 0))
1566 i = 0;
1567
1568 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001569}
1570
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001571void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1572 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001573{
Jani Nikula68f357c2017-03-28 17:59:05 +03001574 /* eDP 1.4 rate select method. */
1575 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001576 *link_bw = 0;
1577 *rate_select =
1578 intel_dp_rate_select(intel_dp, port_clock);
1579 } else {
1580 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1581 *rate_select = 0;
1582 }
1583}
1584
Jani Nikulaf580bea2016-09-15 16:28:52 +03001585static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1586 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001587{
1588 int bpp, bpc;
1589
1590 bpp = pipe_config->pipe_bpp;
1591 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1592
1593 if (bpc > 0)
1594 bpp = min(bpp, 3*bpc);
1595
Manasi Navare611032b2017-01-24 08:21:49 -08001596 /* For DP Compliance we override the computed bpp for the pipe */
1597 if (intel_dp->compliance.test_data.bpc != 0) {
1598 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1599 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1600 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1601 pipe_config->pipe_bpp);
1602 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001603 return bpp;
1604}
1605
Jim Bridedc911f52017-08-09 12:48:53 -07001606static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1607 struct drm_display_mode *m2)
1608{
1609 bool bres = false;
1610
1611 if (m1 && m2)
1612 bres = (m1->hdisplay == m2->hdisplay &&
1613 m1->hsync_start == m2->hsync_start &&
1614 m1->hsync_end == m2->hsync_end &&
1615 m1->htotal == m2->htotal &&
1616 m1->vdisplay == m2->vdisplay &&
1617 m1->vsync_start == m2->vsync_start &&
1618 m1->vsync_end == m2->vsync_end &&
1619 m1->vtotal == m2->vtotal);
1620 return bres;
1621}
1622
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001623bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001624intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001625 struct intel_crtc_state *pipe_config,
1626 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001627{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001628 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001629 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001630 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001631 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001632 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001633 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001634 struct intel_digital_connector_state *intel_conn_state =
1635 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001636 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001637 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001638 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001639 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001640 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301641 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001642 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001643 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001644 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001645 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001646 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1647 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301648
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001649 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001650 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301651
1652 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001653 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301654
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001655 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001656
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001657 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001658 pipe_config->has_pch_encoder = true;
1659
Vandana Kannanf769cd22014-08-05 07:51:22 -07001660 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001661 if (port == PORT_A)
1662 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001663 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001664 pipe_config->has_audio = intel_dp->has_audio;
1665 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001666 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001667
Jani Nikula1853a9d2017-08-18 12:30:20 +03001668 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jim Bridedc911f52017-08-09 12:48:53 -07001669 struct drm_display_mode *panel_mode =
1670 intel_connector->panel.alt_fixed_mode;
1671 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1672
1673 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1674 panel_mode = intel_connector->panel.fixed_mode;
1675
1676 drm_mode_debug_printmodeline(panel_mode);
1677
1678 intel_fixed_panel_mode(panel_mode, adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001679
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001680 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001681 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001682 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001683 if (ret)
1684 return ret;
1685 }
1686
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001687 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001688 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001689 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001690 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001691 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001692 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001693 }
1694
Daniel Vettercb1793c2012-06-04 18:39:21 +02001695 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001696 return false;
1697
Manasi Navareda15f7c2017-01-24 08:16:34 -08001698 /* Use values requested by Compliance Test Request */
1699 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001700 int index;
1701
Manasi Navare140ef132017-06-08 13:41:03 -07001702 /* Validate the compliance test data since max values
1703 * might have changed due to link train fallback.
1704 */
1705 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1706 intel_dp->compliance.test_lane_count)) {
1707 index = intel_dp_rate_index(intel_dp->common_rates,
1708 intel_dp->num_common_rates,
1709 intel_dp->compliance.test_link_rate);
1710 if (index >= 0)
1711 min_clock = max_clock = index;
1712 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1713 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08001714 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001715 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301716 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001717 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001718 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001719
Daniel Vetter36008362013-03-27 00:44:59 +01001720 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1721 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001722 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula1853a9d2017-08-18 12:30:20 +03001723 if (intel_dp_is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301724
1725 /* Get bpp from vbt only for panels that dont have bpp in edid */
1726 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001727 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001728 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001729 dev_priv->vbt.edp.bpp);
1730 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001731 }
1732
Jani Nikula344c5bb2014-09-09 11:25:13 +03001733 /*
1734 * Use the maximum clock and number of lanes the eDP panel
1735 * advertizes being capable of. The panels are generally
1736 * designed to support only a single clock and lane
1737 * configuration, and typically these values correspond to the
1738 * native resolution of the panel.
1739 */
1740 min_lane_count = max_lane_count;
1741 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001742 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001743
Daniel Vetter36008362013-03-27 00:44:59 +01001744 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001745 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1746 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001747
Dave Airliec6930992014-07-14 11:04:39 +10001748 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301749 for (lane_count = min_lane_count;
1750 lane_count <= max_lane_count;
1751 lane_count <<= 1) {
1752
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001753 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001754 link_avail = intel_dp_max_data_rate(link_clock,
1755 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001756
Daniel Vetter36008362013-03-27 00:44:59 +01001757 if (mode_rate <= link_avail) {
1758 goto found;
1759 }
1760 }
1761 }
1762 }
1763
1764 return false;
1765
1766found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001767 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001768 /*
1769 * See:
1770 * CEA-861-E - 5.1 Default Encoding Parameters
1771 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1772 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001773 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001774 bpp != 18 &&
1775 drm_default_rgb_quant_range(adjusted_mode) ==
1776 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001777 } else {
1778 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001779 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001780 }
1781
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001782 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301783
Daniel Vetter657445f2013-05-04 10:09:18 +02001784 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001785 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001786
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001787 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1788 &link_bw, &rate_select);
1789
1790 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1791 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001792 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001793 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1794 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001796 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001797 adjusted_mode->crtc_clock,
1798 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001799 &pipe_config->dp_m_n,
1800 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001801
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301802 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301803 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001804 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301805 intel_link_compute_m_n(bpp, lane_count,
1806 intel_connector->panel.downclock_mode->clock,
1807 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001808 &pipe_config->dp_m2_n2,
1809 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301810 }
1811
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001812 /*
1813 * DPLL0 VCO may need to be adjusted to get the correct
1814 * clock for eDP. This will affect cdclk as well.
1815 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03001816 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001817 int vco;
1818
1819 switch (pipe_config->port_clock / 2) {
1820 case 108000:
1821 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001822 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001823 break;
1824 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001825 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001826 break;
1827 }
1828
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001829 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001830 }
1831
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001832 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001833 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001834
Ville Syrjälä4d90f2d2017-10-12 16:02:01 +03001835 intel_psr_compute_config(intel_dp, pipe_config);
1836
Daniel Vetter36008362013-03-27 00:44:59 +01001837 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001838}
1839
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001840void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001841 int link_rate, uint8_t lane_count,
1842 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001843{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001844 intel_dp->link_rate = link_rate;
1845 intel_dp->lane_count = lane_count;
1846 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001847}
1848
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001849static void intel_dp_prepare(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03001850 const struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001851{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001852 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001853 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001854 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001855 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001856 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001857 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001858
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001859 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1860 pipe_config->lane_count,
1861 intel_crtc_has_type(pipe_config,
1862 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001863
Keith Packard417e8222011-11-01 19:54:11 -07001864 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001865 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001866 *
1867 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001868 * SNB CPU
1869 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001870 * CPT PCH
1871 *
1872 * IBX PCH and CPU are the same for almost everything,
1873 * except that the CPU DP PLL is configured in this
1874 * register
1875 *
1876 * CPT PCH is quite different, having many bits moved
1877 * to the TRANS_DP_CTL register instead. That
1878 * configuration happens (oddly) in ironlake_pch_enable
1879 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001880
Keith Packard417e8222011-11-01 19:54:11 -07001881 /* Preserve the BIOS-computed detected bit. This is
1882 * supposed to be read-only.
1883 */
1884 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001885
Keith Packard417e8222011-11-01 19:54:11 -07001886 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001887 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001888 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001889
Keith Packard417e8222011-11-01 19:54:11 -07001890 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001891
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001892 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001893 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1894 intel_dp->DP |= DP_SYNC_HS_HIGH;
1895 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1896 intel_dp->DP |= DP_SYNC_VS_HIGH;
1897 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1898
Jani Nikula6aba5b62013-10-04 15:08:10 +03001899 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001900 intel_dp->DP |= DP_ENHANCED_FRAMING;
1901
Daniel Vetter7c62a162013-06-01 17:16:20 +02001902 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001903 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001904 u32 trans_dp;
1905
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001906 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001907
1908 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1909 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1910 trans_dp |= TRANS_DP_ENH_FRAMING;
1911 else
1912 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1913 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001914 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001915 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001916 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001917
1918 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1919 intel_dp->DP |= DP_SYNC_HS_HIGH;
1920 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1921 intel_dp->DP |= DP_SYNC_VS_HIGH;
1922 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1923
Jani Nikula6aba5b62013-10-04 15:08:10 +03001924 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001925 intel_dp->DP |= DP_ENHANCED_FRAMING;
1926
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001927 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001928 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001929 else if (crtc->pipe == PIPE_B)
1930 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001931 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001932}
1933
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001934#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1935#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001936
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001937#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1938#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001939
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001940#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1941#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001942
Imre Deakde9c1b62016-06-16 20:01:46 +03001943static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1944 struct intel_dp *intel_dp);
1945
Daniel Vetter4be73782014-01-17 14:39:48 +01001946static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001947 u32 mask,
1948 u32 value)
1949{
Paulo Zanoni30add222012-10-26 19:05:45 -02001950 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001951 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001952 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001953
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001954 lockdep_assert_held(&dev_priv->pps_mutex);
1955
Imre Deakde9c1b62016-06-16 20:01:46 +03001956 intel_pps_verify_state(dev_priv, intel_dp);
1957
Jani Nikulabf13e812013-09-06 07:40:05 +03001958 pp_stat_reg = _pp_stat_reg(intel_dp);
1959 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001960
1961 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001962 mask, value,
1963 I915_READ(pp_stat_reg),
1964 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001965
Chris Wilson9036ff02016-06-30 15:33:09 +01001966 if (intel_wait_for_register(dev_priv,
1967 pp_stat_reg, mask, value,
1968 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001969 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001970 I915_READ(pp_stat_reg),
1971 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001972
1973 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001974}
1975
Daniel Vetter4be73782014-01-17 14:39:48 +01001976static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001977{
1978 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001979 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001980}
1981
Daniel Vetter4be73782014-01-17 14:39:48 +01001982static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001983{
Keith Packardbd943152011-09-18 23:09:52 -07001984 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001985 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001986}
Keith Packardbd943152011-09-18 23:09:52 -07001987
Daniel Vetter4be73782014-01-17 14:39:48 +01001988static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001989{
Abhay Kumard28d4732016-01-22 17:39:04 -08001990 ktime_t panel_power_on_time;
1991 s64 panel_power_off_duration;
1992
Keith Packard99ea7122011-11-01 19:57:50 -07001993 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001994
Abhay Kumard28d4732016-01-22 17:39:04 -08001995 /* take the difference of currrent time and panel power off time
1996 * and then make panel wait for t11_t12 if needed. */
1997 panel_power_on_time = ktime_get_boottime();
1998 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1999
Paulo Zanonidce56b32013-12-19 14:29:40 -02002000 /* When we disable the VDD override bit last we have to do the manual
2001 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08002002 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2003 wait_remaining_ms_from_jiffies(jiffies,
2004 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002005
Daniel Vetter4be73782014-01-17 14:39:48 +01002006 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002007}
Keith Packardbd943152011-09-18 23:09:52 -07002008
Daniel Vetter4be73782014-01-17 14:39:48 +01002009static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002010{
2011 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2012 intel_dp->backlight_on_delay);
2013}
2014
Daniel Vetter4be73782014-01-17 14:39:48 +01002015static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002016{
2017 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2018 intel_dp->backlight_off_delay);
2019}
Keith Packard99ea7122011-11-01 19:57:50 -07002020
Keith Packard832dd3c2011-11-01 19:34:06 -07002021/* Read the current pp_control value, unlocking the register if it
2022 * is locked
2023 */
2024
Jesse Barnes453c5422013-03-28 09:55:41 -07002025static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002026{
Jesse Barnes453c5422013-03-28 09:55:41 -07002027 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002028 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002029 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002030
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002031 lockdep_assert_held(&dev_priv->pps_mutex);
2032
Jani Nikulabf13e812013-09-06 07:40:05 +03002033 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002034 if (WARN_ON(!HAS_DDI(dev_priv) &&
2035 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302036 control &= ~PANEL_UNLOCK_MASK;
2037 control |= PANEL_UNLOCK_REGS;
2038 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002039 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002040}
2041
Ville Syrjälä951468f2014-09-04 14:55:31 +03002042/*
2043 * Must be paired with edp_panel_vdd_off().
2044 * Must hold pps_mutex around the whole on/off sequence.
2045 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2046 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002047static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002048{
Paulo Zanoni30add222012-10-26 19:05:45 -02002049 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002050 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002051 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002052 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002053 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002054 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002055
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002056 lockdep_assert_held(&dev_priv->pps_mutex);
2057
Jani Nikula1853a9d2017-08-18 12:30:20 +03002058 if (!intel_dp_is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002059 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002060
Egbert Eich2c623c12014-11-25 12:54:57 +01002061 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002062 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002063
Daniel Vetter4be73782014-01-17 14:39:48 +01002064 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002065 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002066
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002067 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002068
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002069 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2070 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002071
Daniel Vetter4be73782014-01-17 14:39:48 +01002072 if (!edp_have_panel_power(intel_dp))
2073 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002074
Jesse Barnes453c5422013-03-28 09:55:41 -07002075 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002076 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002077
Jani Nikulabf13e812013-09-06 07:40:05 +03002078 pp_stat_reg = _pp_stat_reg(intel_dp);
2079 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002080
2081 I915_WRITE(pp_ctrl_reg, pp);
2082 POSTING_READ(pp_ctrl_reg);
2083 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2084 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002085 /*
2086 * If the panel wasn't on, delay before accessing aux channel
2087 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002088 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002089 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2090 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002091 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002092 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002093
2094 return need_to_disable;
2095}
2096
Ville Syrjälä951468f2014-09-04 14:55:31 +03002097/*
2098 * Must be paired with intel_edp_panel_vdd_off() or
2099 * intel_edp_panel_off().
2100 * Nested calls to these functions are not allowed since
2101 * we drop the lock. Caller must use some higher level
2102 * locking to prevent nested calls from other threads.
2103 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002104void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002105{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002106 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002107
Jani Nikula1853a9d2017-08-18 12:30:20 +03002108 if (!intel_dp_is_edp(intel_dp))
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002109 return;
2110
Ville Syrjälä773538e82014-09-04 14:54:56 +03002111 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002112 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002113 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002114
Rob Clarke2c719b2014-12-15 13:56:32 -05002115 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002116 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002117}
2118
Daniel Vetter4be73782014-01-17 14:39:48 +01002119static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002120{
Paulo Zanoni30add222012-10-26 19:05:45 -02002121 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002122 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002123 struct intel_digital_port *intel_dig_port =
2124 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002125 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002126 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002127
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002128 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002129
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002130 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002131
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002132 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002133 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002134
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002135 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2136 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002137
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002138 pp = ironlake_get_pp_control(intel_dp);
2139 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002140
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002141 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2142 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002143
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002144 I915_WRITE(pp_ctrl_reg, pp);
2145 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002146
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002147 /* Make sure sequencer is idle before allowing subsequent activity */
2148 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2149 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002150
Imre Deak5a162e22016-08-10 14:07:30 +03002151 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002152 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002153
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002154 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002155}
2156
Daniel Vetter4be73782014-01-17 14:39:48 +01002157static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002158{
2159 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2160 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002161
Ville Syrjälä773538e82014-09-04 14:54:56 +03002162 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002163 if (!intel_dp->want_panel_vdd)
2164 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002165 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002166}
2167
Imre Deakaba86892014-07-30 15:57:31 +03002168static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2169{
2170 unsigned long delay;
2171
2172 /*
2173 * Queue the timer to fire a long time from now (relative to the power
2174 * down delay) to keep the panel power up across a sequence of
2175 * operations.
2176 */
2177 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2178 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2179}
2180
Ville Syrjälä951468f2014-09-04 14:55:31 +03002181/*
2182 * Must be paired with edp_panel_vdd_on().
2183 * Must hold pps_mutex around the whole on/off sequence.
2184 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2185 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002186static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002187{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002188 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002189
2190 lockdep_assert_held(&dev_priv->pps_mutex);
2191
Jani Nikula1853a9d2017-08-18 12:30:20 +03002192 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002193 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002194
Rob Clarke2c719b2014-12-15 13:56:32 -05002195 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002196 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002197
Keith Packardbd943152011-09-18 23:09:52 -07002198 intel_dp->want_panel_vdd = false;
2199
Imre Deakaba86892014-07-30 15:57:31 +03002200 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002201 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002202 else
2203 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002204}
2205
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002206static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002207{
Paulo Zanoni30add222012-10-26 19:05:45 -02002208 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002209 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002210 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002211 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002212
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002213 lockdep_assert_held(&dev_priv->pps_mutex);
2214
Jani Nikula1853a9d2017-08-18 12:30:20 +03002215 if (!intel_dp_is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002216 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002217
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002218 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2219 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002220
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002221 if (WARN(edp_have_panel_power(intel_dp),
2222 "eDP port %c panel power already on\n",
2223 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002224 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002225
Daniel Vetter4be73782014-01-17 14:39:48 +01002226 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002227
Jani Nikulabf13e812013-09-06 07:40:05 +03002228 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002229 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002230 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002231 /* ILK workaround: disable reset around power sequence */
2232 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002233 I915_WRITE(pp_ctrl_reg, pp);
2234 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002235 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002236
Imre Deak5a162e22016-08-10 14:07:30 +03002237 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002238 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002239 pp |= PANEL_POWER_RESET;
2240
Jesse Barnes453c5422013-03-28 09:55:41 -07002241 I915_WRITE(pp_ctrl_reg, pp);
2242 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002243
Daniel Vetter4be73782014-01-17 14:39:48 +01002244 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002245 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002246
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002247 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002248 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002249 I915_WRITE(pp_ctrl_reg, pp);
2250 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002251 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002252}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002253
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002254void intel_edp_panel_on(struct intel_dp *intel_dp)
2255{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002256 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002257 return;
2258
2259 pps_lock(intel_dp);
2260 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002261 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002262}
2263
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002264
2265static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002266{
Paulo Zanoni30add222012-10-26 19:05:45 -02002267 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002268 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002269 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002270 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002271
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002272 lockdep_assert_held(&dev_priv->pps_mutex);
2273
Jani Nikula1853a9d2017-08-18 12:30:20 +03002274 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002275 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002276
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002277 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2278 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002279
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002280 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2281 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002282
Jesse Barnes453c5422013-03-28 09:55:41 -07002283 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002284 /* We need to switch off panel power _and_ force vdd, for otherwise some
2285 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002286 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002287 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002288
Jani Nikulabf13e812013-09-06 07:40:05 +03002289 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002290
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002291 intel_dp->want_panel_vdd = false;
2292
Jesse Barnes453c5422013-03-28 09:55:41 -07002293 I915_WRITE(pp_ctrl_reg, pp);
2294 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002295
Daniel Vetter4be73782014-01-17 14:39:48 +01002296 wait_panel_off(intel_dp);
Manasi Navarecbacf022017-10-04 09:48:26 -07002297 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002298
2299 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002300 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002301}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002302
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002303void intel_edp_panel_off(struct intel_dp *intel_dp)
2304{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002305 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002306 return;
2307
2308 pps_lock(intel_dp);
2309 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002310 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002311}
2312
Jani Nikula1250d102014-08-12 17:11:39 +03002313/* Enable backlight in the panel power control. */
2314static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002316 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2317 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002318 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002319 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002320 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002321
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002322 /*
2323 * If we enable the backlight right away following a panel power
2324 * on, we may see slight flicker as the panel syncs with the eDP
2325 * link. So delay a bit to make sure the image is solid before
2326 * allowing it to appear.
2327 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002328 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002329
Ville Syrjälä773538e82014-09-04 14:54:56 +03002330 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002331
Jesse Barnes453c5422013-03-28 09:55:41 -07002332 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002333 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002334
Jani Nikulabf13e812013-09-06 07:40:05 +03002335 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002336
2337 I915_WRITE(pp_ctrl_reg, pp);
2338 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002339
Ville Syrjälä773538e82014-09-04 14:54:56 +03002340 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002341}
2342
Jani Nikula1250d102014-08-12 17:11:39 +03002343/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002344void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2345 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002346{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002347 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2348
Jani Nikula1853a9d2017-08-18 12:30:20 +03002349 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002350 return;
2351
2352 DRM_DEBUG_KMS("\n");
2353
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002354 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002355 _intel_edp_backlight_on(intel_dp);
2356}
2357
2358/* Disable backlight in the panel power control. */
2359static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002360{
Paulo Zanoni30add222012-10-26 19:05:45 -02002361 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002362 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002363 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002364 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002365
Jani Nikula1853a9d2017-08-18 12:30:20 +03002366 if (!intel_dp_is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07002367 return;
2368
Ville Syrjälä773538e82014-09-04 14:54:56 +03002369 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002370
Jesse Barnes453c5422013-03-28 09:55:41 -07002371 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002372 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002373
Jani Nikulabf13e812013-09-06 07:40:05 +03002374 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002375
2376 I915_WRITE(pp_ctrl_reg, pp);
2377 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002378
Ville Syrjälä773538e82014-09-04 14:54:56 +03002379 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002380
Paulo Zanonidce56b32013-12-19 14:29:40 -02002381 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002382 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002383}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002384
Jani Nikula1250d102014-08-12 17:11:39 +03002385/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002386void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002387{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002388 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2389
Jani Nikula1853a9d2017-08-18 12:30:20 +03002390 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002391 return;
2392
2393 DRM_DEBUG_KMS("\n");
2394
2395 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002396 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002397}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002398
Jani Nikula73580fb72014-08-12 17:11:41 +03002399/*
2400 * Hook for controlling the panel power control backlight through the bl_power
2401 * sysfs attribute. Take care to handle multiple calls.
2402 */
2403static void intel_edp_backlight_power(struct intel_connector *connector,
2404 bool enable)
2405{
2406 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002407 bool is_enabled;
2408
Ville Syrjälä773538e82014-09-04 14:54:56 +03002409 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002410 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002411 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002412
2413 if (is_enabled == enable)
2414 return;
2415
Jani Nikula23ba9372014-08-27 14:08:43 +03002416 DRM_DEBUG_KMS("panel power control backlight %s\n",
2417 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002418
2419 if (enable)
2420 _intel_edp_backlight_on(intel_dp);
2421 else
2422 _intel_edp_backlight_off(intel_dp);
2423}
2424
Ville Syrjälä64e10772015-10-29 21:26:01 +02002425static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2426{
2427 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2428 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2429 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2430
2431 I915_STATE_WARN(cur_state != state,
2432 "DP port %c state assertion failure (expected %s, current %s)\n",
2433 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002434 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002435}
2436#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2437
2438static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2439{
2440 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2441
2442 I915_STATE_WARN(cur_state != state,
2443 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002444 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002445}
2446#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2447#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2448
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002449static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002450 const struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002451{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002452 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002453 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002454
Ville Syrjälä64e10772015-10-29 21:26:01 +02002455 assert_pipe_disabled(dev_priv, crtc->pipe);
2456 assert_dp_port_disabled(intel_dp);
2457 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002458
Ville Syrjäläabfce942015-10-29 21:26:03 +02002459 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002460 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002461
2462 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2463
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002464 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002465 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2466 else
2467 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2468
2469 I915_WRITE(DP_A, intel_dp->DP);
2470 POSTING_READ(DP_A);
2471 udelay(500);
2472
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002473 /*
2474 * [DevILK] Work around required when enabling DP PLL
2475 * while a pipe is enabled going to FDI:
2476 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2477 * 2. Program DP PLL enable
2478 */
2479 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002480 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002481
Daniel Vetter07679352012-09-06 22:15:42 +02002482 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002483
Daniel Vetter07679352012-09-06 22:15:42 +02002484 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002485 POSTING_READ(DP_A);
2486 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002487}
2488
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002489static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002490{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002491 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002492 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2493 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002494
Ville Syrjälä64e10772015-10-29 21:26:01 +02002495 assert_pipe_disabled(dev_priv, crtc->pipe);
2496 assert_dp_port_disabled(intel_dp);
2497 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002498
Ville Syrjäläabfce942015-10-29 21:26:03 +02002499 DRM_DEBUG_KMS("disabling eDP PLL\n");
2500
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002501 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002502
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002503 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002504 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002505 udelay(200);
2506}
2507
Ville Syrjälä857c4162017-10-27 12:45:23 +03002508static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2509{
2510 /*
2511 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2512 * be capable of signalling downstream hpd with a long pulse.
2513 * Whether or not that means D3 is safe to use is not clear,
2514 * but let's assume so until proven otherwise.
2515 *
2516 * FIXME should really check all downstream ports...
2517 */
2518 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2519 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2520 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2521}
2522
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002523/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002524void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002525{
2526 int ret, i;
2527
2528 /* Should have a valid DPCD by this point */
2529 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2530 return;
2531
2532 if (mode != DRM_MODE_DPMS_ON) {
Ville Syrjälä857c4162017-10-27 12:45:23 +03002533 if (downstream_hpd_needs_d0(intel_dp))
2534 return;
2535
Jani Nikula9d1a1032014-03-14 16:51:15 +02002536 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2537 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002538 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002539 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2540
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002541 /*
2542 * When turning on, we need to retry for 1ms to give the sink
2543 * time to wake up.
2544 */
2545 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002546 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2547 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002548 if (ret == 1)
2549 break;
2550 msleep(1);
2551 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002552
2553 if (ret == 1 && lspcon->active)
2554 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002555 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002556
2557 if (ret != 1)
2558 DRM_DEBUG_KMS("failed to %s sink power state\n",
2559 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002560}
2561
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002562static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2563 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002564{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002565 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002566 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002567 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002568 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002569 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002570 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002571
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002572 if (!intel_display_power_get_if_enabled(dev_priv,
2573 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002574 return false;
2575
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002576 ret = false;
2577
Imre Deak6d129be2014-03-05 16:20:54 +02002578 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002579
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002580 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002581 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002582
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002583 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002584 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002585 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002586 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002587
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002588 for_each_pipe(dev_priv, p) {
2589 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2590 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2591 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002592 ret = true;
2593
2594 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002595 }
2596 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002597
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002598 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002599 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002600 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002601 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2602 } else {
2603 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002604 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002605
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002606 ret = true;
2607
2608out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002609 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002610
2611 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002612}
2613
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002614static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002615 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002616{
2617 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002618 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002619 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002620 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002621 enum port port = dp_to_dig_port(intel_dp)->port;
2622 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002623
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002624 if (encoder->type == INTEL_OUTPUT_EDP)
2625 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2626 else
2627 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2628
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002629 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002630
2631 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002632
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002633 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002634 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2635
2636 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002637 flags |= DRM_MODE_FLAG_PHSYNC;
2638 else
2639 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002640
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002641 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002642 flags |= DRM_MODE_FLAG_PVSYNC;
2643 else
2644 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002645 } else {
2646 if (tmp & DP_SYNC_HS_HIGH)
2647 flags |= DRM_MODE_FLAG_PHSYNC;
2648 else
2649 flags |= DRM_MODE_FLAG_NHSYNC;
2650
2651 if (tmp & DP_SYNC_VS_HIGH)
2652 flags |= DRM_MODE_FLAG_PVSYNC;
2653 else
2654 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002655 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002656
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002657 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002658
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002659 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002660 pipe_config->limited_color_range = true;
2661
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002662 pipe_config->lane_count =
2663 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2664
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002665 intel_dp_get_m_n(crtc, pipe_config);
2666
Ville Syrjälä18442d02013-09-13 16:00:08 +03002667 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002668 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002669 pipe_config->port_clock = 162000;
2670 else
2671 pipe_config->port_clock = 270000;
2672 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002673
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002674 pipe_config->base.adjusted_mode.crtc_clock =
2675 intel_dotclock_calculate(pipe_config->port_clock,
2676 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002677
Jani Nikula1853a9d2017-08-18 12:30:20 +03002678 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02002679 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002680 /*
2681 * This is a big fat ugly hack.
2682 *
2683 * Some machines in UEFI boot mode provide us a VBT that has 18
2684 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2685 * unknown we fail to light up. Yet the same BIOS boots up with
2686 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2687 * max, not what it tells us to use.
2688 *
2689 * Note: This will still be broken if the eDP panel is not lit
2690 * up by the BIOS, and thus we can't get the mode at module
2691 * load.
2692 */
2693 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002694 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2695 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002696 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002697}
2698
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002699static void intel_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002700 const struct intel_crtc_state *old_crtc_state,
2701 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002702{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002703 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002704
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002705 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002706 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002707
2708 /* Make sure the panel is off before trying to change the mode. But also
2709 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002710 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002711 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002712 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002713 intel_edp_panel_off(intel_dp);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002714}
2715
2716static void g4x_disable_dp(struct intel_encoder *encoder,
2717 const struct intel_crtc_state *old_crtc_state,
2718 const struct drm_connector_state *old_conn_state)
2719{
2720 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2721
2722 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Daniel Vetter37398502012-09-06 22:15:44 +02002723
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002724 /* disable the port before the pipe on g4x */
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002725 intel_dp_link_down(intel_dp);
2726}
2727
2728static void ilk_disable_dp(struct intel_encoder *encoder,
2729 const struct intel_crtc_state *old_crtc_state,
2730 const struct drm_connector_state *old_conn_state)
2731{
2732 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2733}
2734
2735static void vlv_disable_dp(struct intel_encoder *encoder,
2736 const struct intel_crtc_state *old_crtc_state,
2737 const struct drm_connector_state *old_conn_state)
2738{
2739 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2740
2741 intel_psr_disable(intel_dp, old_crtc_state);
2742
2743 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Jesse Barnesd240f202010-08-13 15:43:26 -07002744}
2745
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002746static void ilk_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002747 const struct intel_crtc_state *old_crtc_state,
2748 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002749{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002750 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002751 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002752
Ville Syrjälä49277c32014-03-31 18:21:26 +03002753 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002754
2755 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002756 if (port == PORT_A)
2757 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002758}
2759
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002760static void vlv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002761 const struct intel_crtc_state *old_crtc_state,
2762 const struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002763{
2764 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2765
2766 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002767}
2768
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002769static void chv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002770 const struct intel_crtc_state *old_crtc_state,
2771 const struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002772{
2773 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002774 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002775 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002776
2777 intel_dp_link_down(intel_dp);
2778
Ville Syrjäläa5805162015-05-26 20:42:30 +03002779 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002780
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002781 /* Assert data lane reset */
2782 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002783
Ville Syrjäläa5805162015-05-26 20:42:30 +03002784 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002785}
2786
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002787static void
2788_intel_dp_set_link_train(struct intel_dp *intel_dp,
2789 uint32_t *DP,
2790 uint8_t dp_train_pat)
2791{
2792 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2793 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002794 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795 enum port port = intel_dig_port->port;
2796
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002797 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2798 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2799 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2800
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002801 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002802 uint32_t temp = I915_READ(DP_TP_CTL(port));
2803
2804 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2805 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2806 else
2807 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2808
2809 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2810 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2811 case DP_TRAINING_PATTERN_DISABLE:
2812 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2813
2814 break;
2815 case DP_TRAINING_PATTERN_1:
2816 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2817 break;
2818 case DP_TRAINING_PATTERN_2:
2819 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2820 break;
2821 case DP_TRAINING_PATTERN_3:
2822 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2823 break;
2824 }
2825 I915_WRITE(DP_TP_CTL(port), temp);
2826
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002827 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002828 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002829 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2830
2831 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2832 case DP_TRAINING_PATTERN_DISABLE:
2833 *DP |= DP_LINK_TRAIN_OFF_CPT;
2834 break;
2835 case DP_TRAINING_PATTERN_1:
2836 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2837 break;
2838 case DP_TRAINING_PATTERN_2:
2839 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2840 break;
2841 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002842 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002843 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2844 break;
2845 }
2846
2847 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002848 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002849 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2850 else
2851 *DP &= ~DP_LINK_TRAIN_MASK;
2852
2853 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2854 case DP_TRAINING_PATTERN_DISABLE:
2855 *DP |= DP_LINK_TRAIN_OFF;
2856 break;
2857 case DP_TRAINING_PATTERN_1:
2858 *DP |= DP_LINK_TRAIN_PAT_1;
2859 break;
2860 case DP_TRAINING_PATTERN_2:
2861 *DP |= DP_LINK_TRAIN_PAT_2;
2862 break;
2863 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002864 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002865 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2866 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002867 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002868 *DP |= DP_LINK_TRAIN_PAT_2;
2869 }
2870 break;
2871 }
2872 }
2873}
2874
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002875static void intel_dp_enable_port(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002876 const struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002877{
2878 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002879 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002880
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002881 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002882
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002883 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002884
2885 /*
2886 * Magic for VLV/CHV. We _must_ first set up the register
2887 * without actually enabling the port, and then do another
2888 * write to enable the port. Otherwise link training will
2889 * fail when the power sequencer is freshly used for this port.
2890 */
2891 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002892 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002893 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002894
2895 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2896 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002897}
2898
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002899static void intel_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002900 const struct intel_crtc_state *pipe_config,
2901 const struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002902{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002903 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2904 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002905 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002906 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002907 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002908 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002909
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002910 if (WARN_ON(dp_reg & DP_PORT_EN))
2911 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002912
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002913 pps_lock(intel_dp);
2914
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002915 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002916 vlv_init_panel_power_sequencer(intel_dp);
2917
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002918 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002919
2920 edp_panel_vdd_on(intel_dp);
2921 edp_panel_on(intel_dp);
2922 edp_panel_vdd_off(intel_dp, true);
2923
2924 pps_unlock(intel_dp);
2925
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002926 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002927 unsigned int lane_mask = 0x0;
2928
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002929 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002930 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002931
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002932 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2933 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002934 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002935
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002936 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2937 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002938 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002939
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002940 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002941 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002942 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002943 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002944 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002945}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002946
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002947static void g4x_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002948 const struct intel_crtc_state *pipe_config,
2949 const struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002950{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002951 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002952 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002953}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002954
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002955static void vlv_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002956 const struct intel_crtc_state *pipe_config,
2957 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002958{
Jani Nikula828f5c62013-09-05 16:44:45 +03002959 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2960
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002961 intel_edp_backlight_on(pipe_config, conn_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002962 intel_psr_enable(intel_dp, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002963}
2964
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002965static void g4x_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002966 const struct intel_crtc_state *pipe_config,
2967 const struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002968{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002969 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002970 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002971
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002972 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002973
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002974 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002975 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002976 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002977}
2978
Ville Syrjälä83b84592014-10-16 21:29:51 +03002979static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2980{
2981 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002982 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002983 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002984 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002985
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002986 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2987
Ville Syrjäläd1586942017-02-08 19:52:54 +02002988 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2989 return;
2990
Ville Syrjälä83b84592014-10-16 21:29:51 +03002991 edp_panel_vdd_off_sync(intel_dp);
2992
2993 /*
2994 * VLV seems to get confused when multiple power seqeuencers
2995 * have the same port selected (even if only one has power/vdd
2996 * enabled). The failure manifests as vlv_wait_port_ready() failing
2997 * CHV on the other hand doesn't seem to mind having the same port
2998 * selected in multiple power seqeuencers, but let's clear the
2999 * port select always when logically disconnecting a power sequencer
3000 * from a port.
3001 */
3002 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
3003 pipe_name(pipe), port_name(intel_dig_port->port));
3004 I915_WRITE(pp_on_reg, 0);
3005 POSTING_READ(pp_on_reg);
3006
3007 intel_dp->pps_pipe = INVALID_PIPE;
3008}
3009
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003010static void vlv_steal_power_sequencer(struct drm_device *dev,
3011 enum pipe pipe)
3012{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003013 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003014 struct intel_encoder *encoder;
3015
3016 lockdep_assert_held(&dev_priv->pps_mutex);
3017
Jani Nikula19c80542015-12-16 12:48:16 +02003018 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003019 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03003020 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003021
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003022 if (encoder->type != INTEL_OUTPUT_DP &&
3023 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003024 continue;
3025
3026 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03003027 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003028
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003029 WARN(intel_dp->active_pipe == pipe,
3030 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3031 pipe_name(pipe), port_name(port));
3032
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003033 if (intel_dp->pps_pipe != pipe)
3034 continue;
3035
3036 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03003037 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003038
3039 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003040 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003041 }
3042}
3043
3044static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
3045{
3046 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3047 struct intel_encoder *encoder = &intel_dig_port->base;
3048 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003049 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003050 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003051
3052 lockdep_assert_held(&dev_priv->pps_mutex);
3053
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003054 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003055
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003056 if (intel_dp->pps_pipe != INVALID_PIPE &&
3057 intel_dp->pps_pipe != crtc->pipe) {
3058 /*
3059 * If another power sequencer was being used on this
3060 * port previously make sure to turn off vdd there while
3061 * we still have control of it.
3062 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003063 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003064 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003065
3066 /*
3067 * We may be stealing the power
3068 * sequencer from another port.
3069 */
3070 vlv_steal_power_sequencer(dev, crtc->pipe);
3071
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003072 intel_dp->active_pipe = crtc->pipe;
3073
Jani Nikula1853a9d2017-08-18 12:30:20 +03003074 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003075 return;
3076
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003077 /* now it's all ours */
3078 intel_dp->pps_pipe = crtc->pipe;
3079
3080 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3081 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3082
3083 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003084 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003085 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003086}
3087
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003088static void vlv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003089 const struct intel_crtc_state *pipe_config,
3090 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003091{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003092 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003093
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003094 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003095}
3096
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003097static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003098 const struct intel_crtc_state *pipe_config,
3099 const struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003100{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003101 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003102
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003103 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003104}
3105
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003106static void chv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003107 const struct intel_crtc_state *pipe_config,
3108 const struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003109{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003110 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003111
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003112 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003113
3114 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003115 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003116}
3117
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003118static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003119 const struct intel_crtc_state *pipe_config,
3120 const struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003121{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003122 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003123
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003124 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003125}
3126
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003127static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003128 const struct intel_crtc_state *pipe_config,
3129 const struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003130{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003131 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003132}
3133
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003134/*
3135 * Fetch AUX CH registers 0x202 - 0x207 which contain
3136 * link status information
3137 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003138bool
Keith Packard93f62da2011-11-01 19:45:03 -07003139intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003140{
Lyude9f085eb2016-04-13 10:58:33 -04003141 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3142 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003143}
3144
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303145static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3146{
3147 uint8_t psr_caps = 0;
3148
Imre Deak9bacd4b2017-05-10 12:21:48 +03003149 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3150 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303151 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3152}
3153
3154static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3155{
3156 uint8_t dprx = 0;
3157
Imre Deak9bacd4b2017-05-10 12:21:48 +03003158 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3159 &dprx) != 1)
3160 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303161 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3162}
3163
Chris Wilsona76f73d2017-01-14 10:51:13 +00003164static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303165{
3166 uint8_t alpm_caps = 0;
3167
Imre Deak9bacd4b2017-05-10 12:21:48 +03003168 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3169 &alpm_caps) != 1)
3170 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303171 return alpm_caps & DP_ALPM_CAP;
3172}
3173
Paulo Zanoni11002442014-06-13 18:45:41 -03003174/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003175uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003176intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003177{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003178 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003179 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003180
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03003181 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003182 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3183 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003184 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003186 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303187 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003188 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303189 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003190 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003192}
3193
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003194uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003195intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3196{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003197 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003198 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003199
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003200 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003201 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3202 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3203 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3205 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3206 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3207 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3209 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003210 default:
3211 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3212 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003213 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003214 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3216 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3217 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3218 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3220 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3221 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003222 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303223 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003224 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003225 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003226 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303227 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3228 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3229 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3230 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3231 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3232 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3233 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003234 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003237 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003238 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303239 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3240 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3241 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3242 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3243 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003244 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303245 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003246 }
3247 } else {
3248 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303249 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3250 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3251 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3252 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3254 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3255 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003256 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303257 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003258 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003259 }
3260}
3261
Daniel Vetter5829975c2015-04-16 11:36:52 +02003262static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003263{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003264 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003265 unsigned long demph_reg_value, preemph_reg_value,
3266 uniqtranscale_reg_value;
3267 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003268
3269 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303270 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003271 preemph_reg_value = 0x0004000;
3272 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303273 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003274 demph_reg_value = 0x2B405555;
3275 uniqtranscale_reg_value = 0x552AB83A;
3276 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303277 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003278 demph_reg_value = 0x2B404040;
3279 uniqtranscale_reg_value = 0x5548B83A;
3280 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003282 demph_reg_value = 0x2B245555;
3283 uniqtranscale_reg_value = 0x5560B83A;
3284 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003286 demph_reg_value = 0x2B405555;
3287 uniqtranscale_reg_value = 0x5598DA3A;
3288 break;
3289 default:
3290 return 0;
3291 }
3292 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003294 preemph_reg_value = 0x0002000;
3295 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303296 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003297 demph_reg_value = 0x2B404040;
3298 uniqtranscale_reg_value = 0x5552B83A;
3299 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303300 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003301 demph_reg_value = 0x2B404848;
3302 uniqtranscale_reg_value = 0x5580B83A;
3303 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303304 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003305 demph_reg_value = 0x2B404040;
3306 uniqtranscale_reg_value = 0x55ADDA3A;
3307 break;
3308 default:
3309 return 0;
3310 }
3311 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003313 preemph_reg_value = 0x0000000;
3314 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303315 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003316 demph_reg_value = 0x2B305555;
3317 uniqtranscale_reg_value = 0x5570B83A;
3318 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003320 demph_reg_value = 0x2B2B4040;
3321 uniqtranscale_reg_value = 0x55ADDA3A;
3322 break;
3323 default:
3324 return 0;
3325 }
3326 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303327 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003328 preemph_reg_value = 0x0006000;
3329 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303330 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003331 demph_reg_value = 0x1B405555;
3332 uniqtranscale_reg_value = 0x55ADDA3A;
3333 break;
3334 default:
3335 return 0;
3336 }
3337 break;
3338 default:
3339 return 0;
3340 }
3341
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003342 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3343 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003344
3345 return 0;
3346}
3347
Daniel Vetter5829975c2015-04-16 11:36:52 +02003348static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003349{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003350 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3351 u32 deemph_reg_value, margin_reg_value;
3352 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003353 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003354
3355 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303356 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003357 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303358 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003359 deemph_reg_value = 128;
3360 margin_reg_value = 52;
3361 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303362 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003363 deemph_reg_value = 128;
3364 margin_reg_value = 77;
3365 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303366 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003367 deemph_reg_value = 128;
3368 margin_reg_value = 102;
3369 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303370 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003371 deemph_reg_value = 128;
3372 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003373 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003374 break;
3375 default:
3376 return 0;
3377 }
3378 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003380 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303381 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003382 deemph_reg_value = 85;
3383 margin_reg_value = 78;
3384 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303385 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003386 deemph_reg_value = 85;
3387 margin_reg_value = 116;
3388 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303389 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003390 deemph_reg_value = 85;
3391 margin_reg_value = 154;
3392 break;
3393 default:
3394 return 0;
3395 }
3396 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303397 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003398 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303399 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003400 deemph_reg_value = 64;
3401 margin_reg_value = 104;
3402 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303403 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003404 deemph_reg_value = 64;
3405 margin_reg_value = 154;
3406 break;
3407 default:
3408 return 0;
3409 }
3410 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303411 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003412 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303413 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003414 deemph_reg_value = 43;
3415 margin_reg_value = 154;
3416 break;
3417 default:
3418 return 0;
3419 }
3420 break;
3421 default:
3422 return 0;
3423 }
3424
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003425 chv_set_phy_signal_level(encoder, deemph_reg_value,
3426 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003427
3428 return 0;
3429}
3430
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003431static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003432gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003433{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003434 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003435
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003436 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303437 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003438 default:
3439 signal_levels |= DP_VOLTAGE_0_4;
3440 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303441 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003442 signal_levels |= DP_VOLTAGE_0_6;
3443 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303444 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003445 signal_levels |= DP_VOLTAGE_0_8;
3446 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303447 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003448 signal_levels |= DP_VOLTAGE_1_2;
3449 break;
3450 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003451 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303452 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003453 default:
3454 signal_levels |= DP_PRE_EMPHASIS_0;
3455 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303456 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003457 signal_levels |= DP_PRE_EMPHASIS_3_5;
3458 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303459 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003460 signal_levels |= DP_PRE_EMPHASIS_6;
3461 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303462 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003463 signal_levels |= DP_PRE_EMPHASIS_9_5;
3464 break;
3465 }
3466 return signal_levels;
3467}
3468
Zhenyu Wange3421a12010-04-08 09:43:27 +08003469/* Gen6's DP voltage swing and pre-emphasis control */
3470static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003471gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003472{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003473 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3474 DP_TRAIN_PRE_EMPHASIS_MASK);
3475 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303476 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3477 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003478 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003480 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303481 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3482 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003483 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303484 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3485 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003486 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303487 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3488 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003489 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003490 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003491 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3492 "0x%x\n", signal_levels);
3493 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003494 }
3495}
3496
Keith Packard1a2eb462011-11-16 16:26:07 -08003497/* Gen7's DP voltage swing and pre-emphasis control */
3498static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003499gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003500{
3501 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3502 DP_TRAIN_PRE_EMPHASIS_MASK);
3503 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303504 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003505 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303506 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003507 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303508 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003509 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3510
Sonika Jindalbd600182014-08-08 16:23:41 +05303511 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003512 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303513 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003514 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3515
Sonika Jindalbd600182014-08-08 16:23:41 +05303516 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003517 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303518 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003519 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3520
3521 default:
3522 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3523 "0x%x\n", signal_levels);
3524 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3525 }
3526}
3527
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003528void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003529intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003530{
3531 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003532 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003533 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003534 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003535 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003536 uint8_t train_set = intel_dp->train_set[0];
3537
Rodrigo Vivid509af62017-08-29 16:22:24 -07003538 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3539 signal_levels = bxt_signal_levels(intel_dp);
3540 } else if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003541 signal_levels = ddi_signal_levels(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07003542 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003543 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003544 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003545 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003546 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003547 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003548 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003549 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003550 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003551 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003552 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3553 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003554 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003555 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3556 }
3557
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303558 if (mask)
3559 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3560
3561 DRM_DEBUG_KMS("Using vswing level %d\n",
3562 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3563 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3564 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3565 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003566
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003567 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003568
3569 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3570 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003571}
3572
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003573void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003574intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3575 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003576{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003577 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003578 struct drm_i915_private *dev_priv =
3579 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003580
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003581 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003582
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003583 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003584 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003585}
3586
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003587void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003588{
3589 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3590 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003591 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003592 enum port port = intel_dig_port->port;
3593 uint32_t val;
3594
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003595 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003596 return;
3597
3598 val = I915_READ(DP_TP_CTL(port));
3599 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3600 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3601 I915_WRITE(DP_TP_CTL(port), val);
3602
3603 /*
3604 * On PORT_A we can have only eDP in SST mode. There the only reason
3605 * we need to set idle transmission mode is to work around a HW issue
3606 * where we enable the pipe while not in idle link-training mode.
3607 * In this case there is requirement to wait for a minimum number of
3608 * idle patterns to be sent.
3609 */
3610 if (port == PORT_A)
3611 return;
3612
Chris Wilsona7670172016-06-30 15:33:10 +01003613 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3614 DP_TP_STATUS_IDLE_DONE,
3615 DP_TP_STATUS_IDLE_DONE,
3616 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003617 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3618}
3619
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003620static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003621intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003622{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003623 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003624 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003625 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003626 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003627 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003628 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003629
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003630 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003631 return;
3632
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003633 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003634 return;
3635
Zhao Yakui28c97732009-10-09 11:39:41 +08003636 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003637
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003638 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003639 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003640 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003641 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003642 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003643 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003644 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3645 else
3646 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003647 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003648 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003649 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003650 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003651
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003652 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3653 I915_WRITE(intel_dp->output_reg, DP);
3654 POSTING_READ(intel_dp->output_reg);
3655
3656 /*
3657 * HW workaround for IBX, we need to move the port
3658 * to transcoder A after disabling it to allow the
3659 * matching HDMI port to be enabled on transcoder A.
3660 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003661 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003662 /*
3663 * We get CPU/PCH FIFO underruns on the other pipe when
3664 * doing the workaround. Sweep them under the rug.
3665 */
3666 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3667 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3668
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003669 /* always enable with pattern 1 (as per spec) */
3670 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3671 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3672 I915_WRITE(intel_dp->output_reg, DP);
3673 POSTING_READ(intel_dp->output_reg);
3674
3675 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003676 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003677 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003678
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003679 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003680 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3681 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003682 }
3683
Keith Packardf01eca22011-09-28 16:48:10 -07003684 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003685
3686 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003687
3688 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3689 pps_lock(intel_dp);
3690 intel_dp->active_pipe = INVALID_PIPE;
3691 pps_unlock(intel_dp);
3692 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003693}
3694
Imre Deak24e807e2016-10-24 19:33:28 +03003695bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003696intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003697{
Lyude9f085eb2016-04-13 10:58:33 -04003698 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3699 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003700 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003701
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003702 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003703
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003704 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3705}
3706
3707static bool
3708intel_edp_init_dpcd(struct intel_dp *intel_dp)
3709{
3710 struct drm_i915_private *dev_priv =
3711 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3712
3713 /* this function is meant to be called only once */
3714 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3715
3716 if (!intel_dp_read_dpcd(intel_dp))
3717 return false;
3718
Jani Nikula84c36752017-05-18 14:10:23 +03003719 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3720 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003721
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003722 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3723 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3724 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3725
3726 /* Check if the panel supports PSR */
3727 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3728 intel_dp->psr_dpcd,
3729 sizeof(intel_dp->psr_dpcd));
3730 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3731 dev_priv->psr.sink_support = true;
3732 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3733 }
3734
3735 if (INTEL_GEN(dev_priv) >= 9 &&
3736 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3737 uint8_t frame_sync_cap;
3738
3739 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003740 if (drm_dp_dpcd_readb(&intel_dp->aux,
3741 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3742 &frame_sync_cap) != 1)
3743 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003744 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3745 /* PSR2 needs frame sync as well */
3746 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3747 DRM_DEBUG_KMS("PSR2 %s on sink",
3748 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303749
3750 if (dev_priv->psr.psr2_support) {
3751 dev_priv->psr.y_cord_support =
3752 intel_dp_get_y_cord_status(intel_dp);
3753 dev_priv->psr.colorimetry_support =
3754 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303755 dev_priv->psr.alpm =
3756 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303757 }
3758
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003759 }
3760
Jani Nikula0501a3b2017-10-26 17:29:31 +03003761 /*
3762 * Read the eDP display control registers.
3763 *
3764 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3765 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3766 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3767 * method). The display control registers should read zero if they're
3768 * not supported anyway.
3769 */
3770 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003771 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3772 sizeof(intel_dp->edp_dpcd))
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003773 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003774 intel_dp->edp_dpcd);
3775
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003776 /* Read the eDP 1.4+ supported link rates. */
3777 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003778 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3779 int i;
3780
3781 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3782 sink_rates, sizeof(sink_rates));
3783
3784 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3785 int val = le16_to_cpu(sink_rates[i]);
3786
3787 if (val == 0)
3788 break;
3789
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003790 /* Value read multiplied by 200kHz gives the per-lane
3791 * link rate in kHz. The source rates are, however,
3792 * stored in terms of LS_Clk kHz. The full conversion
3793 * back to symbols is
3794 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3795 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003796 intel_dp->sink_rates[i] = (val * 200) / 10;
3797 }
3798 intel_dp->num_sink_rates = i;
3799 }
3800
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003801 /*
3802 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3803 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3804 */
Jani Nikula68f357c2017-03-28 17:59:05 +03003805 if (intel_dp->num_sink_rates)
3806 intel_dp->use_rate_select = true;
3807 else
3808 intel_dp_set_sink_rates(intel_dp);
3809
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003810 intel_dp_set_common_rates(intel_dp);
3811
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003812 return true;
3813}
3814
3815
3816static bool
3817intel_dp_get_dpcd(struct intel_dp *intel_dp)
3818{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003819 u8 sink_count;
3820
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003821 if (!intel_dp_read_dpcd(intel_dp))
3822 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003823
Jani Nikula68f357c2017-03-28 17:59:05 +03003824 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003825 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003826 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003827 intel_dp_set_common_rates(intel_dp);
3828 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003829
Jani Nikula27dbefb2017-04-06 16:44:17 +03003830 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303831 return false;
3832
3833 /*
3834 * Sink count can change between short pulse hpd hence
3835 * a member variable in intel_dp will track any changes
3836 * between short pulse interrupts.
3837 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003838 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303839
3840 /*
3841 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3842 * a dongle is present but no display. Unless we require to know
3843 * if a dongle is present or not, we don't need to update
3844 * downstream port information. So, an early return here saves
3845 * time from performing other operations which are not required.
3846 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003847 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303848 return false;
3849
Imre Deakc726ad02016-10-24 19:33:24 +03003850 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003851 return true; /* native DP sink */
3852
3853 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3854 return true; /* no per-port downstream info */
3855
Lyude9f085eb2016-04-13 10:58:33 -04003856 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3857 intel_dp->downstream_ports,
3858 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003859 return false; /* downstream port status fetch failed */
3860
3861 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003862}
3863
Dave Airlie0e32b392014-05-02 14:02:48 +10003864static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003865intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003866{
Jani Nikula010b9b32017-04-06 16:44:16 +03003867 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003868
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003869 if (!i915_modparams.enable_dp_mst)
Nathan Schulte7cc96132016-03-15 10:14:05 -05003870 return false;
3871
Dave Airlie0e32b392014-05-02 14:02:48 +10003872 if (!intel_dp->can_mst)
3873 return false;
3874
3875 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3876 return false;
3877
Jani Nikula010b9b32017-04-06 16:44:16 +03003878 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003879 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003880
Jani Nikula010b9b32017-04-06 16:44:16 +03003881 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003882}
3883
3884static void
3885intel_dp_configure_mst(struct intel_dp *intel_dp)
3886{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003887 if (!i915_modparams.enable_dp_mst)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003888 return;
3889
3890 if (!intel_dp->can_mst)
3891 return;
3892
3893 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3894
3895 if (intel_dp->is_mst)
3896 DRM_DEBUG_KMS("Sink is MST capable\n");
3897 else
3898 DRM_DEBUG_KMS("Sink is not MST capable\n");
3899
3900 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3901 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003902}
3903
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003904static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003905{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003906 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003907 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003908 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003909 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003910 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003911 int count = 0;
3912 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003913
3914 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003915 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003916 ret = -EIO;
3917 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003918 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003919
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003920 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003921 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003922 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003923 ret = -EIO;
3924 goto out;
3925 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003926
Rodrigo Vivic6297842015-11-05 10:50:20 -08003927 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003928 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003929
3930 if (drm_dp_dpcd_readb(&intel_dp->aux,
3931 DP_TEST_SINK_MISC, &buf) < 0) {
3932 ret = -EIO;
3933 goto out;
3934 }
3935 count = buf & DP_TEST_COUNT_MASK;
3936 } while (--attempts && count);
3937
3938 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003939 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003940 ret = -ETIMEDOUT;
3941 }
3942
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003943 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003944 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003945 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003946}
3947
3948static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3949{
3950 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003951 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003952 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3953 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003954 int ret;
3955
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003956 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3957 return -EIO;
3958
3959 if (!(buf & DP_TEST_CRC_SUPPORTED))
3960 return -ENOTTY;
3961
3962 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3963 return -EIO;
3964
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003965 if (buf & DP_TEST_SINK_START) {
3966 ret = intel_dp_sink_crc_stop(intel_dp);
3967 if (ret)
3968 return ret;
3969 }
3970
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003971 hsw_disable_ips(intel_crtc);
3972
3973 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3974 buf | DP_TEST_SINK_START) < 0) {
3975 hsw_enable_ips(intel_crtc);
3976 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003977 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003978
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003979 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003980 return 0;
3981}
3982
3983int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3984{
3985 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003986 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003987 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3988 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003989 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003990 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003991
3992 ret = intel_dp_sink_crc_start(intel_dp);
3993 if (ret)
3994 return ret;
3995
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003996 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003997 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003998
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003999 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004000 DP_TEST_SINK_MISC, &buf) < 0) {
4001 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004002 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004003 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004004 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07004005
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004006 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004007
4008 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004009 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4010 ret = -ETIMEDOUT;
4011 goto stop;
4012 }
4013
4014 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4015 ret = -EIO;
4016 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004017 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004018
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004019stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004020 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004021 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004022}
4023
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004024static bool
4025intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4026{
Jani Nikula010b9b32017-04-06 16:44:16 +03004027 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4028 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004029}
4030
Dave Airlie0e32b392014-05-02 14:02:48 +10004031static bool
4032intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4033{
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004034 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4035 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4036 DP_DPRX_ESI_LEN;
Dave Airlie0e32b392014-05-02 14:02:48 +10004037}
4038
Todd Previtec5d5ab72015-04-15 08:38:38 -07004039static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004040{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004041 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004042 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004043 uint8_t test_lane_count, test_link_bw;
4044 /* (DP CTS 1.2)
4045 * 4.3.1.11
4046 */
4047 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4048 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4049 &test_lane_count);
4050
4051 if (status <= 0) {
4052 DRM_DEBUG_KMS("Lane count read failed\n");
4053 return DP_TEST_NAK;
4054 }
4055 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004056
4057 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4058 &test_link_bw);
4059 if (status <= 0) {
4060 DRM_DEBUG_KMS("Link Rate read failed\n");
4061 return DP_TEST_NAK;
4062 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004063 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004064
4065 /* Validate the requested link rate and lane count */
4066 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4067 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004068 return DP_TEST_NAK;
4069
4070 intel_dp->compliance.test_lane_count = test_lane_count;
4071 intel_dp->compliance.test_link_rate = test_link_rate;
4072
4073 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004074}
4075
4076static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4077{
Manasi Navare611032b2017-01-24 08:21:49 -08004078 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004079 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004080 __be16 h_width, v_height;
4081 int status = 0;
4082
4083 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004084 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4085 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004086 if (status <= 0) {
4087 DRM_DEBUG_KMS("Test pattern read failed\n");
4088 return DP_TEST_NAK;
4089 }
4090 if (test_pattern != DP_COLOR_RAMP)
4091 return DP_TEST_NAK;
4092
4093 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4094 &h_width, 2);
4095 if (status <= 0) {
4096 DRM_DEBUG_KMS("H Width read failed\n");
4097 return DP_TEST_NAK;
4098 }
4099
4100 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4101 &v_height, 2);
4102 if (status <= 0) {
4103 DRM_DEBUG_KMS("V Height read failed\n");
4104 return DP_TEST_NAK;
4105 }
4106
Jani Nikula010b9b32017-04-06 16:44:16 +03004107 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4108 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004109 if (status <= 0) {
4110 DRM_DEBUG_KMS("TEST MISC read failed\n");
4111 return DP_TEST_NAK;
4112 }
4113 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4114 return DP_TEST_NAK;
4115 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4116 return DP_TEST_NAK;
4117 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4118 case DP_TEST_BIT_DEPTH_6:
4119 intel_dp->compliance.test_data.bpc = 6;
4120 break;
4121 case DP_TEST_BIT_DEPTH_8:
4122 intel_dp->compliance.test_data.bpc = 8;
4123 break;
4124 default:
4125 return DP_TEST_NAK;
4126 }
4127
4128 intel_dp->compliance.test_data.video_pattern = test_pattern;
4129 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4130 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4131 /* Set test active flag here so userspace doesn't interrupt things */
4132 intel_dp->compliance.test_active = 1;
4133
4134 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004135}
4136
4137static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4138{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004139 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004140 struct intel_connector *intel_connector = intel_dp->attached_connector;
4141 struct drm_connector *connector = &intel_connector->base;
4142
4143 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004144 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004145 intel_dp->aux.i2c_defer_count > 6) {
4146 /* Check EDID read for NACKs, DEFERs and corruption
4147 * (DP CTS 1.2 Core r1.1)
4148 * 4.2.2.4 : Failed EDID read, I2C_NAK
4149 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4150 * 4.2.2.6 : EDID corruption detected
4151 * Use failsafe mode for all cases
4152 */
4153 if (intel_dp->aux.i2c_nack_count > 0 ||
4154 intel_dp->aux.i2c_defer_count > 0)
4155 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4156 intel_dp->aux.i2c_nack_count,
4157 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004158 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004159 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304160 struct edid *block = intel_connector->detect_edid;
4161
4162 /* We have to write the checksum
4163 * of the last block read
4164 */
4165 block += intel_connector->detect_edid->extensions;
4166
Jani Nikula010b9b32017-04-06 16:44:16 +03004167 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4168 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004169 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4170
4171 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004172 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004173 }
4174
4175 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004176 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004177
Todd Previtec5d5ab72015-04-15 08:38:38 -07004178 return test_result;
4179}
4180
4181static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4182{
4183 uint8_t test_result = DP_TEST_NAK;
4184 return test_result;
4185}
4186
4187static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4188{
4189 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004190 uint8_t request = 0;
4191 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004192
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004193 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004194 if (status <= 0) {
4195 DRM_DEBUG_KMS("Could not read test request from sink\n");
4196 goto update_status;
4197 }
4198
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004199 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004200 case DP_TEST_LINK_TRAINING:
4201 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004202 response = intel_dp_autotest_link_training(intel_dp);
4203 break;
4204 case DP_TEST_LINK_VIDEO_PATTERN:
4205 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004206 response = intel_dp_autotest_video_pattern(intel_dp);
4207 break;
4208 case DP_TEST_LINK_EDID_READ:
4209 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004210 response = intel_dp_autotest_edid(intel_dp);
4211 break;
4212 case DP_TEST_LINK_PHY_TEST_PATTERN:
4213 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004214 response = intel_dp_autotest_phy_pattern(intel_dp);
4215 break;
4216 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004217 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004218 break;
4219 }
4220
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004221 if (response & DP_TEST_ACK)
4222 intel_dp->compliance.test_type = request;
4223
Todd Previtec5d5ab72015-04-15 08:38:38 -07004224update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004225 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004226 if (status <= 0)
4227 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004228}
4229
Dave Airlie0e32b392014-05-02 14:02:48 +10004230static int
4231intel_dp_check_mst_status(struct intel_dp *intel_dp)
4232{
4233 bool bret;
4234
4235 if (intel_dp->is_mst) {
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004236 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
Dave Airlie0e32b392014-05-02 14:02:48 +10004237 int ret = 0;
4238 int retry;
4239 bool handled;
4240 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4241go_again:
4242 if (bret == true) {
4243
4244 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004245 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004246 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004247 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4248 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004249 intel_dp_stop_link_train(intel_dp);
4250 }
4251
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004252 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004253 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4254
4255 if (handled) {
4256 for (retry = 0; retry < 3; retry++) {
4257 int wret;
4258 wret = drm_dp_dpcd_write(&intel_dp->aux,
4259 DP_SINK_COUNT_ESI+1,
4260 &esi[1], 3);
4261 if (wret == 3) {
4262 break;
4263 }
4264 }
4265
4266 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4267 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004268 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004269 goto go_again;
4270 }
4271 } else
4272 ret = 0;
4273
4274 return ret;
4275 } else {
4276 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4277 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4278 intel_dp->is_mst = false;
4279 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4280 /* send a hotplug event */
4281 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4282 }
4283 }
4284 return -EINVAL;
4285}
4286
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304287static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004288intel_dp_retrain_link(struct intel_dp *intel_dp)
4289{
4290 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4291 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4292 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4293
4294 /* Suppress underruns caused by re-training */
4295 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4296 if (crtc->config->has_pch_encoder)
4297 intel_set_pch_fifo_underrun_reporting(dev_priv,
4298 intel_crtc_pch_transcoder(crtc), false);
4299
4300 intel_dp_start_link_train(intel_dp);
4301 intel_dp_stop_link_train(intel_dp);
4302
4303 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004304 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004305
4306 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4307 if (crtc->config->has_pch_encoder)
4308 intel_set_pch_fifo_underrun_reporting(dev_priv,
4309 intel_crtc_pch_transcoder(crtc), true);
4310}
4311
4312static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304313intel_dp_check_link_status(struct intel_dp *intel_dp)
4314{
4315 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4316 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4317 u8 link_status[DP_LINK_STATUS_SIZE];
4318
4319 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4320
4321 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4322 DRM_ERROR("Failed to get link status\n");
4323 return;
4324 }
4325
4326 if (!intel_encoder->base.crtc)
4327 return;
4328
4329 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4330 return;
4331
Manasi Navare14c562c2017-04-06 14:00:12 -07004332 /*
4333 * Validate the cached values of intel_dp->link_rate and
4334 * intel_dp->lane_count before attempting to retrain.
4335 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004336 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4337 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004338 return;
4339
Manasi Navareda15f7c2017-01-24 08:16:34 -08004340 /* Retrain if Channel EQ or CR not ok */
4341 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304342 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4343 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004344
4345 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304346 }
4347}
4348
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004349/*
4350 * According to DP spec
4351 * 5.1.2:
4352 * 1. Read DPCD
4353 * 2. Configure link according to Receiver Capabilities
4354 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4355 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304356 *
4357 * intel_dp_short_pulse - handles short pulse interrupts
4358 * when full detection is not required.
4359 * Returns %true if short pulse is handled and full detection
4360 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004361 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304362static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304363intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004364{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004365 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004366 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004367 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304368 u8 old_sink_count = intel_dp->sink_count;
4369 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004370
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304371 /*
4372 * Clearing compliance test variables to allow capturing
4373 * of values for next automated test request.
4374 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004375 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304376
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304377 /*
4378 * Now read the DPCD to see if it's actually running
4379 * If the current value of sink count doesn't match with
4380 * the value that was stored earlier or dpcd read failed
4381 * we need to do full detection
4382 */
4383 ret = intel_dp_get_dpcd(intel_dp);
4384
4385 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4386 /* No need to proceed if we are going to do full detect */
4387 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004388 }
4389
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004390 /* Try to read the source of the interrupt */
4391 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004392 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4393 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004394 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004395 drm_dp_dpcd_writeb(&intel_dp->aux,
4396 DP_DEVICE_SERVICE_IRQ_VECTOR,
4397 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004398
4399 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004400 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004401 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4402 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4403 }
4404
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304405 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4406 intel_dp_check_link_status(intel_dp);
4407 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004408 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4409 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4410 /* Send a Hotplug Uevent to userspace to start modeset */
4411 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4412 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304413
4414 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004415}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004416
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004417/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004418static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004419intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004420{
Imre Deake393d0d2017-02-22 17:10:52 +02004421 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004422 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004423 uint8_t type;
4424
Imre Deake393d0d2017-02-22 17:10:52 +02004425 if (lspcon->active)
4426 lspcon_resume(lspcon);
4427
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004428 if (!intel_dp_get_dpcd(intel_dp))
4429 return connector_status_disconnected;
4430
Jani Nikula1853a9d2017-08-18 12:30:20 +03004431 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304432 return connector_status_connected;
4433
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004434 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004435 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004436 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004437
4438 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004439 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4440 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004441
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304442 return intel_dp->sink_count ?
4443 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004444 }
4445
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004446 if (intel_dp_can_mst(intel_dp))
4447 return connector_status_connected;
4448
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004449 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004450 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004451 return connector_status_connected;
4452
4453 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004454 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4455 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4456 if (type == DP_DS_PORT_TYPE_VGA ||
4457 type == DP_DS_PORT_TYPE_NON_EDID)
4458 return connector_status_unknown;
4459 } else {
4460 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4461 DP_DWN_STRM_PORT_TYPE_MASK;
4462 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4463 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4464 return connector_status_unknown;
4465 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004466
4467 /* Anything else is out of spec, warn and ignore */
4468 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004469 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004470}
4471
4472static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004473edp_detect(struct intel_dp *intel_dp)
4474{
4475 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004476 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004477 enum drm_connector_status status;
4478
Mika Kahola1650be72016-12-13 10:02:47 +02004479 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004480 if (status == connector_status_unknown)
4481 status = connector_status_connected;
4482
4483 return status;
4484}
4485
Jani Nikulab93433c2015-08-20 10:47:36 +03004486static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4487 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004488{
Jani Nikulab93433c2015-08-20 10:47:36 +03004489 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004490
Jani Nikula0df53b72015-08-20 10:47:40 +03004491 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004492 case PORT_B:
4493 bit = SDE_PORTB_HOTPLUG;
4494 break;
4495 case PORT_C:
4496 bit = SDE_PORTC_HOTPLUG;
4497 break;
4498 case PORT_D:
4499 bit = SDE_PORTD_HOTPLUG;
4500 break;
4501 default:
4502 MISSING_CASE(port->port);
4503 return false;
4504 }
4505
4506 return I915_READ(SDEISR) & bit;
4507}
4508
4509static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4510 struct intel_digital_port *port)
4511{
4512 u32 bit;
4513
4514 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004515 case PORT_B:
4516 bit = SDE_PORTB_HOTPLUG_CPT;
4517 break;
4518 case PORT_C:
4519 bit = SDE_PORTC_HOTPLUG_CPT;
4520 break;
4521 case PORT_D:
4522 bit = SDE_PORTD_HOTPLUG_CPT;
4523 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004524 default:
4525 MISSING_CASE(port->port);
4526 return false;
4527 }
4528
4529 return I915_READ(SDEISR) & bit;
4530}
4531
4532static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4533 struct intel_digital_port *port)
4534{
4535 u32 bit;
4536
4537 switch (port->port) {
4538 case PORT_A:
4539 bit = SDE_PORTA_HOTPLUG_SPT;
4540 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004541 case PORT_E:
4542 bit = SDE_PORTE_HOTPLUG_SPT;
4543 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004544 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004545 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004546 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004547
Jani Nikulab93433c2015-08-20 10:47:36 +03004548 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004549}
4550
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004551static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004552 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004553{
Jani Nikula9642c812015-08-20 10:47:41 +03004554 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004555
Jani Nikula9642c812015-08-20 10:47:41 +03004556 switch (port->port) {
4557 case PORT_B:
4558 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4559 break;
4560 case PORT_C:
4561 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4562 break;
4563 case PORT_D:
4564 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4565 break;
4566 default:
4567 MISSING_CASE(port->port);
4568 return false;
4569 }
4570
4571 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4572}
4573
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004574static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4575 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004576{
4577 u32 bit;
4578
4579 switch (port->port) {
4580 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004581 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004582 break;
4583 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004584 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004585 break;
4586 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004587 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004588 break;
4589 default:
4590 MISSING_CASE(port->port);
4591 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004592 }
4593
Jani Nikula1d245982015-08-20 10:47:37 +03004594 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004595}
4596
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004597static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4598 struct intel_digital_port *port)
4599{
4600 if (port->port == PORT_A)
4601 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4602 else
4603 return ibx_digital_port_connected(dev_priv, port);
4604}
4605
4606static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4607 struct intel_digital_port *port)
4608{
4609 if (port->port == PORT_A)
4610 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4611 else
4612 return cpt_digital_port_connected(dev_priv, port);
4613}
4614
4615static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4616 struct intel_digital_port *port)
4617{
4618 if (port->port == PORT_A)
4619 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4620 else
4621 return cpt_digital_port_connected(dev_priv, port);
4622}
4623
4624static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4625 struct intel_digital_port *port)
4626{
4627 if (port->port == PORT_A)
4628 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4629 else
4630 return cpt_digital_port_connected(dev_priv, port);
4631}
4632
Jani Nikulae464bfd2015-08-20 10:47:42 +03004633static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304634 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004635{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304636 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4637 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004638 u32 bit;
4639
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07004640 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304641 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004642 case PORT_A:
4643 bit = BXT_DE_PORT_HP_DDIA;
4644 break;
4645 case PORT_B:
4646 bit = BXT_DE_PORT_HP_DDIB;
4647 break;
4648 case PORT_C:
4649 bit = BXT_DE_PORT_HP_DDIC;
4650 break;
4651 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304652 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004653 return false;
4654 }
4655
4656 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4657}
4658
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004659/*
4660 * intel_digital_port_connected - is the specified port connected?
4661 * @dev_priv: i915 private structure
4662 * @port: the port to test
4663 *
4664 * Return %true if @port is connected, %false otherwise.
4665 */
Imre Deak390b4e02017-01-27 11:39:19 +02004666bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4667 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004668{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004669 if (HAS_GMCH_DISPLAY(dev_priv)) {
4670 if (IS_GM45(dev_priv))
4671 return gm45_digital_port_connected(dev_priv, port);
4672 else
4673 return g4x_digital_port_connected(dev_priv, port);
4674 }
4675
4676 if (IS_GEN5(dev_priv))
4677 return ilk_digital_port_connected(dev_priv, port);
4678 else if (IS_GEN6(dev_priv))
4679 return snb_digital_port_connected(dev_priv, port);
4680 else if (IS_GEN7(dev_priv))
4681 return ivb_digital_port_connected(dev_priv, port);
4682 else if (IS_GEN8(dev_priv))
4683 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004684 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004685 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004686 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004687 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004688}
4689
Keith Packard8c241fe2011-09-28 16:38:44 -07004690static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004691intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004692{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004693 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004694
Jani Nikula9cd300e2012-10-19 14:51:52 +03004695 /* use cached edid if we have one */
4696 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004697 /* invalid edid */
4698 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004699 return NULL;
4700
Jani Nikula55e9ede2013-10-01 10:38:54 +03004701 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004702 } else
4703 return drm_get_edid(&intel_connector->base,
4704 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004705}
4706
Chris Wilsonbeb60602014-09-02 20:04:00 +01004707static void
4708intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004709{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004710 struct intel_connector *intel_connector = intel_dp->attached_connector;
4711 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004712
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304713 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004714 edid = intel_dp_get_edid(intel_dp);
4715 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004716
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004717 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004718}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004719
Chris Wilsonbeb60602014-09-02 20:04:00 +01004720static void
4721intel_dp_unset_edid(struct intel_dp *intel_dp)
4722{
4723 struct intel_connector *intel_connector = intel_dp->attached_connector;
4724
4725 kfree(intel_connector->detect_edid);
4726 intel_connector->detect_edid = NULL;
4727
4728 intel_dp->has_audio = false;
4729}
4730
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004731static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304732intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004733{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304734 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004735 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004736 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4737 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004738 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004739 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004740 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004741
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004742 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4743
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004744 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004745
Chris Wilsond410b562014-09-02 20:03:59 +01004746 /* Can't disconnect eDP, but you can close the lid... */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004747 if (intel_dp_is_edp(intel_dp))
Chris Wilsond410b562014-09-02 20:03:59 +01004748 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004749 else if (intel_digital_port_connected(to_i915(dev),
4750 dp_to_dig_port(intel_dp)))
4751 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
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304770 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004771 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304772
Manasi Navared7e8ef02017-02-07 16:54:11 -08004773 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004774 /* Initial max link lane count */
4775 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004776
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004777 /* Initial max link rate */
4778 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004779
4780 intel_dp->reset_link_params = false;
4781 }
Manasi Navaref4829842016-12-05 16:27:36 -08004782
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004783 intel_dp_print_rates(intel_dp);
4784
Jani Nikula84c36752017-05-18 14:10:23 +03004785 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4786 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004787
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004788 intel_dp_configure_mst(intel_dp);
4789
4790 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304791 /*
4792 * If we are in MST mode then this connector
4793 * won't appear connected or have anything
4794 * with EDID on it
4795 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004796 status = connector_status_disconnected;
4797 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004798 } else {
4799 /*
4800 * If display is now connected check links status,
4801 * there has been known issues of link loss triggerring
4802 * long pulse.
4803 *
4804 * Some sinks (eg. ASUS PB287Q) seem to perform some
4805 * weird HPD ping pong during modesets. So we can apparently
4806 * end up with HPD going low during a modeset, and then
4807 * going back up soon after. And once that happens we must
4808 * retrain the link to get a picture. That's in case no
4809 * userspace component reacted to intermittent HPD dip.
4810 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304811 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004812 }
4813
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304814 /*
4815 * Clearing NACK and defer counts to get their exact values
4816 * while reading EDID which are required by Compliance tests
4817 * 4.2.2.4 and 4.2.2.5
4818 */
4819 intel_dp->aux.i2c_nack_count = 0;
4820 intel_dp->aux.i2c_defer_count = 0;
4821
Chris Wilsonbeb60602014-09-02 20:04:00 +01004822 intel_dp_set_edid(intel_dp);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004823 if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004824 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304825 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004826
Todd Previte09b1eb12015-04-20 15:27:34 -07004827 /* Try to read the source of the interrupt */
4828 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004829 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4830 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004831 /* Clear interrupt source */
4832 drm_dp_dpcd_writeb(&intel_dp->aux,
4833 DP_DEVICE_SERVICE_IRQ_VECTOR,
4834 sink_irq_vector);
4835
4836 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4837 intel_dp_handle_test_request(intel_dp);
4838 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4839 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4840 }
4841
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004842out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004843 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304844 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304845
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004846 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004847 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304848}
4849
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004850static int
4851intel_dp_detect(struct drm_connector *connector,
4852 struct drm_modeset_acquire_ctx *ctx,
4853 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304854{
4855 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004856 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304857
4858 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4859 connector->base.id, connector->name);
4860
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304861 /* If full detect is not performed yet, do a full detect */
4862 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004863 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304864
4865 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304866
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004867 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004868}
4869
Chris Wilsonbeb60602014-09-02 20:04:00 +01004870static void
4871intel_dp_force(struct drm_connector *connector)
4872{
4873 struct intel_dp *intel_dp = intel_attached_dp(connector);
4874 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004875 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004876
4877 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4878 connector->base.id, connector->name);
4879 intel_dp_unset_edid(intel_dp);
4880
4881 if (connector->status != connector_status_connected)
4882 return;
4883
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004884 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004885
4886 intel_dp_set_edid(intel_dp);
4887
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004888 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004889
4890 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004891 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004892}
4893
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004894static int intel_dp_get_modes(struct drm_connector *connector)
4895{
Jani Nikuladd06f902012-10-19 14:51:50 +03004896 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004897 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004898
Chris Wilsonbeb60602014-09-02 20:04:00 +01004899 edid = intel_connector->detect_edid;
4900 if (edid) {
4901 int ret = intel_connector_update_modes(connector, edid);
4902 if (ret)
4903 return ret;
4904 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004905
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004906 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004907 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004908 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004909 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004910
4911 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004912 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004913 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004914 drm_mode_probed_add(connector, mode);
4915 return 1;
4916 }
4917 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004918
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004919 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004920}
4921
Chris Wilsonf6849602010-09-19 09:29:33 +01004922static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004923intel_dp_connector_register(struct drm_connector *connector)
4924{
4925 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004926 int ret;
4927
4928 ret = intel_connector_register(connector);
4929 if (ret)
4930 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004931
4932 i915_debugfs_connector_add(connector);
4933
4934 DRM_DEBUG_KMS("registering %s bus for %s\n",
4935 intel_dp->aux.name, connector->kdev->kobj.name);
4936
4937 intel_dp->aux.dev = connector->kdev;
4938 return drm_dp_aux_register(&intel_dp->aux);
4939}
4940
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004941static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004942intel_dp_connector_unregister(struct drm_connector *connector)
4943{
4944 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4945 intel_connector_unregister(connector);
4946}
4947
4948static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004949intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004950{
Jani Nikula1d508702012-10-19 14:51:49 +03004951 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004952
Chris Wilson10e972d2014-09-04 21:43:45 +01004953 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004954
Jani Nikula9cd300e2012-10-19 14:51:52 +03004955 if (!IS_ERR_OR_NULL(intel_connector->edid))
4956 kfree(intel_connector->edid);
4957
Jani Nikula1853a9d2017-08-18 12:30:20 +03004958 /*
4959 * Can't call intel_dp_is_edp() since the encoder may have been
4960 * destroyed already.
4961 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004962 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004963 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004964
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004965 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004966 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004967}
4968
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004969void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004970{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004971 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4972 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004973
Dave Airlie0e32b392014-05-02 14:02:48 +10004974 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004975 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004976 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004977 /*
4978 * vdd might still be enabled do to the delayed vdd off.
4979 * Make sure vdd is actually turned off here.
4980 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004981 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004982 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004983 pps_unlock(intel_dp);
4984
Clint Taylor01527b32014-07-07 13:01:46 -07004985 if (intel_dp->edp_notifier.notifier_call) {
4986 unregister_reboot_notifier(&intel_dp->edp_notifier);
4987 intel_dp->edp_notifier.notifier_call = NULL;
4988 }
Keith Packardbd943152011-09-18 23:09:52 -07004989 }
Chris Wilson99681882016-06-20 09:29:17 +01004990
4991 intel_dp_aux_fini(intel_dp);
4992
Imre Deakc8bd0e42014-12-12 17:57:38 +02004993 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004994 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004995}
4996
Imre Deakbf93ba62016-04-18 10:04:21 +03004997void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004998{
4999 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
5000
Jani Nikula1853a9d2017-08-18 12:30:20 +03005001 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03005002 return;
5003
Ville Syrjälä951468f2014-09-04 14:55:31 +03005004 /*
5005 * vdd might still be enabled do to the delayed vdd off.
5006 * Make sure vdd is actually turned off here.
5007 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02005008 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005009 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03005010 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005011 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03005012}
5013
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005014static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
5015{
5016 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5017 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005018 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005019
5020 lockdep_assert_held(&dev_priv->pps_mutex);
5021
5022 if (!edp_have_panel_vdd(intel_dp))
5023 return;
5024
5025 /*
5026 * The VDD bit needs a power domain reference, so if the bit is
5027 * already enabled when we boot or resume, grab this reference and
5028 * schedule a vdd off, so we don't hold on to the reference
5029 * indefinitely.
5030 */
5031 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005032 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005033
5034 edp_panel_vdd_schedule_off(intel_dp);
5035}
5036
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005037static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5038{
5039 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5040
5041 if ((intel_dp->DP & DP_PORT_EN) == 0)
5042 return INVALID_PIPE;
5043
5044 if (IS_CHERRYVIEW(dev_priv))
5045 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5046 else
5047 return PORT_TO_PIPE(intel_dp->DP);
5048}
5049
Imre Deakbf93ba62016-04-18 10:04:21 +03005050void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005051{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005052 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005053 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5054 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005055
5056 if (!HAS_DDI(dev_priv))
5057 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005058
Imre Deakdd75f6d2016-11-21 21:15:05 +02005059 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305060 lspcon_resume(lspcon);
5061
Manasi Navared7e8ef02017-02-07 16:54:11 -08005062 intel_dp->reset_link_params = true;
5063
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005064 pps_lock(intel_dp);
5065
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005066 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5067 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5068
Jani Nikula1853a9d2017-08-18 12:30:20 +03005069 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005070 /* Reinit the power sequencer, in case BIOS did something with it. */
5071 intel_dp_pps_init(encoder->dev, intel_dp);
5072 intel_edp_panel_vdd_sanitize(intel_dp);
5073 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005074
5075 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005076}
5077
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005078static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005079 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005080 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005081 .atomic_get_property = intel_digital_connector_atomic_get_property,
5082 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005083 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005084 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005085 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005086 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005087 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005088};
5089
5090static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005091 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005092 .get_modes = intel_dp_get_modes,
5093 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005094 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005095};
5096
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005097static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005098 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005099 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005100};
5101
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005102enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005103intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5104{
5105 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005106 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005107 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005108 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005109
Takashi Iwai25400582015-11-19 12:09:56 +01005110 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5111 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005112 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005113
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005114 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5115 /*
5116 * vdd off can generate a long pulse on eDP which
5117 * would require vdd on to handle it, and thus we
5118 * would end up in an endless cycle of
5119 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5120 */
5121 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5122 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005123 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005124 }
5125
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005126 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5127 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005128 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005129
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005130 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005131 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005132 intel_dp->detect_done = false;
5133 return IRQ_NONE;
5134 }
5135
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005136 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005137
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005138 if (intel_dp->is_mst) {
5139 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5140 /*
5141 * If we were in MST mode, and device is not
5142 * there, get out of MST mode
5143 */
5144 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5145 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5146 intel_dp->is_mst = false;
5147 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5148 intel_dp->is_mst);
5149 intel_dp->detect_done = false;
5150 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005151 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005152 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005153
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005154 if (!intel_dp->is_mst) {
5155 if (!intel_dp_short_pulse(intel_dp)) {
5156 intel_dp->detect_done = false;
5157 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305158 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005159 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005160
5161 ret = IRQ_HANDLED;
5162
Imre Deak1c767b32014-08-18 14:42:42 +03005163put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005164 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005165
5166 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005167}
5168
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005169/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005170bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005171{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005172 /*
5173 * eDP not supported on g4x. so bail out early just
5174 * for a bit extra safety in case the VBT is bonkers.
5175 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005176 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005177 return false;
5178
Imre Deaka98d9c12016-12-21 12:17:24 +02005179 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005180 return true;
5181
Jani Nikula951d9ef2016-03-16 12:43:31 +02005182 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005183}
5184
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005185static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005186intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5187{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005188 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5189
Chris Wilson3f43c482011-05-12 22:17:24 +01005190 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005191 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005192
Jani Nikula1853a9d2017-08-18 12:30:20 +03005193 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005194 u32 allowed_scalers;
5195
5196 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5197 if (!HAS_GMCH_DISPLAY(dev_priv))
5198 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5199
5200 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5201
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005202 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005203
Yuly Novikov53b41832012-10-26 12:04:00 +03005204 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005205}
5206
Imre Deakdada1a92014-01-29 13:25:41 +02005207static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5208{
Abhay Kumard28d4732016-01-22 17:39:04 -08005209 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005210 intel_dp->last_power_on = jiffies;
5211 intel_dp->last_backlight_off = jiffies;
5212}
5213
Daniel Vetter67a54562012-10-20 20:57:45 +02005214static void
Imre Deak54648612016-06-16 16:37:22 +03005215intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5216 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005217{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305218 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005219 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005220
Imre Deak8e8232d2016-06-16 16:37:21 +03005221 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005222
5223 /* Workaround: Need to write PP_CONTROL with the unlock key as
5224 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305225 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005226
Imre Deak8e8232d2016-06-16 16:37:21 +03005227 pp_on = I915_READ(regs.pp_on);
5228 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005229 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005230 I915_WRITE(regs.pp_ctrl, pp_ctl);
5231 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305232 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005233
5234 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005235 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5236 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005237
Imre Deak54648612016-06-16 16:37:22 +03005238 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5239 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005240
Imre Deak54648612016-06-16 16:37:22 +03005241 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5242 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005243
Imre Deak54648612016-06-16 16:37:22 +03005244 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5245 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005246
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005247 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005248 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5249 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305250 } else {
Imre Deak54648612016-06-16 16:37:22 +03005251 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005252 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305253 }
Imre Deak54648612016-06-16 16:37:22 +03005254}
5255
5256static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005257intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5258{
5259 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5260 state_name,
5261 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5262}
5263
5264static void
5265intel_pps_verify_state(struct drm_i915_private *dev_priv,
5266 struct intel_dp *intel_dp)
5267{
5268 struct edp_power_seq hw;
5269 struct edp_power_seq *sw = &intel_dp->pps_delays;
5270
5271 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5272
5273 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5274 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5275 DRM_ERROR("PPS state mismatch\n");
5276 intel_pps_dump_state("sw", sw);
5277 intel_pps_dump_state("hw", &hw);
5278 }
5279}
5280
5281static void
Imre Deak54648612016-06-16 16:37:22 +03005282intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5283 struct intel_dp *intel_dp)
5284{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005285 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005286 struct edp_power_seq cur, vbt, spec,
5287 *final = &intel_dp->pps_delays;
5288
5289 lockdep_assert_held(&dev_priv->pps_mutex);
5290
5291 /* already initialized? */
5292 if (final->t11_t12 != 0)
5293 return;
5294
5295 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005296
Imre Deakde9c1b62016-06-16 20:01:46 +03005297 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005298
Jani Nikula6aa23e62016-03-24 17:50:20 +02005299 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005300 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5301 * of 500ms appears to be too short. Ocassionally the panel
5302 * just fails to power back on. Increasing the delay to 800ms
5303 * seems sufficient to avoid this problem.
5304 */
5305 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
Manasi Navarec02b8fb2017-10-03 16:37:25 -07005306 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
Manasi Navarec99a2592017-06-30 09:33:48 -07005307 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5308 vbt.t11_t12);
5309 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005310 /* T11_T12 delay is special and actually in units of 100ms, but zero
5311 * based in the hw (so we need to add 100 ms). But the sw vbt
5312 * table multiplies it with 1000 to make it in units of 100usec,
5313 * too. */
5314 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005315
5316 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5317 * our hw here, which are all in 100usec. */
5318 spec.t1_t3 = 210 * 10;
5319 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5320 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5321 spec.t10 = 500 * 10;
5322 /* This one is special and actually in units of 100ms, but zero
5323 * based in the hw (so we need to add 100 ms). But the sw vbt
5324 * table multiplies it with 1000 to make it in units of 100usec,
5325 * too. */
5326 spec.t11_t12 = (510 + 100) * 10;
5327
Imre Deakde9c1b62016-06-16 20:01:46 +03005328 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005329
5330 /* Use the max of the register settings and vbt. If both are
5331 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005332#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005333 spec.field : \
5334 max(cur.field, vbt.field))
5335 assign_final(t1_t3);
5336 assign_final(t8);
5337 assign_final(t9);
5338 assign_final(t10);
5339 assign_final(t11_t12);
5340#undef assign_final
5341
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005342#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005343 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5344 intel_dp->backlight_on_delay = get_delay(t8);
5345 intel_dp->backlight_off_delay = get_delay(t9);
5346 intel_dp->panel_power_down_delay = get_delay(t10);
5347 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5348#undef get_delay
5349
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005350 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5351 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5352 intel_dp->panel_power_cycle_delay);
5353
5354 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5355 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005356
5357 /*
5358 * We override the HW backlight delays to 1 because we do manual waits
5359 * on them. For T8, even BSpec recommends doing it. For T9, if we
5360 * don't do this, we'll end up waiting for the backlight off delay
5361 * twice: once when we do the manual sleep, and once when we disable
5362 * the panel and wait for the PP_STATUS bit to become zero.
5363 */
5364 final->t8 = 1;
5365 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005366}
5367
5368static void
5369intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005370 struct intel_dp *intel_dp,
5371 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005372{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005373 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005374 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005375 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005376 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005377 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005378 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005379
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005380 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005381
Imre Deak8e8232d2016-06-16 16:37:21 +03005382 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005383
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005384 /*
5385 * On some VLV machines the BIOS can leave the VDD
5386 * enabled even on power seqeuencers which aren't
5387 * hooked up to any port. This would mess up the
5388 * power domain tracking the first time we pick
5389 * one of these power sequencers for use since
5390 * edp_panel_vdd_on() would notice that the VDD was
5391 * already on and therefore wouldn't grab the power
5392 * domain reference. Disable VDD first to avoid this.
5393 * This also avoids spuriously turning the VDD on as
5394 * soon as the new power seqeuencer gets initialized.
5395 */
5396 if (force_disable_vdd) {
5397 u32 pp = ironlake_get_pp_control(intel_dp);
5398
5399 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5400
5401 if (pp & EDP_FORCE_VDD)
5402 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5403
5404 pp &= ~EDP_FORCE_VDD;
5405
5406 I915_WRITE(regs.pp_ctrl, pp);
5407 }
5408
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005409 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005410 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5411 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005412 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005413 /* Compute the divisor for the pp clock, simply match the Bspec
5414 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005415 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005416 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305417 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005418 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305419 << BXT_POWER_CYCLE_DELAY_SHIFT);
5420 } else {
5421 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5422 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5423 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5424 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005425
5426 /* Haswell doesn't have any port selection bits for the panel
5427 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005428 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005429 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005430 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005431 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005432 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005433 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005434 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005435 }
5436
Jesse Barnes453c5422013-03-28 09:55:41 -07005437 pp_on |= port_sel;
5438
Imre Deak8e8232d2016-06-16 16:37:21 +03005439 I915_WRITE(regs.pp_on, pp_on);
5440 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005441 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005442 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305443 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005444 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005445
Daniel Vetter67a54562012-10-20 20:57:45 +02005446 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 +03005447 I915_READ(regs.pp_on),
5448 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005449 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005450 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5451 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005452}
5453
Imre Deak335f7522016-08-10 14:07:32 +03005454static void intel_dp_pps_init(struct drm_device *dev,
5455 struct intel_dp *intel_dp)
5456{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005457 struct drm_i915_private *dev_priv = to_i915(dev);
5458
5459 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005460 vlv_initial_power_sequencer_setup(intel_dp);
5461 } else {
5462 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005463 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005464 }
5465}
5466
Vandana Kannanb33a2812015-02-13 15:33:03 +05305467/**
5468 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005469 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005470 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305471 * @refresh_rate: RR to be programmed
5472 *
5473 * This function gets called when refresh rate (RR) has to be changed from
5474 * one frequency to another. Switches can be between high and low RR
5475 * supported by the panel or to any other RR based on media playback (in
5476 * this case, RR value needs to be passed from user space).
5477 *
5478 * The caller of this function needs to take a lock on dev_priv->drrs.
5479 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005480static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005481 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005482 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305483{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305484 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305485 struct intel_digital_port *dig_port = NULL;
5486 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005487 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305488 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305489
5490 if (refresh_rate <= 0) {
5491 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5492 return;
5493 }
5494
Vandana Kannan96178ee2015-01-10 02:25:56 +05305495 if (intel_dp == NULL) {
5496 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305497 return;
5498 }
5499
Vandana Kannan96178ee2015-01-10 02:25:56 +05305500 dig_port = dp_to_dig_port(intel_dp);
5501 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005502 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305503
5504 if (!intel_crtc) {
5505 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5506 return;
5507 }
5508
Vandana Kannan96178ee2015-01-10 02:25:56 +05305509 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305510 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5511 return;
5512 }
5513
Vandana Kannan96178ee2015-01-10 02:25:56 +05305514 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5515 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305516 index = DRRS_LOW_RR;
5517
Vandana Kannan96178ee2015-01-10 02:25:56 +05305518 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305519 DRM_DEBUG_KMS(
5520 "DRRS requested for previously set RR...ignoring\n");
5521 return;
5522 }
5523
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005524 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305525 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5526 return;
5527 }
5528
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005529 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305530 switch (index) {
5531 case DRRS_HIGH_RR:
5532 intel_dp_set_m_n(intel_crtc, M1_N1);
5533 break;
5534 case DRRS_LOW_RR:
5535 intel_dp_set_m_n(intel_crtc, M2_N2);
5536 break;
5537 case DRRS_MAX_RR:
5538 default:
5539 DRM_ERROR("Unsupported refreshrate type\n");
5540 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005541 } else if (INTEL_GEN(dev_priv) > 6) {
5542 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005543 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305544
Ville Syrjälä649636e2015-09-22 19:50:01 +03005545 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305546 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005547 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305548 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5549 else
5550 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305551 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005552 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305553 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5554 else
5555 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305556 }
5557 I915_WRITE(reg, val);
5558 }
5559
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305560 dev_priv->drrs.refresh_rate_type = index;
5561
5562 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5563}
5564
Vandana Kannanb33a2812015-02-13 15:33:03 +05305565/**
5566 * intel_edp_drrs_enable - init drrs struct if supported
5567 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005568 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305569 *
5570 * Initializes frontbuffer_bits and drrs.dp
5571 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005572void intel_edp_drrs_enable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005573 const struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305574{
5575 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005576 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305577
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005578 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305579 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5580 return;
5581 }
5582
Radhakrishna Sripadada83ef82017-09-14 11:16:41 -07005583 if (dev_priv->psr.enabled) {
5584 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5585 return;
5586 }
5587
Vandana Kannanc3955782015-01-22 15:17:40 +05305588 mutex_lock(&dev_priv->drrs.mutex);
5589 if (WARN_ON(dev_priv->drrs.dp)) {
5590 DRM_ERROR("DRRS already enabled\n");
5591 goto unlock;
5592 }
5593
5594 dev_priv->drrs.busy_frontbuffer_bits = 0;
5595
5596 dev_priv->drrs.dp = intel_dp;
5597
5598unlock:
5599 mutex_unlock(&dev_priv->drrs.mutex);
5600}
5601
Vandana Kannanb33a2812015-02-13 15:33:03 +05305602/**
5603 * intel_edp_drrs_disable - Disable DRRS
5604 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005605 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305606 *
5607 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005608void intel_edp_drrs_disable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005609 const struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305610{
5611 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005612 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305613
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005614 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305615 return;
5616
5617 mutex_lock(&dev_priv->drrs.mutex);
5618 if (!dev_priv->drrs.dp) {
5619 mutex_unlock(&dev_priv->drrs.mutex);
5620 return;
5621 }
5622
5623 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005624 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5625 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305626
5627 dev_priv->drrs.dp = NULL;
5628 mutex_unlock(&dev_priv->drrs.mutex);
5629
5630 cancel_delayed_work_sync(&dev_priv->drrs.work);
5631}
5632
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305633static void intel_edp_drrs_downclock_work(struct work_struct *work)
5634{
5635 struct drm_i915_private *dev_priv =
5636 container_of(work, typeof(*dev_priv), drrs.work.work);
5637 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305638
Vandana Kannan96178ee2015-01-10 02:25:56 +05305639 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305640
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305641 intel_dp = dev_priv->drrs.dp;
5642
5643 if (!intel_dp)
5644 goto unlock;
5645
5646 /*
5647 * The delayed work can race with an invalidate hence we need to
5648 * recheck.
5649 */
5650
5651 if (dev_priv->drrs.busy_frontbuffer_bits)
5652 goto unlock;
5653
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005654 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5655 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5656
5657 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5658 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5659 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305660
5661unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305662 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305663}
5664
Vandana Kannanb33a2812015-02-13 15:33:03 +05305665/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305666 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005667 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305668 * @frontbuffer_bits: frontbuffer plane tracking bits
5669 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305670 * This function gets called everytime rendering on the given planes start.
5671 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305672 *
5673 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5674 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005675void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5676 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305677{
Vandana Kannana93fad02015-01-10 02:25:59 +05305678 struct drm_crtc *crtc;
5679 enum pipe pipe;
5680
Daniel Vetter9da7d692015-04-09 16:44:15 +02005681 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 return;
5683
Daniel Vetter88f933a2015-04-09 16:44:16 +02005684 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305685
Vandana Kannana93fad02015-01-10 02:25:59 +05305686 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005687 if (!dev_priv->drrs.dp) {
5688 mutex_unlock(&dev_priv->drrs.mutex);
5689 return;
5690 }
5691
Vandana Kannana93fad02015-01-10 02:25:59 +05305692 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5693 pipe = to_intel_crtc(crtc)->pipe;
5694
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005695 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5696 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5697
Ramalingam C0ddfd202015-06-15 20:50:05 +05305698 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005699 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005700 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5701 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305702
Vandana Kannana93fad02015-01-10 02:25:59 +05305703 mutex_unlock(&dev_priv->drrs.mutex);
5704}
5705
Vandana Kannanb33a2812015-02-13 15:33:03 +05305706/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305707 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005708 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305709 * @frontbuffer_bits: frontbuffer plane tracking bits
5710 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305711 * This function gets called every time rendering on the given planes has
5712 * completed or flip on a crtc is completed. So DRRS should be upclocked
5713 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5714 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305715 *
5716 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5717 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005718void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5719 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305720{
Vandana Kannana93fad02015-01-10 02:25:59 +05305721 struct drm_crtc *crtc;
5722 enum pipe pipe;
5723
Daniel Vetter9da7d692015-04-09 16:44:15 +02005724 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305725 return;
5726
Daniel Vetter88f933a2015-04-09 16:44:16 +02005727 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305728
Vandana Kannana93fad02015-01-10 02:25:59 +05305729 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005730 if (!dev_priv->drrs.dp) {
5731 mutex_unlock(&dev_priv->drrs.mutex);
5732 return;
5733 }
5734
Vandana Kannana93fad02015-01-10 02:25:59 +05305735 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5736 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005737
5738 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305739 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5740
Ramalingam C0ddfd202015-06-15 20:50:05 +05305741 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005742 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005743 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5744 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305745
5746 /*
5747 * flush also means no more activity hence schedule downclock, if all
5748 * other fbs are quiescent too
5749 */
5750 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305751 schedule_delayed_work(&dev_priv->drrs.work,
5752 msecs_to_jiffies(1000));
5753 mutex_unlock(&dev_priv->drrs.mutex);
5754}
5755
Vandana Kannanb33a2812015-02-13 15:33:03 +05305756/**
5757 * DOC: Display Refresh Rate Switching (DRRS)
5758 *
5759 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5760 * which enables swtching between low and high refresh rates,
5761 * dynamically, based on the usage scenario. This feature is applicable
5762 * for internal panels.
5763 *
5764 * Indication that the panel supports DRRS is given by the panel EDID, which
5765 * would list multiple refresh rates for one resolution.
5766 *
5767 * DRRS is of 2 types - static and seamless.
5768 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5769 * (may appear as a blink on screen) and is used in dock-undock scenario.
5770 * Seamless DRRS involves changing RR without any visual effect to the user
5771 * and can be used during normal system usage. This is done by programming
5772 * certain registers.
5773 *
5774 * Support for static/seamless DRRS may be indicated in the VBT based on
5775 * inputs from the panel spec.
5776 *
5777 * DRRS saves power by switching to low RR based on usage scenarios.
5778 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005779 * The implementation is based on frontbuffer tracking implementation. When
5780 * there is a disturbance on the screen triggered by user activity or a periodic
5781 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5782 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5783 * made.
5784 *
5785 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5786 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305787 *
5788 * DRRS can be further extended to support other internal panels and also
5789 * the scenario of video playback wherein RR is set based on the rate
5790 * requested by userspace.
5791 */
5792
5793/**
5794 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5795 * @intel_connector: eDP connector
5796 * @fixed_mode: preferred mode of panel
5797 *
5798 * This function is called only once at driver load to initialize basic
5799 * DRRS stuff.
5800 *
5801 * Returns:
5802 * Downclock mode if panel supports it, else return NULL.
5803 * DRRS support is determined by the presence of downclock mode (apart
5804 * from VBT setting).
5805 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305806static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305807intel_dp_drrs_init(struct intel_connector *intel_connector,
5808 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305809{
5810 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305811 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005812 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305813 struct drm_display_mode *downclock_mode = NULL;
5814
Daniel Vetter9da7d692015-04-09 16:44:15 +02005815 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5816 mutex_init(&dev_priv->drrs.mutex);
5817
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005818 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305819 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5820 return NULL;
5821 }
5822
5823 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005824 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305825 return NULL;
5826 }
5827
5828 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005829 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305830
5831 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305832 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305833 return NULL;
5834 }
5835
Vandana Kannan96178ee2015-01-10 02:25:56 +05305836 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305837
Vandana Kannan96178ee2015-01-10 02:25:56 +05305838 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005839 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305840 return downclock_mode;
5841}
5842
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005843static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005844 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005845{
5846 struct drm_connector *connector = &intel_connector->base;
5847 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005848 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5849 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005850 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005851 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07005852 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305853 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005854 bool has_dpcd;
5855 struct drm_display_mode *scan;
5856 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005857 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005858
Jani Nikula1853a9d2017-08-18 12:30:20 +03005859 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005860 return true;
5861
Imre Deak97a824e12016-06-21 11:51:47 +03005862 /*
5863 * On IBX/CPT we may get here with LVDS already registered. Since the
5864 * driver uses the only internal power sequencer available for both
5865 * eDP and LVDS bail out early in this case to prevent interfering
5866 * with an already powered-on LVDS power sequencer.
5867 */
5868 if (intel_get_lvds_encoder(dev)) {
5869 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5870 DRM_INFO("LVDS was detected, not registering eDP\n");
5871
5872 return false;
5873 }
5874
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005875 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005876
5877 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005878 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005879 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005880
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005881 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005882
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005883 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005884 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005885
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005886 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005887 /* if this fails, presume the device is a ghost */
5888 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005889 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005890 }
5891
Daniel Vetter060c8772014-03-21 23:22:35 +01005892 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005893 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005894 if (edid) {
5895 if (drm_add_edid_modes(connector, edid)) {
5896 drm_mode_connector_update_edid_property(connector,
5897 edid);
5898 drm_edid_to_eld(connector, edid);
5899 } else {
5900 kfree(edid);
5901 edid = ERR_PTR(-EINVAL);
5902 }
5903 } else {
5904 edid = ERR_PTR(-ENOENT);
5905 }
5906 intel_connector->edid = edid;
5907
Jim Bridedc911f52017-08-09 12:48:53 -07005908 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005909 list_for_each_entry(scan, &connector->probed_modes, head) {
5910 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5911 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305912 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305913 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07005914 } else if (!alt_fixed_mode) {
5915 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005916 }
5917 }
5918
5919 /* fallback to VBT if available for eDP */
5920 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5921 fixed_mode = drm_mode_duplicate(dev,
5922 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005923 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005924 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005925 connector->display_info.width_mm = fixed_mode->width_mm;
5926 connector->display_info.height_mm = fixed_mode->height_mm;
5927 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005928 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005929 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005930
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005931 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005932 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5933 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005934
5935 /*
5936 * Figure out the current pipe for the initial backlight setup.
5937 * If the current pipe isn't valid, try the PPS pipe, and if that
5938 * fails just assume pipe A.
5939 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005940 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005941
5942 if (pipe != PIPE_A && pipe != PIPE_B)
5943 pipe = intel_dp->pps_pipe;
5944
5945 if (pipe != PIPE_A && pipe != PIPE_B)
5946 pipe = PIPE_A;
5947
5948 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5949 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005950 }
5951
Jim Bridedc911f52017-08-09 12:48:53 -07005952 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5953 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005954 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005955 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005956
5957 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005958
5959out_vdd_off:
5960 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5961 /*
5962 * vdd might still be enabled do to the delayed vdd off.
5963 * Make sure vdd is actually turned off here.
5964 */
5965 pps_lock(intel_dp);
5966 edp_panel_vdd_off_sync(intel_dp);
5967 pps_unlock(intel_dp);
5968
5969 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005970}
5971
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005972/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005973static void
5974intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5975{
5976 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005977 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005978
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005979 encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port);
5980
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005981 switch (intel_dig_port->port) {
5982 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005983 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005984 break;
5985 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005986 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005987 break;
5988 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005989 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005990 break;
5991 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005992 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005993 break;
5994 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005995 /* FIXME: Check VBT for actual wiring of PORT E */
5996 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005997 break;
5998 default:
5999 MISSING_CASE(intel_dig_port->port);
6000 }
6001}
6002
Manasi Navare93013972017-04-06 16:44:19 +03006003static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
6004{
6005 struct intel_connector *intel_connector;
6006 struct drm_connector *connector;
6007
6008 intel_connector = container_of(work, typeof(*intel_connector),
6009 modeset_retry_work);
6010 connector = &intel_connector->base;
6011 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
6012 connector->name);
6013
6014 /* Grab the locks before changing connector property*/
6015 mutex_lock(&connector->dev->mode_config.mutex);
6016 /* Set connector link status to BAD and send a Uevent to notify
6017 * userspace to do a modeset.
6018 */
6019 drm_mode_connector_set_link_status_property(connector,
6020 DRM_MODE_LINK_STATUS_BAD);
6021 mutex_unlock(&connector->dev->mode_config.mutex);
6022 /* Send Hotplug uevent so userspace can reprobe */
6023 drm_kms_helper_hotplug_event(connector->dev);
6024}
6025
Paulo Zanoni16c25532013-06-12 17:27:25 -03006026bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006027intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6028 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006029{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006030 struct drm_connector *connector = &intel_connector->base;
6031 struct intel_dp *intel_dp = &intel_dig_port->dp;
6032 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6033 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006034 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02006035 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006036 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006037
Manasi Navare93013972017-04-06 16:44:19 +03006038 /* Initialize the work for modeset in case of link train failure */
6039 INIT_WORK(&intel_connector->modeset_retry_work,
6040 intel_dp_modeset_retry_work_fn);
6041
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006042 if (WARN(intel_dig_port->max_lanes < 1,
6043 "Not enough lanes (%d) for DP on port %c\n",
6044 intel_dig_port->max_lanes, port_name(port)))
6045 return false;
6046
Jani Nikula55cfc582017-03-28 17:59:04 +03006047 intel_dp_set_source_rates(intel_dp);
6048
Manasi Navared7e8ef02017-02-07 16:54:11 -08006049 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006050 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006051 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006052
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006053 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006054 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006055 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006056 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006057 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006058 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006059 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6060 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006061 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006062
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006063 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006064 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6065 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006066 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006067
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006068 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006069 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6070
Daniel Vetter07679352012-09-06 22:15:42 +02006071 /* Preserve the current hw state. */
6072 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006073 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006074
Jani Nikula7b91bf72017-08-18 12:30:19 +03006075 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306076 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006077 else
6078 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006079
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006080 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6081 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6082
Imre Deakf7d24902013-05-08 13:14:05 +03006083 /*
6084 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6085 * for DP the encoder type can be set by the caller to
6086 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6087 */
6088 if (type == DRM_MODE_CONNECTOR_eDP)
6089 intel_encoder->type = INTEL_OUTPUT_EDP;
6090
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006091 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006092 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006093 intel_dp_is_edp(intel_dp) &&
6094 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006095 return false;
6096
Imre Deake7281ea2013-05-08 13:14:08 +03006097 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6098 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6099 port_name(port));
6100
Adam Jacksonb3295302010-07-16 14:46:28 -04006101 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006102 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6103
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006104 connector->interlace_allowed = true;
6105 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006106
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006107 intel_dp_init_connector_port_info(intel_dig_port);
6108
Mika Kaholab6339582016-09-09 14:10:52 +03006109 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006110
Daniel Vetter66a92782012-07-12 20:08:18 +02006111 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006112 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006113
Chris Wilsondf0e9242010-09-09 16:20:55 +01006114 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006115
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006116 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006117 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6118 else
6119 intel_connector->get_hw_state = intel_connector_get_hw_state;
6120
Dave Airlie0e32b392014-05-02 14:02:48 +10006121 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006122 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006123 (port == PORT_B || port == PORT_C || port == PORT_D))
6124 intel_dp_mst_encoder_init(intel_dig_port,
6125 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006126
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006127 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006128 intel_dp_aux_fini(intel_dp);
6129 intel_dp_mst_encoder_cleanup(intel_dig_port);
6130 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006131 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006132
Chris Wilsonf6849602010-09-19 09:29:33 +01006133 intel_dp_add_properties(intel_dp, connector);
6134
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006135 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6136 * 0xd. Failure to do so will result in spurious interrupts being
6137 * generated on the port when a cable is not attached.
6138 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006139 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006140 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6141 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6142 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006143
6144 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006145
6146fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006147 drm_connector_cleanup(connector);
6148
6149 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006150}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006151
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006152bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006153 i915_reg_t output_reg,
6154 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006155{
6156 struct intel_digital_port *intel_dig_port;
6157 struct intel_encoder *intel_encoder;
6158 struct drm_encoder *encoder;
6159 struct intel_connector *intel_connector;
6160
Daniel Vetterb14c5672013-09-19 12:18:32 +02006161 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006162 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006163 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006164
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006165 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306166 if (!intel_connector)
6167 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006168
6169 intel_encoder = &intel_dig_port->base;
6170 encoder = &intel_encoder->base;
6171
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006172 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6173 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6174 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306175 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006176
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006177 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006178 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006179 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006180 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006181 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006182 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006183 intel_encoder->pre_enable = chv_pre_enable_dp;
6184 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006185 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006186 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006187 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006188 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006189 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006190 intel_encoder->pre_enable = vlv_pre_enable_dp;
6191 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006192 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006193 intel_encoder->post_disable = vlv_post_disable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006194 } else if (INTEL_GEN(dev_priv) >= 5) {
6195 intel_encoder->pre_enable = g4x_pre_enable_dp;
6196 intel_encoder->enable = g4x_enable_dp;
6197 intel_encoder->disable = ilk_disable_dp;
6198 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006199 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006200 intel_encoder->pre_enable = g4x_pre_enable_dp;
6201 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006202 intel_encoder->disable = g4x_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006203 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006204
Paulo Zanoni174edf12012-10-26 19:05:50 -02006205 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006206 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006207 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006208
Ville Syrjäläcca05022016-06-22 21:57:06 +03006209 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006210 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006211 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006212 if (port == PORT_D)
6213 intel_encoder->crtc_mask = 1 << 2;
6214 else
6215 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6216 } else {
6217 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6218 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006219 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006220 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006221
Dave Airlie13cf5502014-06-18 11:29:35 +10006222 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006223 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006224
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006225 if (port != PORT_A)
6226 intel_infoframe_init(intel_dig_port);
6227
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306228 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6229 goto err_init_connector;
6230
Chris Wilson457c52d2016-06-01 08:27:50 +01006231 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306232
6233err_init_connector:
6234 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306235err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306236 kfree(intel_connector);
6237err_connector_alloc:
6238 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006239 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006240}
Dave Airlie0e32b392014-05-02 14:02:48 +10006241
6242void intel_dp_mst_suspend(struct drm_device *dev)
6243{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006244 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006245 int i;
6246
6247 /* disable MST */
6248 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006249 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006250
6251 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006252 continue;
6253
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006254 if (intel_dig_port->dp.is_mst)
6255 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006256 }
6257}
6258
6259void intel_dp_mst_resume(struct drm_device *dev)
6260{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006261 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006262 int i;
6263
6264 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006265 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006266 int ret;
6267
6268 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006269 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006270
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006271 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6272 if (ret)
6273 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006274 }
6275}