blob: 9b0c6dea40bc2f4873ed06930d73c83b50aa17ee [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
Ville Syrjäläadc10302017-10-31 22:51:14 +0200132static void intel_dp_link_down(struct intel_encoder *encoder,
133 const struct intel_crtc_state *old_crtc_state);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300134static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100135static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjäläadc10302017-10-31 22:51:14 +0200136static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
137 const struct intel_crtc_state *crtc_state);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300138static void vlv_steal_power_sequencer(struct drm_device *dev,
139 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530140static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700141
Jani Nikula68f357c2017-03-28 17:59:05 +0300142/* update sink rates from dpcd */
143static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
144{
Jani Nikulaa8a08882017-10-09 12:29:59 +0300145 int i, max_rate;
Jani Nikula68f357c2017-03-28 17:59:05 +0300146
Jani Nikulaa8a08882017-10-09 12:29:59 +0300147 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
Jani Nikula68f357c2017-03-28 17:59:05 +0300148
Jani Nikulaa8a08882017-10-09 12:29:59 +0300149 for (i = 0; i < ARRAY_SIZE(default_rates); i++) {
150 if (default_rates[i] > max_rate)
151 break;
Jani Nikula68f357c2017-03-28 17:59:05 +0300152 intel_dp->sink_rates[i] = default_rates[i];
Jani Nikulaa8a08882017-10-09 12:29:59 +0300153 }
Jani Nikula68f357c2017-03-28 17:59:05 +0300154
Jani Nikulaa8a08882017-10-09 12:29:59 +0300155 intel_dp->num_sink_rates = i;
Jani Nikula68f357c2017-03-28 17:59:05 +0300156}
157
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300158/* Theoretical max between source and sink */
159static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700160{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300161 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700162}
163
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300164/* Theoretical max between source and sink */
165static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300166{
167 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300168 int source_max = intel_dig_port->max_lanes;
169 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300170
171 return min(source_max, sink_max);
172}
173
Jani Nikula3d65a732017-04-06 16:44:14 +0300174int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300175{
176 return intel_dp->max_link_lane_count;
177}
178
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800179int
Keith Packardc8982612012-01-25 08:16:25 -0800180intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800182 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
183 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700184}
185
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800186int
Dave Airliefe27d532010-06-30 11:46:17 +1000187intel_dp_max_data_rate(int max_link_clock, int max_lanes)
188{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800189 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
190 * link rate that is generally expressed in Gbps. Since, 8 bits of data
191 * is transmitted every LS_Clk per lane, there is no need to account for
192 * the channel encoding that is done in the PHY layer here.
193 */
194
195 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000196}
197
Mika Kahola70ec0642016-09-09 14:10:55 +0300198static int
199intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
200{
201 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
202 struct intel_encoder *encoder = &intel_dig_port->base;
203 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
204 int max_dotclk = dev_priv->max_dotclk_freq;
205 int ds_max_dotclk;
206
207 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
208
209 if (type != DP_DS_PORT_TYPE_VGA)
210 return max_dotclk;
211
212 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
213 intel_dp->downstream_ports);
214
215 if (ds_max_dotclk != 0)
216 max_dotclk = min(max_dotclk, ds_max_dotclk);
217
218 return max_dotclk;
219}
220
Jani Nikula55cfc582017-03-28 17:59:04 +0300221static void
222intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700223{
224 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
225 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200226 enum port port = dig_port->base.port;
Jani Nikula55cfc582017-03-28 17:59:04 +0300227 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700228 int size;
Rodrigo Vivid907b662017-08-10 15:40:08 -0700229 u32 voltage;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700230
Jani Nikula55cfc582017-03-28 17:59:04 +0300231 /* This should only be done once */
232 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
233
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200234 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300235 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700236 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700237 } else if (IS_CANNONLAKE(dev_priv)) {
238 source_rates = cnl_rates;
239 size = ARRAY_SIZE(cnl_rates);
240 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
241 if (port == PORT_A || port == PORT_D ||
242 voltage == VOLTAGE_INFO_0_85V)
243 size -= 2;
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800244 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300245 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700246 size = ARRAY_SIZE(skl_rates);
Jani Nikulafc603ca2017-10-09 12:29:58 +0300247 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
248 IS_BROADWELL(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300249 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700250 size = ARRAY_SIZE(default_rates);
Jani Nikulafc603ca2017-10-09 12:29:58 +0300251 } else {
252 source_rates = default_rates;
253 size = ARRAY_SIZE(default_rates) - 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700254 }
255
Jani Nikula55cfc582017-03-28 17:59:04 +0300256 intel_dp->source_rates = source_rates;
257 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700258}
259
260static int intersect_rates(const int *source_rates, int source_len,
261 const int *sink_rates, int sink_len,
262 int *common_rates)
263{
264 int i = 0, j = 0, k = 0;
265
266 while (i < source_len && j < sink_len) {
267 if (source_rates[i] == sink_rates[j]) {
268 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
269 return k;
270 common_rates[k] = source_rates[i];
271 ++k;
272 ++i;
273 ++j;
274 } else if (source_rates[i] < sink_rates[j]) {
275 ++i;
276 } else {
277 ++j;
278 }
279 }
280 return k;
281}
282
Jani Nikula8001b752017-03-28 17:59:03 +0300283/* return index of rate in rates array, or -1 if not found */
284static int intel_dp_rate_index(const int *rates, int len, int rate)
285{
286 int i;
287
288 for (i = 0; i < len; i++)
289 if (rate == rates[i])
290 return i;
291
292 return -1;
293}
294
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300295static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700296{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300297 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700298
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300299 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
300 intel_dp->num_source_rates,
301 intel_dp->sink_rates,
302 intel_dp->num_sink_rates,
303 intel_dp->common_rates);
304
305 /* Paranoia, there should always be something in common. */
306 if (WARN_ON(intel_dp->num_common_rates == 0)) {
307 intel_dp->common_rates[0] = default_rates[0];
308 intel_dp->num_common_rates = 1;
309 }
310}
311
312/* get length of common rates potentially limited by max_rate */
313static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
314 int max_rate)
315{
316 const int *common_rates = intel_dp->common_rates;
317 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700318
Jani Nikula68f357c2017-03-28 17:59:05 +0300319 /* Limit results by potentially reduced max rate */
320 for (i = 0; i < common_len; i++) {
321 if (common_rates[common_len - i - 1] <= max_rate)
322 return common_len - i;
323 }
324
325 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700326}
327
Manasi Navare1a92c702017-06-08 13:41:02 -0700328static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
329 uint8_t lane_count)
Manasi Navare14c562c2017-04-06 14:00:12 -0700330{
331 /*
332 * FIXME: we need to synchronize the current link parameters with
333 * hardware readout. Currently fast link training doesn't work on
334 * boot-up.
335 */
Manasi Navare1a92c702017-06-08 13:41:02 -0700336 if (link_rate == 0 ||
337 link_rate > intel_dp->max_link_rate)
Manasi Navare14c562c2017-04-06 14:00:12 -0700338 return false;
339
Manasi Navare1a92c702017-06-08 13:41:02 -0700340 if (lane_count == 0 ||
341 lane_count > intel_dp_max_lane_count(intel_dp))
Manasi Navare14c562c2017-04-06 14:00:12 -0700342 return false;
343
344 return true;
345}
346
Manasi Navarefdb14d32016-12-08 19:05:12 -0800347int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
348 int link_rate, uint8_t lane_count)
349{
Jani Nikulab1810a72017-04-06 16:44:11 +0300350 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800351
Jani Nikulab1810a72017-04-06 16:44:11 +0300352 index = intel_dp_rate_index(intel_dp->common_rates,
353 intel_dp->num_common_rates,
354 link_rate);
355 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300356 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
357 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800358 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300359 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300360 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800361 } else {
362 DRM_ERROR("Link Training Unsuccessful\n");
363 return -1;
364 }
365
366 return 0;
367}
368
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000369static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700370intel_dp_mode_valid(struct drm_connector *connector,
371 struct drm_display_mode *mode)
372{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100373 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300374 struct intel_connector *intel_connector = to_intel_connector(connector);
375 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100376 int target_clock = mode->clock;
377 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300378 int max_dotclk;
379
380 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700381
Jani Nikula1853a9d2017-08-18 12:30:20 +0300382 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
Jani Nikuladd06f902012-10-19 14:51:50 +0300383 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100384 return MODE_PANEL;
385
Jani Nikuladd06f902012-10-19 14:51:50 +0300386 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100387 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200388
389 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100390 }
391
Ville Syrjälä50fec212015-03-12 17:10:34 +0200392 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300393 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100394
395 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
396 mode_rate = intel_dp_link_required(target_clock, 18);
397
Mika Kahola799487f2016-02-02 15:16:38 +0200398 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200399 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700400
401 if (mode->clock < 10000)
402 return MODE_CLOCK_LOW;
403
Daniel Vetter0af78a22012-05-23 11:30:55 +0200404 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
405 return MODE_H_ILLEGAL;
406
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700407 return MODE_OK;
408}
409
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800410uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700411{
412 int i;
413 uint32_t v = 0;
414
415 if (src_bytes > 4)
416 src_bytes = 4;
417 for (i = 0; i < src_bytes; i++)
418 v |= ((uint32_t) src[i]) << ((3-i) * 8);
419 return v;
420}
421
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000422static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700423{
424 int i;
425 if (dst_bytes > 4)
426 dst_bytes = 4;
427 for (i = 0; i < dst_bytes; i++)
428 dst[i] = src >> ((3-i) * 8);
429}
430
Jani Nikulabf13e812013-09-06 07:40:05 +0300431static void
432intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300433 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300434static void
435intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200436 struct intel_dp *intel_dp,
437 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300438static void
439intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300440
Ville Syrjälä773538e82014-09-04 14:54:56 +0300441static void pps_lock(struct intel_dp *intel_dp)
442{
443 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
444 struct intel_encoder *encoder = &intel_dig_port->base;
445 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100446 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300447
448 /*
449 * See vlv_power_sequencer_reset() why we need
450 * a power domain reference here.
451 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200452 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300453
454 mutex_lock(&dev_priv->pps_mutex);
455}
456
457static void pps_unlock(struct intel_dp *intel_dp)
458{
459 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
460 struct intel_encoder *encoder = &intel_dig_port->base;
461 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100462 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300463
464 mutex_unlock(&dev_priv->pps_mutex);
465
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200466 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300467}
468
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300469static void
470vlv_power_sequencer_kick(struct intel_dp *intel_dp)
471{
472 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200473 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300474 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300475 bool pll_enabled, release_cl_override = false;
476 enum dpio_phy phy = DPIO_PHY(pipe);
477 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300478 uint32_t DP;
479
480 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
481 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200482 pipe_name(pipe), port_name(intel_dig_port->base.port)))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300483 return;
484
485 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200486 pipe_name(pipe), port_name(intel_dig_port->base.port));
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300487
488 /* Preserve the BIOS-computed detected bit. This is
489 * supposed to be read-only.
490 */
491 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
492 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
493 DP |= DP_PORT_WIDTH(1);
494 DP |= DP_LINK_TRAIN_PAT_1;
495
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100496 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300497 DP |= DP_PIPE_SELECT_CHV(pipe);
498 else if (pipe == PIPE_B)
499 DP |= DP_PIPEB_SELECT;
500
Ville Syrjäläd288f652014-10-28 13:20:22 +0200501 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
502
503 /*
504 * The DPLL for the pipe must be enabled for this to work.
505 * So enable temporarily it if it's not already enabled.
506 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300507 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100508 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300509 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
510
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200511 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000512 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
513 DRM_ERROR("Failed to force on pll for pipe %c!\n",
514 pipe_name(pipe));
515 return;
516 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300517 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200518
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300519 /*
520 * Similar magic as in intel_dp_enable_port().
521 * We _must_ do this port enable + disable trick
522 * to make this power seqeuencer lock onto the port.
523 * Otherwise even VDD force bit won't work.
524 */
525 I915_WRITE(intel_dp->output_reg, DP);
526 POSTING_READ(intel_dp->output_reg);
527
528 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
529 POSTING_READ(intel_dp->output_reg);
530
531 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
532 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200533
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300534 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200535 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300536
537 if (release_cl_override)
538 chv_phy_powergate_ch(dev_priv, phy, ch, false);
539 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300540}
541
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200542static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
543{
544 struct intel_encoder *encoder;
545 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
546
547 /*
548 * We don't have power sequencer currently.
549 * Pick one that's not used by other ports.
550 */
551 for_each_intel_encoder(&dev_priv->drm, encoder) {
552 struct intel_dp *intel_dp;
553
554 if (encoder->type != INTEL_OUTPUT_DP &&
555 encoder->type != INTEL_OUTPUT_EDP)
556 continue;
557
558 intel_dp = enc_to_intel_dp(&encoder->base);
559
560 if (encoder->type == INTEL_OUTPUT_EDP) {
561 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
562 intel_dp->active_pipe != intel_dp->pps_pipe);
563
564 if (intel_dp->pps_pipe != INVALID_PIPE)
565 pipes &= ~(1 << intel_dp->pps_pipe);
566 } else {
567 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
568
569 if (intel_dp->active_pipe != INVALID_PIPE)
570 pipes &= ~(1 << intel_dp->active_pipe);
571 }
572 }
573
574 if (pipes == 0)
575 return INVALID_PIPE;
576
577 return ffs(pipes) - 1;
578}
579
Jani Nikulabf13e812013-09-06 07:40:05 +0300580static enum pipe
581vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
582{
583 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300584 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100585 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300586 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300587
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300588 lockdep_assert_held(&dev_priv->pps_mutex);
589
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300590 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300591 WARN_ON(!intel_dp_is_edp(intel_dp));
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300592
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200593 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
594 intel_dp->active_pipe != intel_dp->pps_pipe);
595
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300596 if (intel_dp->pps_pipe != INVALID_PIPE)
597 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300598
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200599 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300600
601 /*
602 * Didn't find one. This should not happen since there
603 * are two power sequencers and up to two eDP ports.
604 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200605 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300606 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300607
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300608 vlv_steal_power_sequencer(dev, pipe);
609 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300610
611 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
612 pipe_name(intel_dp->pps_pipe),
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200613 port_name(intel_dig_port->base.port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300614
615 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300616 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200617 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300618
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300619 /*
620 * Even vdd force doesn't work until we've made
621 * the power sequencer lock in on the port.
622 */
623 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300624
625 return intel_dp->pps_pipe;
626}
627
Imre Deak78597992016-06-16 16:37:20 +0300628static int
629bxt_power_sequencer_idx(struct intel_dp *intel_dp)
630{
631 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
632 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100633 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300634
635 lockdep_assert_held(&dev_priv->pps_mutex);
636
637 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300638 WARN_ON(!intel_dp_is_edp(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300639
640 /*
641 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
642 * mapping needs to be retrieved from VBT, for now just hard-code to
643 * use instance #0 always.
644 */
645 if (!intel_dp->pps_reset)
646 return 0;
647
648 intel_dp->pps_reset = false;
649
650 /*
651 * Only the HW needs to be reprogrammed, the SW state is fixed and
652 * has been setup during connector init.
653 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200654 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300655
656 return 0;
657}
658
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300659typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
660 enum pipe pipe);
661
662static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
663 enum pipe pipe)
664{
Imre Deak44cb7342016-08-10 14:07:29 +0300665 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300666}
667
668static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
669 enum pipe pipe)
670{
Imre Deak44cb7342016-08-10 14:07:29 +0300671 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300672}
673
674static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
675 enum pipe pipe)
676{
677 return true;
678}
679
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300680static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300681vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
682 enum port port,
683 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300684{
Jani Nikulabf13e812013-09-06 07:40:05 +0300685 enum pipe pipe;
686
Jani Nikulabf13e812013-09-06 07:40:05 +0300687 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300688 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300689 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300690
691 if (port_sel != PANEL_PORT_SELECT_VLV(port))
692 continue;
693
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300694 if (!pipe_check(dev_priv, pipe))
695 continue;
696
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300697 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300698 }
699
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300700 return INVALID_PIPE;
701}
702
703static void
704vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
705{
706 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
707 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100708 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200709 enum port port = intel_dig_port->base.port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300710
711 lockdep_assert_held(&dev_priv->pps_mutex);
712
713 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300714 /* first pick one where the panel is on */
715 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
716 vlv_pipe_has_pp_on);
717 /* didn't find one? pick one where vdd is on */
718 if (intel_dp->pps_pipe == INVALID_PIPE)
719 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
720 vlv_pipe_has_vdd_on);
721 /* didn't find one? pick one with just the correct port */
722 if (intel_dp->pps_pipe == INVALID_PIPE)
723 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
724 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300725
726 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
727 if (intel_dp->pps_pipe == INVALID_PIPE) {
728 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
729 port_name(port));
730 return;
731 }
732
733 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
734 port_name(port), pipe_name(intel_dp->pps_pipe));
735
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300736 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200737 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300738}
739
Imre Deak78597992016-06-16 16:37:20 +0300740void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300741{
Chris Wilson91c8a322016-07-05 10:40:23 +0100742 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300743 struct intel_encoder *encoder;
744
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100745 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200746 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300747 return;
748
749 /*
750 * We can't grab pps_mutex here due to deadlock with power_domain
751 * mutex when power_domain functions are called while holding pps_mutex.
752 * That also means that in order to use pps_pipe the code needs to
753 * hold both a power domain reference and pps_mutex, and the power domain
754 * reference get/put must be done while _not_ holding pps_mutex.
755 * pps_{lock,unlock}() do these steps in the correct order, so one
756 * should use them always.
757 */
758
Jani Nikula19c80542015-12-16 12:48:16 +0200759 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300760 struct intel_dp *intel_dp;
761
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200762 if (encoder->type != INTEL_OUTPUT_DP &&
Ville Syrjälä7e732ca2017-10-27 22:31:24 +0300763 encoder->type != INTEL_OUTPUT_EDP &&
764 encoder->type != INTEL_OUTPUT_DDI)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300765 continue;
766
767 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200768
Ville Syrjälä7e732ca2017-10-27 22:31:24 +0300769 /* Skip pure DVI/HDMI DDI encoders */
770 if (!i915_mmio_reg_valid(intel_dp->output_reg))
771 continue;
772
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200773 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
774
775 if (encoder->type != INTEL_OUTPUT_EDP)
776 continue;
777
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200778 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300779 intel_dp->pps_reset = true;
780 else
781 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300782 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300783}
784
Imre Deak8e8232d2016-06-16 16:37:21 +0300785struct pps_registers {
786 i915_reg_t pp_ctrl;
787 i915_reg_t pp_stat;
788 i915_reg_t pp_on;
789 i915_reg_t pp_off;
790 i915_reg_t pp_div;
791};
792
793static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
794 struct intel_dp *intel_dp,
795 struct pps_registers *regs)
796{
Imre Deak44cb7342016-08-10 14:07:29 +0300797 int pps_idx = 0;
798
Imre Deak8e8232d2016-06-16 16:37:21 +0300799 memset(regs, 0, sizeof(*regs));
800
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200801 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300802 pps_idx = bxt_power_sequencer_idx(intel_dp);
803 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
804 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300805
Imre Deak44cb7342016-08-10 14:07:29 +0300806 regs->pp_ctrl = PP_CONTROL(pps_idx);
807 regs->pp_stat = PP_STATUS(pps_idx);
808 regs->pp_on = PP_ON_DELAYS(pps_idx);
809 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700810 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300811 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300812}
813
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200814static i915_reg_t
815_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300816{
Imre Deak8e8232d2016-06-16 16:37:21 +0300817 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300818
Imre Deak8e8232d2016-06-16 16:37:21 +0300819 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
820 &regs);
821
822 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300823}
824
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200825static i915_reg_t
826_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300827{
Imre Deak8e8232d2016-06-16 16:37:21 +0300828 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300829
Imre Deak8e8232d2016-06-16 16:37:21 +0300830 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
831 &regs);
832
833 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300834}
835
Clint Taylor01527b32014-07-07 13:01:46 -0700836/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
837 This function only applicable when panel PM state is not to be tracked */
838static int edp_notify_handler(struct notifier_block *this, unsigned long code,
839 void *unused)
840{
841 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
842 edp_notifier);
843 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100844 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700845
Jani Nikula1853a9d2017-08-18 12:30:20 +0300846 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
Clint Taylor01527b32014-07-07 13:01:46 -0700847 return 0;
848
Ville Syrjälä773538e82014-09-04 14:54:56 +0300849 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300850
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100851 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300852 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200853 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300854 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300855
Imre Deak44cb7342016-08-10 14:07:29 +0300856 pp_ctrl_reg = PP_CONTROL(pipe);
857 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700858 pp_div = I915_READ(pp_div_reg);
859 pp_div &= PP_REFERENCE_DIVIDER_MASK;
860
861 /* 0x1F write to PP_DIV_REG sets max cycle delay */
862 I915_WRITE(pp_div_reg, pp_div | 0x1F);
863 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
864 msleep(intel_dp->panel_power_cycle_delay);
865 }
866
Ville Syrjälä773538e82014-09-04 14:54:56 +0300867 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300868
Clint Taylor01527b32014-07-07 13:01:46 -0700869 return 0;
870}
871
Daniel Vetter4be73782014-01-17 14:39:48 +0100872static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700873{
Paulo Zanoni30add222012-10-26 19:05:45 -0200874 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100875 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700876
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300877 lockdep_assert_held(&dev_priv->pps_mutex);
878
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100879 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300880 intel_dp->pps_pipe == INVALID_PIPE)
881 return false;
882
Jani Nikulabf13e812013-09-06 07:40:05 +0300883 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700884}
885
Daniel Vetter4be73782014-01-17 14:39:48 +0100886static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700887{
Paulo Zanoni30add222012-10-26 19:05:45 -0200888 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100889 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700890
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300891 lockdep_assert_held(&dev_priv->pps_mutex);
892
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100893 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300894 intel_dp->pps_pipe == INVALID_PIPE)
895 return false;
896
Ville Syrjälä773538e82014-09-04 14:54:56 +0300897 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700898}
899
Keith Packard9b984da2011-09-19 13:54:47 -0700900static void
901intel_dp_check_edp(struct intel_dp *intel_dp)
902{
Paulo Zanoni30add222012-10-26 19:05:45 -0200903 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100904 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700905
Jani Nikula1853a9d2017-08-18 12:30:20 +0300906 if (!intel_dp_is_edp(intel_dp))
Keith Packard9b984da2011-09-19 13:54:47 -0700907 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700908
Daniel Vetter4be73782014-01-17 14:39:48 +0100909 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700910 WARN(1, "eDP powered off while attempting aux channel communication.\n");
911 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300912 I915_READ(_pp_stat_reg(intel_dp)),
913 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700914 }
915}
916
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100917static uint32_t
918intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
919{
920 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
921 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100922 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200923 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100924 uint32_t status;
925 bool done;
926
Daniel Vetteref04f002012-12-01 21:03:59 +0100927#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100928 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300929 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300930 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100931 else
Imre Deak713a6b662016-06-28 13:37:33 +0300932 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100933 if (!done)
934 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
935 has_aux_irq);
936#undef C
937
938 return status;
939}
940
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200941static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000942{
943 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200944 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000945
Ville Syrjäläa457f542016-03-02 17:22:17 +0200946 if (index)
947 return 0;
948
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000949 /*
950 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200951 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000952 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200953 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000954}
955
956static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
957{
958 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200959 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000960
961 if (index)
962 return 0;
963
Ville Syrjäläa457f542016-03-02 17:22:17 +0200964 /*
965 * The clock divider is based off the cdclk or PCH rawclk, and would
966 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
967 * divide by 2000 and use that
968 */
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200969 if (intel_dig_port->base.port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200970 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200971 else
972 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000973}
974
975static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300976{
977 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200978 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300979
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200980 if (intel_dig_port->base.port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300981 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100982 switch (index) {
983 case 0: return 63;
984 case 1: return 72;
985 default: return 0;
986 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300987 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200988
989 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300990}
991
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000992static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
993{
994 /*
995 * SKL doesn't need us to program the AUX clock divider (Hardware will
996 * derive the clock from CDCLK automatically). We still implement the
997 * get_aux_clock_divider vfunc to plug-in into the existing code.
998 */
999 return index ? 0 : 1;
1000}
1001
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02001002static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1003 bool has_aux_irq,
1004 int send_bytes,
1005 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001006{
1007 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001008 struct drm_i915_private *dev_priv =
1009 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001010 uint32_t precharge, timeout;
1011
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001012 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001013 precharge = 3;
1014 else
1015 precharge = 5;
1016
James Ausmus8f5f63d2017-10-12 14:30:37 -07001017 if (IS_BROADWELL(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001018 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1019 else
1020 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1021
1022 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001023 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001024 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001025 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001026 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001027 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001028 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1029 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001030 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001031}
1032
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001033static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1034 bool has_aux_irq,
1035 int send_bytes,
1036 uint32_t unused)
1037{
1038 return DP_AUX_CH_CTL_SEND_BUSY |
1039 DP_AUX_CH_CTL_DONE |
1040 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1041 DP_AUX_CH_CTL_TIME_OUT_ERROR |
James Ausmus6fa228b2017-10-12 14:30:36 -07001042 DP_AUX_CH_CTL_TIME_OUT_MAX |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001043 DP_AUX_CH_CTL_RECEIVE_ERROR |
1044 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001045 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001046 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1047}
1048
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001049static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001050intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001051 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001052 uint8_t *recv, int recv_size)
1053{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001054 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001055 struct drm_i915_private *dev_priv =
1056 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001057 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001058 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001059 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001060 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001061 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001062 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001063 bool vdd;
1064
Ville Syrjälä773538e82014-09-04 14:54:56 +03001065 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001066
Ville Syrjälä72c35002014-08-18 22:16:00 +03001067 /*
1068 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1069 * In such cases we want to leave VDD enabled and it's up to upper layers
1070 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1071 * ourselves.
1072 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001073 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001074
1075 /* dp aux is extremely sensitive to irq latency, hence request the
1076 * lowest possible wakeup latency and so prevent the cpu from going into
1077 * deep sleep states.
1078 */
1079 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001080
Keith Packard9b984da2011-09-19 13:54:47 -07001081 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001082
Jesse Barnes11bee432011-08-01 15:02:20 -07001083 /* Try to wait for any previous AUX channel activity */
1084 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001085 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001086 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1087 break;
1088 msleep(1);
1089 }
1090
1091 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001092 static u32 last_status = -1;
1093 const u32 status = I915_READ(ch_ctl);
1094
1095 if (status != last_status) {
1096 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1097 status);
1098 last_status = status;
1099 }
1100
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001101 ret = -EBUSY;
1102 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001103 }
1104
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001105 /* Only 5 data registers! */
1106 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1107 ret = -E2BIG;
1108 goto out;
1109 }
1110
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001111 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001112 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1113 has_aux_irq,
1114 send_bytes,
1115 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001116
Chris Wilsonbc866252013-07-21 16:00:03 +01001117 /* Must try at least 3 times according to DP spec */
1118 for (try = 0; try < 5; try++) {
1119 /* Load the send data into the aux channel data registers */
1120 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001121 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001122 intel_dp_pack_aux(send + i,
1123 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001124
Chris Wilsonbc866252013-07-21 16:00:03 +01001125 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001126 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001127
Chris Wilsonbc866252013-07-21 16:00:03 +01001128 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001129
Chris Wilsonbc866252013-07-21 16:00:03 +01001130 /* Clear done status and any errors */
1131 I915_WRITE(ch_ctl,
1132 status |
1133 DP_AUX_CH_CTL_DONE |
1134 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1135 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001136
Todd Previte74ebf292015-04-15 08:38:41 -07001137 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001138 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001139
1140 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1141 * 400us delay required for errors and timeouts
1142 * Timeout errors from the HW already meet this
1143 * requirement so skip to next iteration
1144 */
1145 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1146 usleep_range(400, 500);
1147 continue;
1148 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001149 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001150 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001151 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001152 }
1153
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001154 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001155 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001156 ret = -EBUSY;
1157 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001158 }
1159
Jim Bridee058c942015-05-27 10:21:48 -07001160done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001161 /* Check for timeout or receive error.
1162 * Timeouts occur when the sink is not connected
1163 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001164 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001165 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001166 ret = -EIO;
1167 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001168 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001169
1170 /* Timeouts occur when the device isn't connected, so they're
1171 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001172 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001173 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001174 ret = -ETIMEDOUT;
1175 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001176 }
1177
1178 /* Unload any bytes sent back from the other side */
1179 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1180 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001181
1182 /*
1183 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1184 * We have no idea of what happened so we return -EBUSY so
1185 * drm layer takes care for the necessary retries.
1186 */
1187 if (recv_bytes == 0 || recv_bytes > 20) {
1188 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1189 recv_bytes);
1190 /*
1191 * FIXME: This patch was created on top of a series that
1192 * organize the retries at drm level. There EBUSY should
1193 * also take care for 1ms wait before retrying.
1194 * That aux retries re-org is still needed and after that is
1195 * merged we remove this sleep from here.
1196 */
1197 usleep_range(1000, 1500);
1198 ret = -EBUSY;
1199 goto out;
1200 }
1201
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001202 if (recv_bytes > recv_size)
1203 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001204
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001205 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001206 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001207 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001208
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001209 ret = recv_bytes;
1210out:
1211 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1212
Jani Nikula884f19e2014-03-14 16:51:14 +02001213 if (vdd)
1214 edp_panel_vdd_off(intel_dp, false);
1215
Ville Syrjälä773538e82014-09-04 14:54:56 +03001216 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001217
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001218 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001219}
1220
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001221#define BARE_ADDRESS_SIZE 3
1222#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001223static ssize_t
1224intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001225{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001226 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1227 uint8_t txbuf[20], rxbuf[20];
1228 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001229 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001230
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001231 txbuf[0] = (msg->request << 4) |
1232 ((msg->address >> 16) & 0xf);
1233 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001234 txbuf[2] = msg->address & 0xff;
1235 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001236
Jani Nikula9d1a1032014-03-14 16:51:15 +02001237 switch (msg->request & ~DP_AUX_I2C_MOT) {
1238 case DP_AUX_NATIVE_WRITE:
1239 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001240 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001241 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001242 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001243
Jani Nikula9d1a1032014-03-14 16:51:15 +02001244 if (WARN_ON(txsize > 20))
1245 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001246
Ville Syrjälädd788092016-07-28 17:55:04 +03001247 WARN_ON(!msg->buffer != !msg->size);
1248
Imre Deakd81a67c2016-01-29 14:52:26 +02001249 if (msg->buffer)
1250 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001251
Jani Nikula9d1a1032014-03-14 16:51:15 +02001252 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1253 if (ret > 0) {
1254 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001255
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001256 if (ret > 1) {
1257 /* Number of bytes written in a short write. */
1258 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1259 } else {
1260 /* Return payload size. */
1261 ret = msg->size;
1262 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001263 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001264 break;
1265
1266 case DP_AUX_NATIVE_READ:
1267 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001268 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001269 rxsize = msg->size + 1;
1270
1271 if (WARN_ON(rxsize > 20))
1272 return -E2BIG;
1273
1274 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1275 if (ret > 0) {
1276 msg->reply = rxbuf[0] >> 4;
1277 /*
1278 * Assume happy day, and copy the data. The caller is
1279 * expected to check msg->reply before touching it.
1280 *
1281 * Return payload size.
1282 */
1283 ret--;
1284 memcpy(msg->buffer, rxbuf + 1, ret);
1285 }
1286 break;
1287
1288 default:
1289 ret = -EINVAL;
1290 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001291 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001292
Jani Nikula9d1a1032014-03-14 16:51:15 +02001293 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001294}
1295
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001296static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1297 enum port port)
1298{
1299 const struct ddi_vbt_port_info *info =
1300 &dev_priv->vbt.ddi_port_info[port];
1301 enum port aux_port;
1302
1303 if (!info->alternate_aux_channel) {
1304 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1305 port_name(port), port_name(port));
1306 return port;
1307 }
1308
1309 switch (info->alternate_aux_channel) {
1310 case DP_AUX_A:
1311 aux_port = PORT_A;
1312 break;
1313 case DP_AUX_B:
1314 aux_port = PORT_B;
1315 break;
1316 case DP_AUX_C:
1317 aux_port = PORT_C;
1318 break;
1319 case DP_AUX_D:
1320 aux_port = PORT_D;
1321 break;
1322 default:
1323 MISSING_CASE(info->alternate_aux_channel);
1324 aux_port = PORT_A;
1325 break;
1326 }
1327
1328 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1329 port_name(aux_port), port_name(port));
1330
1331 return aux_port;
1332}
1333
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001334static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001335 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001336{
1337 switch (port) {
1338 case PORT_B:
1339 case PORT_C:
1340 case PORT_D:
1341 return DP_AUX_CH_CTL(port);
1342 default:
1343 MISSING_CASE(port);
1344 return DP_AUX_CH_CTL(PORT_B);
1345 }
1346}
1347
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001348static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001349 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001350{
1351 switch (port) {
1352 case PORT_B:
1353 case PORT_C:
1354 case PORT_D:
1355 return DP_AUX_CH_DATA(port, index);
1356 default:
1357 MISSING_CASE(port);
1358 return DP_AUX_CH_DATA(PORT_B, index);
1359 }
1360}
1361
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001362static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001363 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001364{
1365 switch (port) {
1366 case PORT_A:
1367 return DP_AUX_CH_CTL(port);
1368 case PORT_B:
1369 case PORT_C:
1370 case PORT_D:
1371 return PCH_DP_AUX_CH_CTL(port);
1372 default:
1373 MISSING_CASE(port);
1374 return DP_AUX_CH_CTL(PORT_A);
1375 }
1376}
1377
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001378static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001379 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001380{
1381 switch (port) {
1382 case PORT_A:
1383 return DP_AUX_CH_DATA(port, index);
1384 case PORT_B:
1385 case PORT_C:
1386 case PORT_D:
1387 return PCH_DP_AUX_CH_DATA(port, index);
1388 default:
1389 MISSING_CASE(port);
1390 return DP_AUX_CH_DATA(PORT_A, index);
1391 }
1392}
1393
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001394static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001395 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001396{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001397 switch (port) {
1398 case PORT_A:
1399 case PORT_B:
1400 case PORT_C:
1401 case PORT_D:
1402 return DP_AUX_CH_CTL(port);
1403 default:
1404 MISSING_CASE(port);
1405 return DP_AUX_CH_CTL(PORT_A);
1406 }
1407}
1408
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001409static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001410 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001411{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001412 switch (port) {
1413 case PORT_A:
1414 case PORT_B:
1415 case PORT_C:
1416 case PORT_D:
1417 return DP_AUX_CH_DATA(port, index);
1418 default:
1419 MISSING_CASE(port);
1420 return DP_AUX_CH_DATA(PORT_A, index);
1421 }
1422}
1423
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001424static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001425 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001426{
1427 if (INTEL_INFO(dev_priv)->gen >= 9)
1428 return skl_aux_ctl_reg(dev_priv, port);
1429 else if (HAS_PCH_SPLIT(dev_priv))
1430 return ilk_aux_ctl_reg(dev_priv, port);
1431 else
1432 return g4x_aux_ctl_reg(dev_priv, port);
1433}
1434
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001435static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001436 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001437{
1438 if (INTEL_INFO(dev_priv)->gen >= 9)
1439 return skl_aux_data_reg(dev_priv, port, index);
1440 else if (HAS_PCH_SPLIT(dev_priv))
1441 return ilk_aux_data_reg(dev_priv, port, index);
1442 else
1443 return g4x_aux_data_reg(dev_priv, port, index);
1444}
1445
1446static void intel_aux_reg_init(struct intel_dp *intel_dp)
1447{
1448 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001449 enum port port = intel_aux_port(dev_priv,
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001450 dp_to_dig_port(intel_dp)->base.port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001451 int i;
1452
1453 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1454 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1455 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1456}
1457
Jani Nikula9d1a1032014-03-14 16:51:15 +02001458static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001459intel_dp_aux_fini(struct intel_dp *intel_dp)
1460{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001461 kfree(intel_dp->aux.name);
1462}
1463
Chris Wilson7a418e32016-06-24 14:00:14 +01001464static void
Mika Kaholab6339582016-09-09 14:10:52 +03001465intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001466{
Jani Nikula33ad6622014-03-14 16:51:16 +02001467 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001468 enum port port = intel_dig_port->base.port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001469
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001470 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001471 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001472
Chris Wilson7a418e32016-06-24 14:00:14 +01001473 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001474 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001475 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001476}
1477
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001478bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301479{
Jani Nikulafc603ca2017-10-09 12:29:58 +03001480 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001481
Jani Nikulafc603ca2017-10-09 12:29:58 +03001482 return max_rate >= 540000;
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301483}
1484
Daniel Vetter0e503382014-07-04 11:26:04 -03001485static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001486intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001487 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001488{
1489 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001490 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001491 const struct dp_link_dpll *divisor = NULL;
1492 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001493
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001494 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001495 divisor = gen4_dpll;
1496 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001497 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001498 divisor = pch_dpll;
1499 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001500 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001501 divisor = chv_dpll;
1502 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001503 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001504 divisor = vlv_dpll;
1505 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001506 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001507
1508 if (divisor && count) {
1509 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001510 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001511 pipe_config->dpll = divisor[i].dpll;
1512 pipe_config->clock_set = true;
1513 break;
1514 }
1515 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001516 }
1517}
1518
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001519static void snprintf_int_array(char *str, size_t len,
1520 const int *array, int nelem)
1521{
1522 int i;
1523
1524 str[0] = '\0';
1525
1526 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001527 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001528 if (r >= len)
1529 return;
1530 str += r;
1531 len -= r;
1532 }
1533}
1534
1535static void intel_dp_print_rates(struct intel_dp *intel_dp)
1536{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001537 char str[128]; /* FIXME: too big for stack? */
1538
1539 if ((drm_debug & DRM_UT_KMS) == 0)
1540 return;
1541
Jani Nikula55cfc582017-03-28 17:59:04 +03001542 snprintf_int_array(str, sizeof(str),
1543 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001544 DRM_DEBUG_KMS("source rates: %s\n", str);
1545
Jani Nikula68f357c2017-03-28 17:59:05 +03001546 snprintf_int_array(str, sizeof(str),
1547 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001548 DRM_DEBUG_KMS("sink rates: %s\n", str);
1549
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001550 snprintf_int_array(str, sizeof(str),
1551 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001552 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001553}
1554
Ville Syrjälä50fec212015-03-12 17:10:34 +02001555int
1556intel_dp_max_link_rate(struct intel_dp *intel_dp)
1557{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001558 int len;
1559
Jani Nikulae6c0c642017-04-06 16:44:12 +03001560 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001561 if (WARN_ON(len <= 0))
1562 return 162000;
1563
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001564 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001565}
1566
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001567int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1568{
Jani Nikula8001b752017-03-28 17:59:03 +03001569 int i = intel_dp_rate_index(intel_dp->sink_rates,
1570 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001571
1572 if (WARN_ON(i < 0))
1573 i = 0;
1574
1575 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001576}
1577
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001578void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1579 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001580{
Jani Nikula68f357c2017-03-28 17:59:05 +03001581 /* eDP 1.4 rate select method. */
1582 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001583 *link_bw = 0;
1584 *rate_select =
1585 intel_dp_rate_select(intel_dp, port_clock);
1586 } else {
1587 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1588 *rate_select = 0;
1589 }
1590}
1591
Jani Nikulaf580bea2016-09-15 16:28:52 +03001592static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1593 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001594{
1595 int bpp, bpc;
1596
1597 bpp = pipe_config->pipe_bpp;
1598 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1599
1600 if (bpc > 0)
1601 bpp = min(bpp, 3*bpc);
1602
Manasi Navare611032b2017-01-24 08:21:49 -08001603 /* For DP Compliance we override the computed bpp for the pipe */
1604 if (intel_dp->compliance.test_data.bpc != 0) {
1605 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1606 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1607 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1608 pipe_config->pipe_bpp);
1609 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001610 return bpp;
1611}
1612
Jim Bridedc911f52017-08-09 12:48:53 -07001613static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1614 struct drm_display_mode *m2)
1615{
1616 bool bres = false;
1617
1618 if (m1 && m2)
1619 bres = (m1->hdisplay == m2->hdisplay &&
1620 m1->hsync_start == m2->hsync_start &&
1621 m1->hsync_end == m2->hsync_end &&
1622 m1->htotal == m2->htotal &&
1623 m1->vdisplay == m2->vdisplay &&
1624 m1->vsync_start == m2->vsync_start &&
1625 m1->vsync_end == m2->vsync_end &&
1626 m1->vtotal == m2->vtotal);
1627 return bres;
1628}
1629
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001630bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001631intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001632 struct intel_crtc_state *pipe_config,
1633 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001634{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001635 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001636 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001637 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001638 enum port port = encoder->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001639 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001640 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001641 struct intel_digital_connector_state *intel_conn_state =
1642 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001643 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001644 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001645 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001646 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001647 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301648 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001649 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001650 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001651 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001652 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001653 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1654 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301655
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001656 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001657 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301658
1659 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001660 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301661
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001662 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001663
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001664 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001665 pipe_config->has_pch_encoder = true;
1666
Vandana Kannanf769cd22014-08-05 07:51:22 -07001667 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001668 if (port == PORT_A)
1669 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001670 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001671 pipe_config->has_audio = intel_dp->has_audio;
1672 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001673 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001674
Jani Nikula1853a9d2017-08-18 12:30:20 +03001675 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jim Bridedc911f52017-08-09 12:48:53 -07001676 struct drm_display_mode *panel_mode =
1677 intel_connector->panel.alt_fixed_mode;
1678 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1679
1680 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1681 panel_mode = intel_connector->panel.fixed_mode;
1682
1683 drm_mode_debug_printmodeline(panel_mode);
1684
1685 intel_fixed_panel_mode(panel_mode, adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001686
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001687 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001688 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001689 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001690 if (ret)
1691 return ret;
1692 }
1693
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001694 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001695 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001696 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001697 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001698 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001699 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001700 }
1701
Daniel Vettercb1793c2012-06-04 18:39:21 +02001702 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001703 return false;
1704
Manasi Navareda15f7c2017-01-24 08:16:34 -08001705 /* Use values requested by Compliance Test Request */
1706 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001707 int index;
1708
Manasi Navare140ef132017-06-08 13:41:03 -07001709 /* Validate the compliance test data since max values
1710 * might have changed due to link train fallback.
1711 */
1712 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1713 intel_dp->compliance.test_lane_count)) {
1714 index = intel_dp_rate_index(intel_dp->common_rates,
1715 intel_dp->num_common_rates,
1716 intel_dp->compliance.test_link_rate);
1717 if (index >= 0)
1718 min_clock = max_clock = index;
1719 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1720 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08001721 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001722 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301723 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001724 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001725 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001726
Daniel Vetter36008362013-03-27 00:44:59 +01001727 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1728 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001729 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula1853a9d2017-08-18 12:30:20 +03001730 if (intel_dp_is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301731
1732 /* Get bpp from vbt only for panels that dont have bpp in edid */
1733 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001734 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001735 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001736 dev_priv->vbt.edp.bpp);
1737 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001738 }
1739
Jani Nikula344c5bb2014-09-09 11:25:13 +03001740 /*
1741 * Use the maximum clock and number of lanes the eDP panel
1742 * advertizes being capable of. The panels are generally
1743 * designed to support only a single clock and lane
1744 * configuration, and typically these values correspond to the
1745 * native resolution of the panel.
1746 */
1747 min_lane_count = max_lane_count;
1748 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001749 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001750
Daniel Vetter36008362013-03-27 00:44:59 +01001751 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001752 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1753 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001754
Dave Airliec6930992014-07-14 11:04:39 +10001755 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301756 for (lane_count = min_lane_count;
1757 lane_count <= max_lane_count;
1758 lane_count <<= 1) {
1759
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001760 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001761 link_avail = intel_dp_max_data_rate(link_clock,
1762 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001763
Daniel Vetter36008362013-03-27 00:44:59 +01001764 if (mode_rate <= link_avail) {
1765 goto found;
1766 }
1767 }
1768 }
1769 }
1770
1771 return false;
1772
1773found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001774 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001775 /*
1776 * See:
1777 * CEA-861-E - 5.1 Default Encoding Parameters
1778 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1779 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001780 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001781 bpp != 18 &&
1782 drm_default_rgb_quant_range(adjusted_mode) ==
1783 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001784 } else {
1785 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001786 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001787 }
1788
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001789 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301790
Daniel Vetter657445f2013-05-04 10:09:18 +02001791 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001792 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001793
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001794 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1795 &link_bw, &rate_select);
1796
1797 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1798 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001799 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001800 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1801 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001802
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001803 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001804 adjusted_mode->crtc_clock,
1805 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001806 &pipe_config->dp_m_n,
1807 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001808
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301809 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301810 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001811 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301812 intel_link_compute_m_n(bpp, lane_count,
1813 intel_connector->panel.downclock_mode->clock,
1814 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001815 &pipe_config->dp_m2_n2,
1816 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301817 }
1818
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001819 /*
1820 * DPLL0 VCO may need to be adjusted to get the correct
1821 * clock for eDP. This will affect cdclk as well.
1822 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03001823 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001824 int vco;
1825
1826 switch (pipe_config->port_clock / 2) {
1827 case 108000:
1828 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001829 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001830 break;
1831 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001832 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001833 break;
1834 }
1835
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001836 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001837 }
1838
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001839 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001840 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001841
Ville Syrjälä4d90f2d2017-10-12 16:02:01 +03001842 intel_psr_compute_config(intel_dp, pipe_config);
1843
Daniel Vetter36008362013-03-27 00:44:59 +01001844 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001845}
1846
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001847void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001848 int link_rate, uint8_t lane_count,
1849 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001850{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001851 intel_dp->link_rate = link_rate;
1852 intel_dp->lane_count = lane_count;
1853 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001854}
1855
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001856static void intel_dp_prepare(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03001857 const struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001858{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001859 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001860 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001861 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001862 enum port port = encoder->port;
Ville Syrjäläadc10302017-10-31 22:51:14 +02001863 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001864 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001865
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001866 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1867 pipe_config->lane_count,
1868 intel_crtc_has_type(pipe_config,
1869 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001870
Keith Packard417e8222011-11-01 19:54:11 -07001871 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001872 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001873 *
1874 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001875 * SNB CPU
1876 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001877 * CPT PCH
1878 *
1879 * IBX PCH and CPU are the same for almost everything,
1880 * except that the CPU DP PLL is configured in this
1881 * register
1882 *
1883 * CPT PCH is quite different, having many bits moved
1884 * to the TRANS_DP_CTL register instead. That
1885 * configuration happens (oddly) in ironlake_pch_enable
1886 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001887
Keith Packard417e8222011-11-01 19:54:11 -07001888 /* Preserve the BIOS-computed detected bit. This is
1889 * supposed to be read-only.
1890 */
1891 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001892
Keith Packard417e8222011-11-01 19:54:11 -07001893 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001894 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001895 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001896
Keith Packard417e8222011-11-01 19:54:11 -07001897 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001898
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001899 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001900 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1901 intel_dp->DP |= DP_SYNC_HS_HIGH;
1902 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1903 intel_dp->DP |= DP_SYNC_VS_HIGH;
1904 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1905
Jani Nikula6aba5b62013-10-04 15:08:10 +03001906 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001907 intel_dp->DP |= DP_ENHANCED_FRAMING;
1908
Daniel Vetter7c62a162013-06-01 17:16:20 +02001909 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001910 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001911 u32 trans_dp;
1912
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001913 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001914
1915 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1916 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1917 trans_dp |= TRANS_DP_ENH_FRAMING;
1918 else
1919 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1920 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001921 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001922 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001923 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001924
1925 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1926 intel_dp->DP |= DP_SYNC_HS_HIGH;
1927 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1928 intel_dp->DP |= DP_SYNC_VS_HIGH;
1929 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1930
Jani Nikula6aba5b62013-10-04 15:08:10 +03001931 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001932 intel_dp->DP |= DP_ENHANCED_FRAMING;
1933
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001934 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001935 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001936 else if (crtc->pipe == PIPE_B)
1937 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001938 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001939}
1940
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001941#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1942#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001943
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001944#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1945#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001946
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001947#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1948#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001949
Imre Deakde9c1b62016-06-16 20:01:46 +03001950static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1951 struct intel_dp *intel_dp);
1952
Daniel Vetter4be73782014-01-17 14:39:48 +01001953static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001954 u32 mask,
1955 u32 value)
1956{
Paulo Zanoni30add222012-10-26 19:05:45 -02001957 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001958 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001959 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001960
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001961 lockdep_assert_held(&dev_priv->pps_mutex);
1962
Imre Deakde9c1b62016-06-16 20:01:46 +03001963 intel_pps_verify_state(dev_priv, intel_dp);
1964
Jani Nikulabf13e812013-09-06 07:40:05 +03001965 pp_stat_reg = _pp_stat_reg(intel_dp);
1966 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001967
1968 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001969 mask, value,
1970 I915_READ(pp_stat_reg),
1971 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001972
Chris Wilson9036ff02016-06-30 15:33:09 +01001973 if (intel_wait_for_register(dev_priv,
1974 pp_stat_reg, mask, value,
1975 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001976 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001977 I915_READ(pp_stat_reg),
1978 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001979
1980 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001981}
1982
Daniel Vetter4be73782014-01-17 14:39:48 +01001983static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001984{
1985 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001986 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001987}
1988
Daniel Vetter4be73782014-01-17 14:39:48 +01001989static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001990{
Keith Packardbd943152011-09-18 23:09:52 -07001991 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001992 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001993}
Keith Packardbd943152011-09-18 23:09:52 -07001994
Daniel Vetter4be73782014-01-17 14:39:48 +01001995static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001996{
Abhay Kumard28d4732016-01-22 17:39:04 -08001997 ktime_t panel_power_on_time;
1998 s64 panel_power_off_duration;
1999
Keith Packard99ea7122011-11-01 19:57:50 -07002000 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02002001
Abhay Kumard28d4732016-01-22 17:39:04 -08002002 /* take the difference of currrent time and panel power off time
2003 * and then make panel wait for t11_t12 if needed. */
2004 panel_power_on_time = ktime_get_boottime();
2005 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2006
Paulo Zanonidce56b32013-12-19 14:29:40 -02002007 /* When we disable the VDD override bit last we have to do the manual
2008 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08002009 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2010 wait_remaining_ms_from_jiffies(jiffies,
2011 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002012
Daniel Vetter4be73782014-01-17 14:39:48 +01002013 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002014}
Keith Packardbd943152011-09-18 23:09:52 -07002015
Daniel Vetter4be73782014-01-17 14:39:48 +01002016static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002017{
2018 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2019 intel_dp->backlight_on_delay);
2020}
2021
Daniel Vetter4be73782014-01-17 14:39:48 +01002022static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002023{
2024 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2025 intel_dp->backlight_off_delay);
2026}
Keith Packard99ea7122011-11-01 19:57:50 -07002027
Keith Packard832dd3c2011-11-01 19:34:06 -07002028/* Read the current pp_control value, unlocking the register if it
2029 * is locked
2030 */
2031
Jesse Barnes453c5422013-03-28 09:55:41 -07002032static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002033{
Jesse Barnes453c5422013-03-28 09:55:41 -07002034 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002035 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002036 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002037
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002038 lockdep_assert_held(&dev_priv->pps_mutex);
2039
Jani Nikulabf13e812013-09-06 07:40:05 +03002040 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002041 if (WARN_ON(!HAS_DDI(dev_priv) &&
2042 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302043 control &= ~PANEL_UNLOCK_MASK;
2044 control |= PANEL_UNLOCK_REGS;
2045 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002046 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002047}
2048
Ville Syrjälä951468f2014-09-04 14:55:31 +03002049/*
2050 * Must be paired with edp_panel_vdd_off().
2051 * Must hold pps_mutex around the whole on/off sequence.
2052 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2053 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002054static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002055{
Paulo Zanoni30add222012-10-26 19:05:45 -02002056 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002057 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002058 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002059 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002060 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002061 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002062
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002063 lockdep_assert_held(&dev_priv->pps_mutex);
2064
Jani Nikula1853a9d2017-08-18 12:30:20 +03002065 if (!intel_dp_is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002066 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002067
Egbert Eich2c623c12014-11-25 12:54:57 +01002068 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002069 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002070
Daniel Vetter4be73782014-01-17 14:39:48 +01002071 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002072 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002073
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002074 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002075
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002076 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002077 port_name(intel_dig_port->base.port));
Keith Packardbd943152011-09-18 23:09:52 -07002078
Daniel Vetter4be73782014-01-17 14:39:48 +01002079 if (!edp_have_panel_power(intel_dp))
2080 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002081
Jesse Barnes453c5422013-03-28 09:55:41 -07002082 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002083 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002084
Jani Nikulabf13e812013-09-06 07:40:05 +03002085 pp_stat_reg = _pp_stat_reg(intel_dp);
2086 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002087
2088 I915_WRITE(pp_ctrl_reg, pp);
2089 POSTING_READ(pp_ctrl_reg);
2090 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2091 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002092 /*
2093 * If the panel wasn't on, delay before accessing aux channel
2094 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002095 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002096 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002097 port_name(intel_dig_port->base.port));
Keith Packardf01eca22011-09-28 16:48:10 -07002098 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002099 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002100
2101 return need_to_disable;
2102}
2103
Ville Syrjälä951468f2014-09-04 14:55:31 +03002104/*
2105 * Must be paired with intel_edp_panel_vdd_off() or
2106 * intel_edp_panel_off().
2107 * Nested calls to these functions are not allowed since
2108 * we drop the lock. Caller must use some higher level
2109 * locking to prevent nested calls from other threads.
2110 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002111void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002112{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002113 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002114
Jani Nikula1853a9d2017-08-18 12:30:20 +03002115 if (!intel_dp_is_edp(intel_dp))
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002116 return;
2117
Ville Syrjälä773538e82014-09-04 14:54:56 +03002118 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002119 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002120 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002121
Rob Clarke2c719b2014-12-15 13:56:32 -05002122 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002123 port_name(dp_to_dig_port(intel_dp)->base.port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002124}
2125
Daniel Vetter4be73782014-01-17 14:39:48 +01002126static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002127{
Paulo Zanoni30add222012-10-26 19:05:45 -02002128 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002129 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002130 struct intel_digital_port *intel_dig_port =
2131 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002132 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002133 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002134
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002135 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002136
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002137 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002138
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002139 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002140 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002141
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002142 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002143 port_name(intel_dig_port->base.port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002144
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002145 pp = ironlake_get_pp_control(intel_dp);
2146 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002147
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002148 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2149 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002150
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002151 I915_WRITE(pp_ctrl_reg, pp);
2152 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002153
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002154 /* Make sure sequencer is idle before allowing subsequent activity */
2155 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2156 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002157
Imre Deak5a162e22016-08-10 14:07:30 +03002158 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002159 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002160
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002161 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002162}
2163
Daniel Vetter4be73782014-01-17 14:39:48 +01002164static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002165{
2166 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2167 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002168
Ville Syrjälä773538e82014-09-04 14:54:56 +03002169 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002170 if (!intel_dp->want_panel_vdd)
2171 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002172 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002173}
2174
Imre Deakaba86892014-07-30 15:57:31 +03002175static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2176{
2177 unsigned long delay;
2178
2179 /*
2180 * Queue the timer to fire a long time from now (relative to the power
2181 * down delay) to keep the panel power up across a sequence of
2182 * operations.
2183 */
2184 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2185 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2186}
2187
Ville Syrjälä951468f2014-09-04 14:55:31 +03002188/*
2189 * Must be paired with edp_panel_vdd_on().
2190 * Must hold pps_mutex around the whole on/off sequence.
2191 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2192 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002193static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002194{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002195 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002196
2197 lockdep_assert_held(&dev_priv->pps_mutex);
2198
Jani Nikula1853a9d2017-08-18 12:30:20 +03002199 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002200 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002201
Rob Clarke2c719b2014-12-15 13:56:32 -05002202 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002203 port_name(dp_to_dig_port(intel_dp)->base.port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002204
Keith Packardbd943152011-09-18 23:09:52 -07002205 intel_dp->want_panel_vdd = false;
2206
Imre Deakaba86892014-07-30 15:57:31 +03002207 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002208 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002209 else
2210 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002211}
2212
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002213static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002214{
Paulo Zanoni30add222012-10-26 19:05:45 -02002215 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002216 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002217 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002218 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002219
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002220 lockdep_assert_held(&dev_priv->pps_mutex);
2221
Jani Nikula1853a9d2017-08-18 12:30:20 +03002222 if (!intel_dp_is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002223 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002224
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002225 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002226 port_name(dp_to_dig_port(intel_dp)->base.port));
Keith Packard99ea7122011-11-01 19:57:50 -07002227
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002228 if (WARN(edp_have_panel_power(intel_dp),
2229 "eDP port %c panel power already on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002230 port_name(dp_to_dig_port(intel_dp)->base.port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002231 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002232
Daniel Vetter4be73782014-01-17 14:39:48 +01002233 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002234
Jani Nikulabf13e812013-09-06 07:40:05 +03002235 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002236 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002237 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002238 /* ILK workaround: disable reset around power sequence */
2239 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002240 I915_WRITE(pp_ctrl_reg, pp);
2241 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002242 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002243
Imre Deak5a162e22016-08-10 14:07:30 +03002244 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002245 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002246 pp |= PANEL_POWER_RESET;
2247
Jesse Barnes453c5422013-03-28 09:55:41 -07002248 I915_WRITE(pp_ctrl_reg, pp);
2249 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002250
Daniel Vetter4be73782014-01-17 14:39:48 +01002251 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002252 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002253
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002254 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002255 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002256 I915_WRITE(pp_ctrl_reg, pp);
2257 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002258 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002259}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002260
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002261void intel_edp_panel_on(struct intel_dp *intel_dp)
2262{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002263 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002264 return;
2265
2266 pps_lock(intel_dp);
2267 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002268 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002269}
2270
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002271
2272static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002273{
Paulo Zanoni30add222012-10-26 19:05:45 -02002274 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002275 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002276 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002277 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002278
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002279 lockdep_assert_held(&dev_priv->pps_mutex);
2280
Jani Nikula1853a9d2017-08-18 12:30:20 +03002281 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002282 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002283
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002284 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002285 port_name(dp_to_dig_port(intel_dp)->base.port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002286
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002287 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002288 port_name(dp_to_dig_port(intel_dp)->base.port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002289
Jesse Barnes453c5422013-03-28 09:55:41 -07002290 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002291 /* We need to switch off panel power _and_ force vdd, for otherwise some
2292 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002293 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002294 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002295
Jani Nikulabf13e812013-09-06 07:40:05 +03002296 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002297
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002298 intel_dp->want_panel_vdd = false;
2299
Jesse Barnes453c5422013-03-28 09:55:41 -07002300 I915_WRITE(pp_ctrl_reg, pp);
2301 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002302
Daniel Vetter4be73782014-01-17 14:39:48 +01002303 wait_panel_off(intel_dp);
Manasi Navarecbacf022017-10-04 09:48:26 -07002304 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002305
2306 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002307 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002308}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002309
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002310void intel_edp_panel_off(struct intel_dp *intel_dp)
2311{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002312 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002313 return;
2314
2315 pps_lock(intel_dp);
2316 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002317 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002318}
2319
Jani Nikula1250d102014-08-12 17:11:39 +03002320/* Enable backlight in the panel power control. */
2321static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002322{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002323 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2324 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002325 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002326 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002327 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002328
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002329 /*
2330 * If we enable the backlight right away following a panel power
2331 * on, we may see slight flicker as the panel syncs with the eDP
2332 * link. So delay a bit to make sure the image is solid before
2333 * allowing it to appear.
2334 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002335 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002336
Ville Syrjälä773538e82014-09-04 14:54:56 +03002337 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002338
Jesse Barnes453c5422013-03-28 09:55:41 -07002339 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002340 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002341
Jani Nikulabf13e812013-09-06 07:40:05 +03002342 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002343
2344 I915_WRITE(pp_ctrl_reg, pp);
2345 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002346
Ville Syrjälä773538e82014-09-04 14:54:56 +03002347 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002348}
2349
Jani Nikula1250d102014-08-12 17:11:39 +03002350/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002351void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2352 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002353{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002354 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2355
Jani Nikula1853a9d2017-08-18 12:30:20 +03002356 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002357 return;
2358
2359 DRM_DEBUG_KMS("\n");
2360
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002361 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002362 _intel_edp_backlight_on(intel_dp);
2363}
2364
2365/* Disable backlight in the panel power control. */
2366static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002367{
Paulo Zanoni30add222012-10-26 19:05:45 -02002368 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002369 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002370 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002371 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002372
Jani Nikula1853a9d2017-08-18 12:30:20 +03002373 if (!intel_dp_is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07002374 return;
2375
Ville Syrjälä773538e82014-09-04 14:54:56 +03002376 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002377
Jesse Barnes453c5422013-03-28 09:55:41 -07002378 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002379 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002380
Jani Nikulabf13e812013-09-06 07:40:05 +03002381 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002382
2383 I915_WRITE(pp_ctrl_reg, pp);
2384 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002385
Ville Syrjälä773538e82014-09-04 14:54:56 +03002386 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002387
Paulo Zanonidce56b32013-12-19 14:29:40 -02002388 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002389 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002390}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002391
Jani Nikula1250d102014-08-12 17:11:39 +03002392/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002393void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002394{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002395 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2396
Jani Nikula1853a9d2017-08-18 12:30:20 +03002397 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002398 return;
2399
2400 DRM_DEBUG_KMS("\n");
2401
2402 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002403 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002404}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002405
Jani Nikula73580fb72014-08-12 17:11:41 +03002406/*
2407 * Hook for controlling the panel power control backlight through the bl_power
2408 * sysfs attribute. Take care to handle multiple calls.
2409 */
2410static void intel_edp_backlight_power(struct intel_connector *connector,
2411 bool enable)
2412{
2413 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002414 bool is_enabled;
2415
Ville Syrjälä773538e82014-09-04 14:54:56 +03002416 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002417 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002418 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002419
2420 if (is_enabled == enable)
2421 return;
2422
Jani Nikula23ba9372014-08-27 14:08:43 +03002423 DRM_DEBUG_KMS("panel power control backlight %s\n",
2424 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002425
2426 if (enable)
2427 _intel_edp_backlight_on(intel_dp);
2428 else
2429 _intel_edp_backlight_off(intel_dp);
2430}
2431
Ville Syrjälä64e10772015-10-29 21:26:01 +02002432static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2433{
2434 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2435 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2436 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2437
2438 I915_STATE_WARN(cur_state != state,
2439 "DP port %c state assertion failure (expected %s, current %s)\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002440 port_name(dig_port->base.port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002441 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002442}
2443#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2444
2445static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2446{
2447 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2448
2449 I915_STATE_WARN(cur_state != state,
2450 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002451 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002452}
2453#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2454#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2455
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002456static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002457 const struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002458{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002459 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002460 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002461
Ville Syrjälä64e10772015-10-29 21:26:01 +02002462 assert_pipe_disabled(dev_priv, crtc->pipe);
2463 assert_dp_port_disabled(intel_dp);
2464 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002465
Ville Syrjäläabfce942015-10-29 21:26:03 +02002466 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002467 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002468
2469 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2470
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002471 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002472 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2473 else
2474 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2475
2476 I915_WRITE(DP_A, intel_dp->DP);
2477 POSTING_READ(DP_A);
2478 udelay(500);
2479
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002480 /*
2481 * [DevILK] Work around required when enabling DP PLL
2482 * while a pipe is enabled going to FDI:
2483 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2484 * 2. Program DP PLL enable
2485 */
2486 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002487 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002488
Daniel Vetter07679352012-09-06 22:15:42 +02002489 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002490
Daniel Vetter07679352012-09-06 22:15:42 +02002491 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002492 POSTING_READ(DP_A);
2493 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002494}
2495
Ville Syrjäläadc10302017-10-31 22:51:14 +02002496static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2497 const struct intel_crtc_state *old_crtc_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002498{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002499 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002500 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002501
Ville Syrjälä64e10772015-10-29 21:26:01 +02002502 assert_pipe_disabled(dev_priv, crtc->pipe);
2503 assert_dp_port_disabled(intel_dp);
2504 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002505
Ville Syrjäläabfce942015-10-29 21:26:03 +02002506 DRM_DEBUG_KMS("disabling eDP PLL\n");
2507
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002508 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002509
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002510 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002511 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002512 udelay(200);
2513}
2514
Ville Syrjälä857c4162017-10-27 12:45:23 +03002515static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2516{
2517 /*
2518 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2519 * be capable of signalling downstream hpd with a long pulse.
2520 * Whether or not that means D3 is safe to use is not clear,
2521 * but let's assume so until proven otherwise.
2522 *
2523 * FIXME should really check all downstream ports...
2524 */
2525 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2526 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2527 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2528}
2529
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002530/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002531void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002532{
2533 int ret, i;
2534
2535 /* Should have a valid DPCD by this point */
2536 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2537 return;
2538
2539 if (mode != DRM_MODE_DPMS_ON) {
Ville Syrjälä857c4162017-10-27 12:45:23 +03002540 if (downstream_hpd_needs_d0(intel_dp))
2541 return;
2542
Jani Nikula9d1a1032014-03-14 16:51:15 +02002543 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2544 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002545 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002546 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2547
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002548 /*
2549 * When turning on, we need to retry for 1ms to give the sink
2550 * time to wake up.
2551 */
2552 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002553 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2554 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002555 if (ret == 1)
2556 break;
2557 msleep(1);
2558 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002559
2560 if (ret == 1 && lspcon->active)
2561 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002562 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002563
2564 if (ret != 1)
2565 DRM_DEBUG_KMS("failed to %s sink power state\n",
2566 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002567}
2568
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002569static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2570 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002571{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002572 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002573 enum port port = encoder->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002574 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002575 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002576 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002577 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002578
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002579 if (!intel_display_power_get_if_enabled(dev_priv,
2580 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002581 return false;
2582
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002583 ret = false;
2584
Imre Deak6d129be2014-03-05 16:20:54 +02002585 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002586
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002587 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002588 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002589
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002590 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002591 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002592 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002593 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002594
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002595 for_each_pipe(dev_priv, p) {
2596 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2597 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2598 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002599 ret = true;
2600
2601 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002602 }
2603 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002604
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002605 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002606 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002607 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002608 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2609 } else {
2610 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002611 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002612
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002613 ret = true;
2614
2615out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002616 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002617
2618 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002619}
2620
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002621static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002622 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002623{
2624 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002625 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002626 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002627 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002628 enum port port = encoder->port;
Ville Syrjäläadc10302017-10-31 22:51:14 +02002629 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002630
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002631 if (encoder->type == INTEL_OUTPUT_EDP)
2632 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2633 else
2634 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2635
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002636 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002637
2638 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002639
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002640 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002641 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2642
2643 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002644 flags |= DRM_MODE_FLAG_PHSYNC;
2645 else
2646 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002647
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002648 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002649 flags |= DRM_MODE_FLAG_PVSYNC;
2650 else
2651 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002652 } else {
2653 if (tmp & DP_SYNC_HS_HIGH)
2654 flags |= DRM_MODE_FLAG_PHSYNC;
2655 else
2656 flags |= DRM_MODE_FLAG_NHSYNC;
2657
2658 if (tmp & DP_SYNC_VS_HIGH)
2659 flags |= DRM_MODE_FLAG_PVSYNC;
2660 else
2661 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002662 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002663
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002664 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002665
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002666 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002667 pipe_config->limited_color_range = true;
2668
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002669 pipe_config->lane_count =
2670 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2671
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002672 intel_dp_get_m_n(crtc, pipe_config);
2673
Ville Syrjälä18442d02013-09-13 16:00:08 +03002674 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002675 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002676 pipe_config->port_clock = 162000;
2677 else
2678 pipe_config->port_clock = 270000;
2679 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002680
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002681 pipe_config->base.adjusted_mode.crtc_clock =
2682 intel_dotclock_calculate(pipe_config->port_clock,
2683 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002684
Jani Nikula1853a9d2017-08-18 12:30:20 +03002685 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02002686 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002687 /*
2688 * This is a big fat ugly hack.
2689 *
2690 * Some machines in UEFI boot mode provide us a VBT that has 18
2691 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2692 * unknown we fail to light up. Yet the same BIOS boots up with
2693 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2694 * max, not what it tells us to use.
2695 *
2696 * Note: This will still be broken if the eDP panel is not lit
2697 * up by the BIOS, and thus we can't get the mode at module
2698 * load.
2699 */
2700 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002701 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2702 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002703 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002704}
2705
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002706static void intel_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002707 const struct intel_crtc_state *old_crtc_state,
2708 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002709{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002710 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002711
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002712 if (old_crtc_state->has_audio)
Ville Syrjälä8ec47de2017-10-30 20:46:53 +02002713 intel_audio_codec_disable(encoder,
2714 old_crtc_state, old_conn_state);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002715
2716 /* Make sure the panel is off before trying to change the mode. But also
2717 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002718 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002719 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002720 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002721 intel_edp_panel_off(intel_dp);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002722}
2723
2724static void g4x_disable_dp(struct intel_encoder *encoder,
2725 const struct intel_crtc_state *old_crtc_state,
2726 const struct drm_connector_state *old_conn_state)
2727{
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002728 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Daniel Vetter37398502012-09-06 22:15:44 +02002729
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002730 /* disable the port before the pipe on g4x */
Ville Syrjäläadc10302017-10-31 22:51:14 +02002731 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002732}
2733
2734static void ilk_disable_dp(struct intel_encoder *encoder,
2735 const struct intel_crtc_state *old_crtc_state,
2736 const struct drm_connector_state *old_conn_state)
2737{
2738 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2739}
2740
2741static void vlv_disable_dp(struct intel_encoder *encoder,
2742 const struct intel_crtc_state *old_crtc_state,
2743 const struct drm_connector_state *old_conn_state)
2744{
2745 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2746
2747 intel_psr_disable(intel_dp, old_crtc_state);
2748
2749 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Jesse Barnesd240f202010-08-13 15:43:26 -07002750}
2751
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002752static void ilk_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002753 const struct intel_crtc_state *old_crtc_state,
2754 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002755{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002756 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläadc10302017-10-31 22:51:14 +02002757 enum port port = encoder->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002758
Ville Syrjäläadc10302017-10-31 22:51:14 +02002759 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002760
2761 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002762 if (port == PORT_A)
Ville Syrjäläadc10302017-10-31 22:51:14 +02002763 ironlake_edp_pll_off(intel_dp, old_crtc_state);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002764}
2765
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002766static void vlv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002767 const struct intel_crtc_state *old_crtc_state,
2768 const struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002769{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002770 intel_dp_link_down(encoder, old_crtc_state);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002771}
2772
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002773static void chv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002774 const struct intel_crtc_state *old_crtc_state,
2775 const struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002776{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002777 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002778
Ville Syrjäläadc10302017-10-31 22:51:14 +02002779 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002780
Ville Syrjäläa5805162015-05-26 20:42:30 +03002781 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002782
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002783 /* Assert data lane reset */
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02002784 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002785
Ville Syrjäläa5805162015-05-26 20:42:30 +03002786 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002787}
2788
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002789static void
2790_intel_dp_set_link_train(struct intel_dp *intel_dp,
2791 uint32_t *DP,
2792 uint8_t dp_train_pat)
2793{
2794 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2795 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002796 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002797 enum port port = intel_dig_port->base.port;
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002798
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002799 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2800 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2801 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2802
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002803 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002804 uint32_t temp = I915_READ(DP_TP_CTL(port));
2805
2806 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2807 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2808 else
2809 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2810
2811 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2812 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2813 case DP_TRAINING_PATTERN_DISABLE:
2814 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2815
2816 break;
2817 case DP_TRAINING_PATTERN_1:
2818 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2819 break;
2820 case DP_TRAINING_PATTERN_2:
2821 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2822 break;
2823 case DP_TRAINING_PATTERN_3:
2824 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2825 break;
2826 }
2827 I915_WRITE(DP_TP_CTL(port), temp);
2828
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002829 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002830 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002831 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2832
2833 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2834 case DP_TRAINING_PATTERN_DISABLE:
2835 *DP |= DP_LINK_TRAIN_OFF_CPT;
2836 break;
2837 case DP_TRAINING_PATTERN_1:
2838 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2839 break;
2840 case DP_TRAINING_PATTERN_2:
2841 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2842 break;
2843 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002844 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002845 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2846 break;
2847 }
2848
2849 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002850 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002851 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2852 else
2853 *DP &= ~DP_LINK_TRAIN_MASK;
2854
2855 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2856 case DP_TRAINING_PATTERN_DISABLE:
2857 *DP |= DP_LINK_TRAIN_OFF;
2858 break;
2859 case DP_TRAINING_PATTERN_1:
2860 *DP |= DP_LINK_TRAIN_PAT_1;
2861 break;
2862 case DP_TRAINING_PATTERN_2:
2863 *DP |= DP_LINK_TRAIN_PAT_2;
2864 break;
2865 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002866 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002867 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2868 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002869 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002870 *DP |= DP_LINK_TRAIN_PAT_2;
2871 }
2872 break;
2873 }
2874 }
2875}
2876
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002877static void intel_dp_enable_port(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002878 const struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002879{
2880 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002881 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002882
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002883 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002884
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002885 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002886
2887 /*
2888 * Magic for VLV/CHV. We _must_ first set up the register
2889 * without actually enabling the port, and then do another
2890 * write to enable the port. Otherwise link training will
2891 * fail when the power sequencer is freshly used for this port.
2892 */
2893 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002894 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002895 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002896
2897 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2898 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002899}
2900
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002901static void intel_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002902 const struct intel_crtc_state *pipe_config,
2903 const struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002904{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002905 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2906 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002907 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläadc10302017-10-31 22:51:14 +02002908 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002909 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002910 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002911
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002912 if (WARN_ON(dp_reg & DP_PORT_EN))
2913 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002914
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002915 pps_lock(intel_dp);
2916
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002917 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläadc10302017-10-31 22:51:14 +02002918 vlv_init_panel_power_sequencer(encoder, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002919
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002920 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002921
2922 edp_panel_vdd_on(intel_dp);
2923 edp_panel_on(intel_dp);
2924 edp_panel_vdd_off(intel_dp, true);
2925
2926 pps_unlock(intel_dp);
2927
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002928 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002929 unsigned int lane_mask = 0x0;
2930
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002931 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002932 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002933
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002934 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2935 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002936 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002937
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002938 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2939 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002940 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002941
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002942 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002943 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002944 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002945 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002946 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002947}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002948
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002949static void g4x_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002950 const struct intel_crtc_state *pipe_config,
2951 const struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002952{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002953 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002954 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002955}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002956
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002957static void vlv_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002958 const struct intel_crtc_state *pipe_config,
2959 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002960{
Jani Nikula828f5c62013-09-05 16:44:45 +03002961 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2962
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002963 intel_edp_backlight_on(pipe_config, conn_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002964 intel_psr_enable(intel_dp, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002965}
2966
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002967static void g4x_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002968 const struct intel_crtc_state *pipe_config,
2969 const struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002970{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002971 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002972 enum port port = encoder->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002973
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002974 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002975
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002976 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002977 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002978 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002979}
2980
Ville Syrjälä83b84592014-10-16 21:29:51 +03002981static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2982{
2983 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002984 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002985 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002986 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002987
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002988 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2989
Ville Syrjäläd1586942017-02-08 19:52:54 +02002990 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2991 return;
2992
Ville Syrjälä83b84592014-10-16 21:29:51 +03002993 edp_panel_vdd_off_sync(intel_dp);
2994
2995 /*
2996 * VLV seems to get confused when multiple power seqeuencers
2997 * have the same port selected (even if only one has power/vdd
2998 * enabled). The failure manifests as vlv_wait_port_ready() failing
2999 * CHV on the other hand doesn't seem to mind having the same port
3000 * selected in multiple power seqeuencers, but let's clear the
3001 * port select always when logically disconnecting a power sequencer
3002 * from a port.
3003 */
3004 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003005 pipe_name(pipe), port_name(intel_dig_port->base.port));
Ville Syrjälä83b84592014-10-16 21:29:51 +03003006 I915_WRITE(pp_on_reg, 0);
3007 POSTING_READ(pp_on_reg);
3008
3009 intel_dp->pps_pipe = INVALID_PIPE;
3010}
3011
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003012static void vlv_steal_power_sequencer(struct drm_device *dev,
3013 enum pipe pipe)
3014{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003015 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003016 struct intel_encoder *encoder;
3017
3018 lockdep_assert_held(&dev_priv->pps_mutex);
3019
Jani Nikula19c80542015-12-16 12:48:16 +02003020 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003021 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03003022 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003023
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003024 if (encoder->type != INTEL_OUTPUT_DP &&
3025 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003026 continue;
3027
3028 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003029 port = dp_to_dig_port(intel_dp)->base.port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003030
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003031 WARN(intel_dp->active_pipe == pipe,
3032 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3033 pipe_name(pipe), port_name(port));
3034
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003035 if (intel_dp->pps_pipe != pipe)
3036 continue;
3037
3038 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03003039 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003040
3041 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003042 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003043 }
3044}
3045
Ville Syrjäläadc10302017-10-31 22:51:14 +02003046static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3047 const struct intel_crtc_state *crtc_state)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003048{
Ville Syrjäläadc10302017-10-31 22:51:14 +02003049 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003050 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003051 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläadc10302017-10-31 22:51:14 +02003052 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003053
3054 lockdep_assert_held(&dev_priv->pps_mutex);
3055
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003056 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003057
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003058 if (intel_dp->pps_pipe != INVALID_PIPE &&
3059 intel_dp->pps_pipe != crtc->pipe) {
3060 /*
3061 * If another power sequencer was being used on this
3062 * port previously make sure to turn off vdd there while
3063 * we still have control of it.
3064 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003065 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003066 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003067
3068 /*
3069 * We may be stealing the power
3070 * sequencer from another port.
3071 */
3072 vlv_steal_power_sequencer(dev, crtc->pipe);
3073
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003074 intel_dp->active_pipe = crtc->pipe;
3075
Jani Nikula1853a9d2017-08-18 12:30:20 +03003076 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003077 return;
3078
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003079 /* now it's all ours */
3080 intel_dp->pps_pipe = crtc->pipe;
3081
3082 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
Ville Syrjäläadc10302017-10-31 22:51:14 +02003083 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003084
3085 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003086 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003087 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003088}
3089
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003090static void vlv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003091 const struct intel_crtc_state *pipe_config,
3092 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003093{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003094 vlv_phy_pre_encoder_enable(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003095
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003096 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003097}
3098
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003099static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003100 const struct intel_crtc_state *pipe_config,
3101 const struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003102{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003103 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003104
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003105 vlv_phy_pre_pll_enable(encoder, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003106}
3107
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003108static void chv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003109 const struct intel_crtc_state *pipe_config,
3110 const struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003111{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003112 chv_phy_pre_encoder_enable(encoder, pipe_config);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003113
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003114 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003115
3116 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003117 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003118}
3119
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003120static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003121 const struct intel_crtc_state *pipe_config,
3122 const struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003123{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003124 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003125
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003126 chv_phy_pre_pll_enable(encoder, pipe_config);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003127}
3128
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003129static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003130 const struct intel_crtc_state *old_crtc_state,
3131 const struct drm_connector_state *old_conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003132{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003133 chv_phy_post_pll_disable(encoder, old_crtc_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003134}
3135
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003136/*
3137 * Fetch AUX CH registers 0x202 - 0x207 which contain
3138 * link status information
3139 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003140bool
Keith Packard93f62da2011-11-01 19:45:03 -07003141intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003142{
Lyude9f085eb2016-04-13 10:58:33 -04003143 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3144 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003145}
3146
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303147static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3148{
3149 uint8_t psr_caps = 0;
3150
Imre Deak9bacd4b2017-05-10 12:21:48 +03003151 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3152 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303153 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3154}
3155
3156static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3157{
3158 uint8_t dprx = 0;
3159
Imre Deak9bacd4b2017-05-10 12:21:48 +03003160 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3161 &dprx) != 1)
3162 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303163 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3164}
3165
Chris Wilsona76f73d2017-01-14 10:51:13 +00003166static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303167{
3168 uint8_t alpm_caps = 0;
3169
Imre Deak9bacd4b2017-05-10 12:21:48 +03003170 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3171 &alpm_caps) != 1)
3172 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303173 return alpm_caps & DP_ALPM_CAP;
3174}
3175
Paulo Zanoni11002442014-06-13 18:45:41 -03003176/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003177uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003178intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003179{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003180 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003181 enum port port = dp_to_dig_port(intel_dp)->base.port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003182
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03003183 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003184 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3185 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003186 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303187 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003188 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303189 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003190 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003192 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003194}
3195
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003196uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003197intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3198{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003199 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003200 enum port port = dp_to_dig_port(intel_dp)->base.port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003201
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003202 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003203 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3205 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3206 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3207 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3209 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3211 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003212 default:
3213 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3214 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003215 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003216 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303217 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3218 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3220 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3221 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3222 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3223 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003224 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303225 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003226 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003227 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003228 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3230 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3231 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3232 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3233 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3234 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303237 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003238 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003239 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003240 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303241 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3242 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3243 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3244 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3245 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003246 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303247 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003248 }
3249 } else {
3250 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303251 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3252 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3254 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3255 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3256 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003258 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303259 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003260 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003261 }
3262}
3263
Daniel Vetter5829975c2015-04-16 11:36:52 +02003264static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003265{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003266 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003267 unsigned long demph_reg_value, preemph_reg_value,
3268 uniqtranscale_reg_value;
3269 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003270
3271 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303272 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003273 preemph_reg_value = 0x0004000;
3274 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003276 demph_reg_value = 0x2B405555;
3277 uniqtranscale_reg_value = 0x552AB83A;
3278 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303279 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003280 demph_reg_value = 0x2B404040;
3281 uniqtranscale_reg_value = 0x5548B83A;
3282 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003284 demph_reg_value = 0x2B245555;
3285 uniqtranscale_reg_value = 0x5560B83A;
3286 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003288 demph_reg_value = 0x2B405555;
3289 uniqtranscale_reg_value = 0x5598DA3A;
3290 break;
3291 default:
3292 return 0;
3293 }
3294 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003296 preemph_reg_value = 0x0002000;
3297 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303298 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003299 demph_reg_value = 0x2B404040;
3300 uniqtranscale_reg_value = 0x5552B83A;
3301 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303302 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003303 demph_reg_value = 0x2B404848;
3304 uniqtranscale_reg_value = 0x5580B83A;
3305 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303306 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003307 demph_reg_value = 0x2B404040;
3308 uniqtranscale_reg_value = 0x55ADDA3A;
3309 break;
3310 default:
3311 return 0;
3312 }
3313 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303314 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003315 preemph_reg_value = 0x0000000;
3316 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003318 demph_reg_value = 0x2B305555;
3319 uniqtranscale_reg_value = 0x5570B83A;
3320 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003322 demph_reg_value = 0x2B2B4040;
3323 uniqtranscale_reg_value = 0x55ADDA3A;
3324 break;
3325 default:
3326 return 0;
3327 }
3328 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003330 preemph_reg_value = 0x0006000;
3331 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303332 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003333 demph_reg_value = 0x1B405555;
3334 uniqtranscale_reg_value = 0x55ADDA3A;
3335 break;
3336 default:
3337 return 0;
3338 }
3339 break;
3340 default:
3341 return 0;
3342 }
3343
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003344 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3345 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003346
3347 return 0;
3348}
3349
Daniel Vetter5829975c2015-04-16 11:36:52 +02003350static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003351{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003352 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3353 u32 deemph_reg_value, margin_reg_value;
3354 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003355 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003356
3357 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303358 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003359 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003361 deemph_reg_value = 128;
3362 margin_reg_value = 52;
3363 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303364 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003365 deemph_reg_value = 128;
3366 margin_reg_value = 77;
3367 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303368 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003369 deemph_reg_value = 128;
3370 margin_reg_value = 102;
3371 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303372 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003373 deemph_reg_value = 128;
3374 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003375 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003376 break;
3377 default:
3378 return 0;
3379 }
3380 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303381 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003382 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003384 deemph_reg_value = 85;
3385 margin_reg_value = 78;
3386 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303387 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003388 deemph_reg_value = 85;
3389 margin_reg_value = 116;
3390 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303391 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003392 deemph_reg_value = 85;
3393 margin_reg_value = 154;
3394 break;
3395 default:
3396 return 0;
3397 }
3398 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303399 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003400 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303401 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003402 deemph_reg_value = 64;
3403 margin_reg_value = 104;
3404 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003406 deemph_reg_value = 64;
3407 margin_reg_value = 154;
3408 break;
3409 default:
3410 return 0;
3411 }
3412 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303413 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003414 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003416 deemph_reg_value = 43;
3417 margin_reg_value = 154;
3418 break;
3419 default:
3420 return 0;
3421 }
3422 break;
3423 default:
3424 return 0;
3425 }
3426
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003427 chv_set_phy_signal_level(encoder, deemph_reg_value,
3428 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003429
3430 return 0;
3431}
3432
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003433static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003434gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003435{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003436 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003437
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003438 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303439 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003440 default:
3441 signal_levels |= DP_VOLTAGE_0_4;
3442 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303443 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003444 signal_levels |= DP_VOLTAGE_0_6;
3445 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303446 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003447 signal_levels |= DP_VOLTAGE_0_8;
3448 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303449 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003450 signal_levels |= DP_VOLTAGE_1_2;
3451 break;
3452 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003453 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303454 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003455 default:
3456 signal_levels |= DP_PRE_EMPHASIS_0;
3457 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303458 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003459 signal_levels |= DP_PRE_EMPHASIS_3_5;
3460 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303461 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003462 signal_levels |= DP_PRE_EMPHASIS_6;
3463 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303464 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003465 signal_levels |= DP_PRE_EMPHASIS_9_5;
3466 break;
3467 }
3468 return signal_levels;
3469}
3470
Zhenyu Wange3421a12010-04-08 09:43:27 +08003471/* Gen6's DP voltage swing and pre-emphasis control */
3472static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003473gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003474{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003475 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3476 DP_TRAIN_PRE_EMPHASIS_MASK);
3477 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303478 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003480 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303481 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003482 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303483 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3484 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003485 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303486 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3487 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003488 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303489 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3490 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003491 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003492 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003493 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3494 "0x%x\n", signal_levels);
3495 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003496 }
3497}
3498
Keith Packard1a2eb462011-11-16 16:26:07 -08003499/* Gen7's DP voltage swing and pre-emphasis control */
3500static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003501gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003502{
3503 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3504 DP_TRAIN_PRE_EMPHASIS_MASK);
3505 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303506 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003507 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303508 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003509 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303510 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003511 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3512
Sonika Jindalbd600182014-08-08 16:23:41 +05303513 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003514 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303515 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003516 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3517
Sonika Jindalbd600182014-08-08 16:23:41 +05303518 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003519 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303520 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003521 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3522
3523 default:
3524 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3525 "0x%x\n", signal_levels);
3526 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3527 }
3528}
3529
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003530void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003531intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003532{
3533 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003534 enum port port = intel_dig_port->base.port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003535 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003536 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003537 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003538 uint8_t train_set = intel_dp->train_set[0];
3539
Rodrigo Vivid509af62017-08-29 16:22:24 -07003540 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3541 signal_levels = bxt_signal_levels(intel_dp);
3542 } else if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003543 signal_levels = ddi_signal_levels(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07003544 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003545 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003546 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003547 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003548 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003549 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003550 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003551 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003552 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003553 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003554 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3555 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003556 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003557 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3558 }
3559
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303560 if (mask)
3561 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3562
3563 DRM_DEBUG_KMS("Using vswing level %d\n",
3564 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3565 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3566 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3567 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003568
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003569 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003570
3571 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3572 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003573}
3574
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003575void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003576intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3577 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003578{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003579 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003580 struct drm_i915_private *dev_priv =
3581 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003582
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003583 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003584
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003585 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003586 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003587}
3588
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003589void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003590{
3591 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3592 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003593 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003594 enum port port = intel_dig_port->base.port;
Imre Deak3ab9c632013-05-03 12:57:41 +03003595 uint32_t val;
3596
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003597 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003598 return;
3599
3600 val = I915_READ(DP_TP_CTL(port));
3601 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3602 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3603 I915_WRITE(DP_TP_CTL(port), val);
3604
3605 /*
3606 * On PORT_A we can have only eDP in SST mode. There the only reason
3607 * we need to set idle transmission mode is to work around a HW issue
3608 * where we enable the pipe while not in idle link-training mode.
3609 * In this case there is requirement to wait for a minimum number of
3610 * idle patterns to be sent.
3611 */
3612 if (port == PORT_A)
3613 return;
3614
Chris Wilsona7670172016-06-30 15:33:10 +01003615 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3616 DP_TP_STATUS_IDLE_DONE,
3617 DP_TP_STATUS_IDLE_DONE,
3618 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003619 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3620}
3621
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003622static void
Ville Syrjäläadc10302017-10-31 22:51:14 +02003623intel_dp_link_down(struct intel_encoder *encoder,
3624 const struct intel_crtc_state *old_crtc_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003625{
Ville Syrjäläadc10302017-10-31 22:51:14 +02003626 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3627 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3628 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3629 enum port port = encoder->port;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003630 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003631
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003632 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003633 return;
3634
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003635 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003636 return;
3637
Zhao Yakui28c97732009-10-09 11:39:41 +08003638 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003639
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003640 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003641 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003642 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003643 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003644 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003645 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003646 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3647 else
3648 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003649 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003650 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003651 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003652 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003653
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003654 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3655 I915_WRITE(intel_dp->output_reg, DP);
3656 POSTING_READ(intel_dp->output_reg);
3657
3658 /*
3659 * HW workaround for IBX, we need to move the port
3660 * to transcoder A after disabling it to allow the
3661 * matching HDMI port to be enabled on transcoder A.
3662 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003663 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003664 /*
3665 * We get CPU/PCH FIFO underruns on the other pipe when
3666 * doing the workaround. Sweep them under the rug.
3667 */
3668 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3669 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3670
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003671 /* always enable with pattern 1 (as per spec) */
3672 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3673 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3674 I915_WRITE(intel_dp->output_reg, DP);
3675 POSTING_READ(intel_dp->output_reg);
3676
3677 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003678 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003679 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003680
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003681 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003682 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3683 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003684 }
3685
Keith Packardf01eca22011-09-28 16:48:10 -07003686 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003687
3688 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003689
3690 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3691 pps_lock(intel_dp);
3692 intel_dp->active_pipe = INVALID_PIPE;
3693 pps_unlock(intel_dp);
3694 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003695}
3696
Imre Deak24e807e2016-10-24 19:33:28 +03003697bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003698intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003699{
Lyude9f085eb2016-04-13 10:58:33 -04003700 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3701 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003702 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003703
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003704 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003705
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003706 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3707}
3708
3709static bool
3710intel_edp_init_dpcd(struct intel_dp *intel_dp)
3711{
3712 struct drm_i915_private *dev_priv =
3713 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3714
3715 /* this function is meant to be called only once */
3716 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3717
3718 if (!intel_dp_read_dpcd(intel_dp))
3719 return false;
3720
Jani Nikula84c36752017-05-18 14:10:23 +03003721 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3722 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003723
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003724 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3725 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3726 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3727
3728 /* Check if the panel supports PSR */
3729 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3730 intel_dp->psr_dpcd,
3731 sizeof(intel_dp->psr_dpcd));
3732 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3733 dev_priv->psr.sink_support = true;
3734 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3735 }
3736
3737 if (INTEL_GEN(dev_priv) >= 9 &&
3738 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3739 uint8_t frame_sync_cap;
3740
3741 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003742 if (drm_dp_dpcd_readb(&intel_dp->aux,
3743 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3744 &frame_sync_cap) != 1)
3745 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003746 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3747 /* PSR2 needs frame sync as well */
3748 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3749 DRM_DEBUG_KMS("PSR2 %s on sink",
3750 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303751
3752 if (dev_priv->psr.psr2_support) {
3753 dev_priv->psr.y_cord_support =
3754 intel_dp_get_y_cord_status(intel_dp);
3755 dev_priv->psr.colorimetry_support =
3756 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303757 dev_priv->psr.alpm =
3758 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303759 }
3760
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003761 }
3762
Jani Nikula0501a3b2017-10-26 17:29:31 +03003763 /*
3764 * Read the eDP display control registers.
3765 *
3766 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3767 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3768 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3769 * method). The display control registers should read zero if they're
3770 * not supported anyway.
3771 */
3772 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003773 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3774 sizeof(intel_dp->edp_dpcd))
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003775 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003776 intel_dp->edp_dpcd);
3777
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003778 /* Read the eDP 1.4+ supported link rates. */
3779 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003780 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3781 int i;
3782
3783 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3784 sink_rates, sizeof(sink_rates));
3785
3786 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3787 int val = le16_to_cpu(sink_rates[i]);
3788
3789 if (val == 0)
3790 break;
3791
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003792 /* Value read multiplied by 200kHz gives the per-lane
3793 * link rate in kHz. The source rates are, however,
3794 * stored in terms of LS_Clk kHz. The full conversion
3795 * back to symbols is
3796 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3797 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003798 intel_dp->sink_rates[i] = (val * 200) / 10;
3799 }
3800 intel_dp->num_sink_rates = i;
3801 }
3802
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003803 /*
3804 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3805 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3806 */
Jani Nikula68f357c2017-03-28 17:59:05 +03003807 if (intel_dp->num_sink_rates)
3808 intel_dp->use_rate_select = true;
3809 else
3810 intel_dp_set_sink_rates(intel_dp);
3811
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003812 intel_dp_set_common_rates(intel_dp);
3813
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003814 return true;
3815}
3816
3817
3818static bool
3819intel_dp_get_dpcd(struct intel_dp *intel_dp)
3820{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003821 u8 sink_count;
3822
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003823 if (!intel_dp_read_dpcd(intel_dp))
3824 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003825
Jani Nikula68f357c2017-03-28 17:59:05 +03003826 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003827 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003828 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003829 intel_dp_set_common_rates(intel_dp);
3830 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003831
Jani Nikula27dbefb2017-04-06 16:44:17 +03003832 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303833 return false;
3834
3835 /*
3836 * Sink count can change between short pulse hpd hence
3837 * a member variable in intel_dp will track any changes
3838 * between short pulse interrupts.
3839 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003840 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303841
3842 /*
3843 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3844 * a dongle is present but no display. Unless we require to know
3845 * if a dongle is present or not, we don't need to update
3846 * downstream port information. So, an early return here saves
3847 * time from performing other operations which are not required.
3848 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003849 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303850 return false;
3851
Imre Deakc726ad02016-10-24 19:33:24 +03003852 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003853 return true; /* native DP sink */
3854
3855 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3856 return true; /* no per-port downstream info */
3857
Lyude9f085eb2016-04-13 10:58:33 -04003858 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3859 intel_dp->downstream_ports,
3860 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003861 return false; /* downstream port status fetch failed */
3862
3863 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003864}
3865
Dave Airlie0e32b392014-05-02 14:02:48 +10003866static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003867intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003868{
Jani Nikula010b9b32017-04-06 16:44:16 +03003869 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003870
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003871 if (!i915_modparams.enable_dp_mst)
Nathan Schulte7cc96132016-03-15 10:14:05 -05003872 return false;
3873
Dave Airlie0e32b392014-05-02 14:02:48 +10003874 if (!intel_dp->can_mst)
3875 return false;
3876
3877 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3878 return false;
3879
Jani Nikula010b9b32017-04-06 16:44:16 +03003880 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003881 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003882
Jani Nikula010b9b32017-04-06 16:44:16 +03003883 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003884}
3885
3886static void
3887intel_dp_configure_mst(struct intel_dp *intel_dp)
3888{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003889 if (!i915_modparams.enable_dp_mst)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003890 return;
3891
3892 if (!intel_dp->can_mst)
3893 return;
3894
3895 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3896
3897 if (intel_dp->is_mst)
3898 DRM_DEBUG_KMS("Sink is MST capable\n");
3899 else
3900 DRM_DEBUG_KMS("Sink is not MST capable\n");
3901
3902 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3903 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003904}
3905
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003906static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003907{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003908 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003909 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003910 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003911 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003912 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003913 int count = 0;
3914 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003915
3916 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003917 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003918 ret = -EIO;
3919 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003920 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003921
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003922 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003923 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003924 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003925 ret = -EIO;
3926 goto out;
3927 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003928
Rodrigo Vivic6297842015-11-05 10:50:20 -08003929 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003930 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003931
3932 if (drm_dp_dpcd_readb(&intel_dp->aux,
3933 DP_TEST_SINK_MISC, &buf) < 0) {
3934 ret = -EIO;
3935 goto out;
3936 }
3937 count = buf & DP_TEST_COUNT_MASK;
3938 } while (--attempts && count);
3939
3940 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003941 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003942 ret = -ETIMEDOUT;
3943 }
3944
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003945 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003946 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003947 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003948}
3949
3950static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3951{
3952 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003953 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003954 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3955 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003956 int ret;
3957
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003958 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3959 return -EIO;
3960
3961 if (!(buf & DP_TEST_CRC_SUPPORTED))
3962 return -ENOTTY;
3963
3964 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3965 return -EIO;
3966
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003967 if (buf & DP_TEST_SINK_START) {
3968 ret = intel_dp_sink_crc_stop(intel_dp);
3969 if (ret)
3970 return ret;
3971 }
3972
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003973 hsw_disable_ips(intel_crtc);
3974
3975 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3976 buf | DP_TEST_SINK_START) < 0) {
3977 hsw_enable_ips(intel_crtc);
3978 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003979 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003980
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003981 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003982 return 0;
3983}
3984
3985int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3986{
3987 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003988 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003989 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3990 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003991 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003992 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003993
3994 ret = intel_dp_sink_crc_start(intel_dp);
3995 if (ret)
3996 return ret;
3997
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003998 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003999 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004000
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07004001 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004002 DP_TEST_SINK_MISC, &buf) < 0) {
4003 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004004 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004005 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004006 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07004007
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004008 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004009
4010 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004011 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4012 ret = -ETIMEDOUT;
4013 goto stop;
4014 }
4015
4016 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4017 ret = -EIO;
4018 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004019 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004020
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004021stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004022 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004023 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004024}
4025
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004026static bool
4027intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4028{
Jani Nikula010b9b32017-04-06 16:44:16 +03004029 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4030 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004031}
4032
Dave Airlie0e32b392014-05-02 14:02:48 +10004033static bool
4034intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4035{
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004036 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4037 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4038 DP_DPRX_ESI_LEN;
Dave Airlie0e32b392014-05-02 14:02:48 +10004039}
4040
Todd Previtec5d5ab72015-04-15 08:38:38 -07004041static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004042{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004043 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004044 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004045 uint8_t test_lane_count, test_link_bw;
4046 /* (DP CTS 1.2)
4047 * 4.3.1.11
4048 */
4049 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4050 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4051 &test_lane_count);
4052
4053 if (status <= 0) {
4054 DRM_DEBUG_KMS("Lane count read failed\n");
4055 return DP_TEST_NAK;
4056 }
4057 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004058
4059 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4060 &test_link_bw);
4061 if (status <= 0) {
4062 DRM_DEBUG_KMS("Link Rate read failed\n");
4063 return DP_TEST_NAK;
4064 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004065 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004066
4067 /* Validate the requested link rate and lane count */
4068 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4069 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004070 return DP_TEST_NAK;
4071
4072 intel_dp->compliance.test_lane_count = test_lane_count;
4073 intel_dp->compliance.test_link_rate = test_link_rate;
4074
4075 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004076}
4077
4078static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4079{
Manasi Navare611032b2017-01-24 08:21:49 -08004080 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004081 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004082 __be16 h_width, v_height;
4083 int status = 0;
4084
4085 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004086 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4087 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004088 if (status <= 0) {
4089 DRM_DEBUG_KMS("Test pattern read failed\n");
4090 return DP_TEST_NAK;
4091 }
4092 if (test_pattern != DP_COLOR_RAMP)
4093 return DP_TEST_NAK;
4094
4095 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4096 &h_width, 2);
4097 if (status <= 0) {
4098 DRM_DEBUG_KMS("H Width read failed\n");
4099 return DP_TEST_NAK;
4100 }
4101
4102 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4103 &v_height, 2);
4104 if (status <= 0) {
4105 DRM_DEBUG_KMS("V Height read failed\n");
4106 return DP_TEST_NAK;
4107 }
4108
Jani Nikula010b9b32017-04-06 16:44:16 +03004109 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4110 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004111 if (status <= 0) {
4112 DRM_DEBUG_KMS("TEST MISC read failed\n");
4113 return DP_TEST_NAK;
4114 }
4115 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4116 return DP_TEST_NAK;
4117 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4118 return DP_TEST_NAK;
4119 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4120 case DP_TEST_BIT_DEPTH_6:
4121 intel_dp->compliance.test_data.bpc = 6;
4122 break;
4123 case DP_TEST_BIT_DEPTH_8:
4124 intel_dp->compliance.test_data.bpc = 8;
4125 break;
4126 default:
4127 return DP_TEST_NAK;
4128 }
4129
4130 intel_dp->compliance.test_data.video_pattern = test_pattern;
4131 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4132 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4133 /* Set test active flag here so userspace doesn't interrupt things */
4134 intel_dp->compliance.test_active = 1;
4135
4136 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004137}
4138
4139static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4140{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004141 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004142 struct intel_connector *intel_connector = intel_dp->attached_connector;
4143 struct drm_connector *connector = &intel_connector->base;
4144
4145 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004146 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004147 intel_dp->aux.i2c_defer_count > 6) {
4148 /* Check EDID read for NACKs, DEFERs and corruption
4149 * (DP CTS 1.2 Core r1.1)
4150 * 4.2.2.4 : Failed EDID read, I2C_NAK
4151 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4152 * 4.2.2.6 : EDID corruption detected
4153 * Use failsafe mode for all cases
4154 */
4155 if (intel_dp->aux.i2c_nack_count > 0 ||
4156 intel_dp->aux.i2c_defer_count > 0)
4157 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4158 intel_dp->aux.i2c_nack_count,
4159 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004160 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004161 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304162 struct edid *block = intel_connector->detect_edid;
4163
4164 /* We have to write the checksum
4165 * of the last block read
4166 */
4167 block += intel_connector->detect_edid->extensions;
4168
Jani Nikula010b9b32017-04-06 16:44:16 +03004169 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4170 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004171 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4172
4173 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004174 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004175 }
4176
4177 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004178 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004179
Todd Previtec5d5ab72015-04-15 08:38:38 -07004180 return test_result;
4181}
4182
4183static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4184{
4185 uint8_t test_result = DP_TEST_NAK;
4186 return test_result;
4187}
4188
4189static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4190{
4191 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004192 uint8_t request = 0;
4193 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004194
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004195 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004196 if (status <= 0) {
4197 DRM_DEBUG_KMS("Could not read test request from sink\n");
4198 goto update_status;
4199 }
4200
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004201 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004202 case DP_TEST_LINK_TRAINING:
4203 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004204 response = intel_dp_autotest_link_training(intel_dp);
4205 break;
4206 case DP_TEST_LINK_VIDEO_PATTERN:
4207 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004208 response = intel_dp_autotest_video_pattern(intel_dp);
4209 break;
4210 case DP_TEST_LINK_EDID_READ:
4211 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004212 response = intel_dp_autotest_edid(intel_dp);
4213 break;
4214 case DP_TEST_LINK_PHY_TEST_PATTERN:
4215 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004216 response = intel_dp_autotest_phy_pattern(intel_dp);
4217 break;
4218 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004219 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004220 break;
4221 }
4222
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004223 if (response & DP_TEST_ACK)
4224 intel_dp->compliance.test_type = request;
4225
Todd Previtec5d5ab72015-04-15 08:38:38 -07004226update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004227 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004228 if (status <= 0)
4229 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004230}
4231
Dave Airlie0e32b392014-05-02 14:02:48 +10004232static int
4233intel_dp_check_mst_status(struct intel_dp *intel_dp)
4234{
4235 bool bret;
4236
4237 if (intel_dp->is_mst) {
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004238 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
Dave Airlie0e32b392014-05-02 14:02:48 +10004239 int ret = 0;
4240 int retry;
4241 bool handled;
4242 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4243go_again:
4244 if (bret == true) {
4245
4246 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004247 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004248 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004249 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4250 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004251 intel_dp_stop_link_train(intel_dp);
4252 }
4253
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004254 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004255 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4256
4257 if (handled) {
4258 for (retry = 0; retry < 3; retry++) {
4259 int wret;
4260 wret = drm_dp_dpcd_write(&intel_dp->aux,
4261 DP_SINK_COUNT_ESI+1,
4262 &esi[1], 3);
4263 if (wret == 3) {
4264 break;
4265 }
4266 }
4267
4268 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4269 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004270 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004271 goto go_again;
4272 }
4273 } else
4274 ret = 0;
4275
4276 return ret;
4277 } else {
4278 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4279 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4280 intel_dp->is_mst = false;
4281 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4282 /* send a hotplug event */
4283 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4284 }
4285 }
4286 return -EINVAL;
4287}
4288
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304289static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004290intel_dp_retrain_link(struct intel_dp *intel_dp)
4291{
4292 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4293 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4294 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4295
4296 /* Suppress underruns caused by re-training */
4297 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4298 if (crtc->config->has_pch_encoder)
4299 intel_set_pch_fifo_underrun_reporting(dev_priv,
4300 intel_crtc_pch_transcoder(crtc), false);
4301
4302 intel_dp_start_link_train(intel_dp);
4303 intel_dp_stop_link_train(intel_dp);
4304
4305 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004306 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004307
4308 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4309 if (crtc->config->has_pch_encoder)
4310 intel_set_pch_fifo_underrun_reporting(dev_priv,
4311 intel_crtc_pch_transcoder(crtc), true);
4312}
4313
4314static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304315intel_dp_check_link_status(struct intel_dp *intel_dp)
4316{
4317 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4318 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4319 u8 link_status[DP_LINK_STATUS_SIZE];
4320
4321 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4322
4323 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4324 DRM_ERROR("Failed to get link status\n");
4325 return;
4326 }
4327
4328 if (!intel_encoder->base.crtc)
4329 return;
4330
4331 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4332 return;
4333
Manasi Navare14c562c2017-04-06 14:00:12 -07004334 /*
4335 * Validate the cached values of intel_dp->link_rate and
4336 * intel_dp->lane_count before attempting to retrain.
4337 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004338 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4339 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004340 return;
4341
Manasi Navareda15f7c2017-01-24 08:16:34 -08004342 /* Retrain if Channel EQ or CR not ok */
4343 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304344 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4345 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004346
4347 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304348 }
4349}
4350
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004351/*
4352 * According to DP spec
4353 * 5.1.2:
4354 * 1. Read DPCD
4355 * 2. Configure link according to Receiver Capabilities
4356 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4357 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304358 *
4359 * intel_dp_short_pulse - handles short pulse interrupts
4360 * when full detection is not required.
4361 * Returns %true if short pulse is handled and full detection
4362 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004363 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304364static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304365intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004366{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004367 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004368 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004369 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304370 u8 old_sink_count = intel_dp->sink_count;
4371 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004372
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304373 /*
4374 * Clearing compliance test variables to allow capturing
4375 * of values for next automated test request.
4376 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004377 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304378
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304379 /*
4380 * Now read the DPCD to see if it's actually running
4381 * If the current value of sink count doesn't match with
4382 * the value that was stored earlier or dpcd read failed
4383 * we need to do full detection
4384 */
4385 ret = intel_dp_get_dpcd(intel_dp);
4386
4387 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4388 /* No need to proceed if we are going to do full detect */
4389 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004390 }
4391
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004392 /* Try to read the source of the interrupt */
4393 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004394 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4395 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004396 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004397 drm_dp_dpcd_writeb(&intel_dp->aux,
4398 DP_DEVICE_SERVICE_IRQ_VECTOR,
4399 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004400
4401 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004402 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004403 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4404 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4405 }
4406
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304407 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4408 intel_dp_check_link_status(intel_dp);
4409 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004410 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4411 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4412 /* Send a Hotplug Uevent to userspace to start modeset */
4413 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4414 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304415
4416 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004417}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004418
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004419/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004420static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004421intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004422{
Imre Deake393d0d2017-02-22 17:10:52 +02004423 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004424 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004425 uint8_t type;
4426
Imre Deake393d0d2017-02-22 17:10:52 +02004427 if (lspcon->active)
4428 lspcon_resume(lspcon);
4429
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004430 if (!intel_dp_get_dpcd(intel_dp))
4431 return connector_status_disconnected;
4432
Jani Nikula1853a9d2017-08-18 12:30:20 +03004433 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304434 return connector_status_connected;
4435
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004436 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004437 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004438 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004439
4440 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004441 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4442 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004443
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304444 return intel_dp->sink_count ?
4445 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004446 }
4447
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004448 if (intel_dp_can_mst(intel_dp))
4449 return connector_status_connected;
4450
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004451 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004452 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004453 return connector_status_connected;
4454
4455 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004456 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4457 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4458 if (type == DP_DS_PORT_TYPE_VGA ||
4459 type == DP_DS_PORT_TYPE_NON_EDID)
4460 return connector_status_unknown;
4461 } else {
4462 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4463 DP_DWN_STRM_PORT_TYPE_MASK;
4464 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4465 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4466 return connector_status_unknown;
4467 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004468
4469 /* Anything else is out of spec, warn and ignore */
4470 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004471 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004472}
4473
4474static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004475edp_detect(struct intel_dp *intel_dp)
4476{
4477 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004478 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004479 enum drm_connector_status status;
4480
Mika Kahola1650be72016-12-13 10:02:47 +02004481 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004482 if (status == connector_status_unknown)
4483 status = connector_status_connected;
4484
4485 return status;
4486}
4487
Jani Nikulab93433c2015-08-20 10:47:36 +03004488static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4489 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004490{
Jani Nikulab93433c2015-08-20 10:47:36 +03004491 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004492
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004493 switch (port->base.port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004494 case PORT_B:
4495 bit = SDE_PORTB_HOTPLUG;
4496 break;
4497 case PORT_C:
4498 bit = SDE_PORTC_HOTPLUG;
4499 break;
4500 case PORT_D:
4501 bit = SDE_PORTD_HOTPLUG;
4502 break;
4503 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004504 MISSING_CASE(port->base.port);
Jani Nikula0df53b72015-08-20 10:47:40 +03004505 return false;
4506 }
4507
4508 return I915_READ(SDEISR) & bit;
4509}
4510
4511static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4512 struct intel_digital_port *port)
4513{
4514 u32 bit;
4515
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004516 switch (port->base.port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004517 case PORT_B:
4518 bit = SDE_PORTB_HOTPLUG_CPT;
4519 break;
4520 case PORT_C:
4521 bit = SDE_PORTC_HOTPLUG_CPT;
4522 break;
4523 case PORT_D:
4524 bit = SDE_PORTD_HOTPLUG_CPT;
4525 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004526 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004527 MISSING_CASE(port->base.port);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004528 return false;
4529 }
4530
4531 return I915_READ(SDEISR) & bit;
4532}
4533
4534static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4535 struct intel_digital_port *port)
4536{
4537 u32 bit;
4538
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004539 switch (port->base.port) {
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004540 case PORT_A:
4541 bit = SDE_PORTA_HOTPLUG_SPT;
4542 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004543 case PORT_E:
4544 bit = SDE_PORTE_HOTPLUG_SPT;
4545 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004546 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004547 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004548 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004549
Jani Nikulab93433c2015-08-20 10:47:36 +03004550 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004551}
4552
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004553static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004554 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004555{
Jani Nikula9642c812015-08-20 10:47:41 +03004556 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004557
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004558 switch (port->base.port) {
Jani Nikula9642c812015-08-20 10:47:41 +03004559 case PORT_B:
4560 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4561 break;
4562 case PORT_C:
4563 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4564 break;
4565 case PORT_D:
4566 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4567 break;
4568 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004569 MISSING_CASE(port->base.port);
Jani Nikula9642c812015-08-20 10:47:41 +03004570 return false;
4571 }
4572
4573 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4574}
4575
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004576static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4577 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004578{
4579 u32 bit;
4580
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004581 switch (port->base.port) {
Jani Nikula9642c812015-08-20 10:47:41 +03004582 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004583 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004584 break;
4585 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004586 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004587 break;
4588 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004589 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004590 break;
4591 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004592 MISSING_CASE(port->base.port);
Jani Nikula9642c812015-08-20 10:47:41 +03004593 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004594 }
4595
Jani Nikula1d245982015-08-20 10:47:37 +03004596 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004597}
4598
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004599static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4600 struct intel_digital_port *port)
4601{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004602 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004603 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4604 else
4605 return ibx_digital_port_connected(dev_priv, port);
4606}
4607
4608static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4609 struct intel_digital_port *port)
4610{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004611 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004612 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4613 else
4614 return cpt_digital_port_connected(dev_priv, port);
4615}
4616
4617static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4618 struct intel_digital_port *port)
4619{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004620 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004621 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4622 else
4623 return cpt_digital_port_connected(dev_priv, port);
4624}
4625
4626static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4627 struct intel_digital_port *port)
4628{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004629 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004630 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4631 else
4632 return cpt_digital_port_connected(dev_priv, port);
4633}
4634
Jani Nikulae464bfd2015-08-20 10:47:42 +03004635static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304636 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004637{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304638 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4639 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004640 u32 bit;
4641
Rodrigo Vivi256cfdde2017-08-11 11:26:49 -07004642 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304643 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004644 case PORT_A:
4645 bit = BXT_DE_PORT_HP_DDIA;
4646 break;
4647 case PORT_B:
4648 bit = BXT_DE_PORT_HP_DDIB;
4649 break;
4650 case PORT_C:
4651 bit = BXT_DE_PORT_HP_DDIC;
4652 break;
4653 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304654 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004655 return false;
4656 }
4657
4658 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4659}
4660
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004661/*
4662 * intel_digital_port_connected - is the specified port connected?
4663 * @dev_priv: i915 private structure
4664 * @port: the port to test
4665 *
4666 * Return %true if @port is connected, %false otherwise.
4667 */
Imre Deak390b4e02017-01-27 11:39:19 +02004668bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4669 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004670{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004671 if (HAS_GMCH_DISPLAY(dev_priv)) {
4672 if (IS_GM45(dev_priv))
4673 return gm45_digital_port_connected(dev_priv, port);
4674 else
4675 return g4x_digital_port_connected(dev_priv, port);
4676 }
4677
4678 if (IS_GEN5(dev_priv))
4679 return ilk_digital_port_connected(dev_priv, port);
4680 else if (IS_GEN6(dev_priv))
4681 return snb_digital_port_connected(dev_priv, port);
4682 else if (IS_GEN7(dev_priv))
4683 return ivb_digital_port_connected(dev_priv, port);
4684 else if (IS_GEN8(dev_priv))
4685 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004686 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004687 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004688 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004689 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004690}
4691
Keith Packard8c241fe2011-09-28 16:38:44 -07004692static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004693intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004694{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004695 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004696
Jani Nikula9cd300e2012-10-19 14:51:52 +03004697 /* use cached edid if we have one */
4698 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004699 /* invalid edid */
4700 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004701 return NULL;
4702
Jani Nikula55e9ede2013-10-01 10:38:54 +03004703 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004704 } else
4705 return drm_get_edid(&intel_connector->base,
4706 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004707}
4708
Chris Wilsonbeb60602014-09-02 20:04:00 +01004709static void
4710intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004711{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004712 struct intel_connector *intel_connector = intel_dp->attached_connector;
4713 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004714
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304715 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004716 edid = intel_dp_get_edid(intel_dp);
4717 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004718
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004719 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004720}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004721
Chris Wilsonbeb60602014-09-02 20:04:00 +01004722static void
4723intel_dp_unset_edid(struct intel_dp *intel_dp)
4724{
4725 struct intel_connector *intel_connector = intel_dp->attached_connector;
4726
4727 kfree(intel_connector->detect_edid);
4728 intel_connector->detect_edid = NULL;
4729
4730 intel_dp->has_audio = false;
4731}
4732
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004733static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304734intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004735{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304736 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004737 struct intel_dp *intel_dp = intel_attached_dp(connector);
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
Manasi Navared7e8ef02017-02-07 16:54:11 -08004770 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004771 /* Initial max link lane count */
4772 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004773
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004774 /* Initial max link rate */
4775 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004776
4777 intel_dp->reset_link_params = false;
4778 }
Manasi Navaref4829842016-12-05 16:27:36 -08004779
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004780 intel_dp_print_rates(intel_dp);
4781
Jani Nikula84c36752017-05-18 14:10:23 +03004782 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4783 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004784
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004785 intel_dp_configure_mst(intel_dp);
4786
4787 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304788 /*
4789 * If we are in MST mode then this connector
4790 * won't appear connected or have anything
4791 * with EDID on it
4792 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004793 status = connector_status_disconnected;
4794 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004795 } else {
4796 /*
4797 * If display is now connected check links status,
4798 * there has been known issues of link loss triggerring
4799 * long pulse.
4800 *
4801 * Some sinks (eg. ASUS PB287Q) seem to perform some
4802 * weird HPD ping pong during modesets. So we can apparently
4803 * end up with HPD going low during a modeset, and then
4804 * going back up soon after. And once that happens we must
4805 * retrain the link to get a picture. That's in case no
4806 * userspace component reacted to intermittent HPD dip.
4807 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304808 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004809 }
4810
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304811 /*
4812 * Clearing NACK and defer counts to get their exact values
4813 * while reading EDID which are required by Compliance tests
4814 * 4.2.2.4 and 4.2.2.5
4815 */
4816 intel_dp->aux.i2c_nack_count = 0;
4817 intel_dp->aux.i2c_defer_count = 0;
4818
Chris Wilsonbeb60602014-09-02 20:04:00 +01004819 intel_dp_set_edid(intel_dp);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004820 if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004821 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304822 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004823
Todd Previte09b1eb12015-04-20 15:27:34 -07004824 /* Try to read the source of the interrupt */
4825 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004826 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4827 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004828 /* Clear interrupt source */
4829 drm_dp_dpcd_writeb(&intel_dp->aux,
4830 DP_DEVICE_SERVICE_IRQ_VECTOR,
4831 sink_irq_vector);
4832
4833 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4834 intel_dp_handle_test_request(intel_dp);
4835 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4836 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4837 }
4838
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004839out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004840 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304841 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304842
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004843 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004844 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304845}
4846
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004847static int
4848intel_dp_detect(struct drm_connector *connector,
4849 struct drm_modeset_acquire_ctx *ctx,
4850 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304851{
4852 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004853 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304854
4855 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4856 connector->base.id, connector->name);
4857
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304858 /* If full detect is not performed yet, do a full detect */
4859 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004860 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304861
4862 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304863
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004864 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004865}
4866
Chris Wilsonbeb60602014-09-02 20:04:00 +01004867static void
4868intel_dp_force(struct drm_connector *connector)
4869{
4870 struct intel_dp *intel_dp = intel_attached_dp(connector);
4871 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004872 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004873
4874 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4875 connector->base.id, connector->name);
4876 intel_dp_unset_edid(intel_dp);
4877
4878 if (connector->status != connector_status_connected)
4879 return;
4880
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004881 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004882
4883 intel_dp_set_edid(intel_dp);
4884
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004885 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004886}
4887
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004888static int intel_dp_get_modes(struct drm_connector *connector)
4889{
Jani Nikuladd06f902012-10-19 14:51:50 +03004890 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004891 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004892
Chris Wilsonbeb60602014-09-02 20:04:00 +01004893 edid = intel_connector->detect_edid;
4894 if (edid) {
4895 int ret = intel_connector_update_modes(connector, edid);
4896 if (ret)
4897 return ret;
4898 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004899
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004900 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004901 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004902 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004903 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004904
4905 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004906 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004907 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004908 drm_mode_probed_add(connector, mode);
4909 return 1;
4910 }
4911 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004912
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004913 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004914}
4915
Chris Wilsonf6849602010-09-19 09:29:33 +01004916static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004917intel_dp_connector_register(struct drm_connector *connector)
4918{
4919 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004920 int ret;
4921
4922 ret = intel_connector_register(connector);
4923 if (ret)
4924 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004925
4926 i915_debugfs_connector_add(connector);
4927
4928 DRM_DEBUG_KMS("registering %s bus for %s\n",
4929 intel_dp->aux.name, connector->kdev->kobj.name);
4930
4931 intel_dp->aux.dev = connector->kdev;
4932 return drm_dp_aux_register(&intel_dp->aux);
4933}
4934
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004935static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004936intel_dp_connector_unregister(struct drm_connector *connector)
4937{
4938 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4939 intel_connector_unregister(connector);
4940}
4941
4942static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004943intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004944{
Jani Nikula1d508702012-10-19 14:51:49 +03004945 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004946
Chris Wilson10e972d2014-09-04 21:43:45 +01004947 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004948
Jani Nikula9cd300e2012-10-19 14:51:52 +03004949 if (!IS_ERR_OR_NULL(intel_connector->edid))
4950 kfree(intel_connector->edid);
4951
Jani Nikula1853a9d2017-08-18 12:30:20 +03004952 /*
4953 * Can't call intel_dp_is_edp() since the encoder may have been
4954 * destroyed already.
4955 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004956 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004957 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004958
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004959 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004960 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004961}
4962
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004963void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004964{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004965 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4966 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004967
Dave Airlie0e32b392014-05-02 14:02:48 +10004968 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004969 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004970 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004971 /*
4972 * vdd might still be enabled do to the delayed vdd off.
4973 * Make sure vdd is actually turned off here.
4974 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004975 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004976 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004977 pps_unlock(intel_dp);
4978
Clint Taylor01527b32014-07-07 13:01:46 -07004979 if (intel_dp->edp_notifier.notifier_call) {
4980 unregister_reboot_notifier(&intel_dp->edp_notifier);
4981 intel_dp->edp_notifier.notifier_call = NULL;
4982 }
Keith Packardbd943152011-09-18 23:09:52 -07004983 }
Chris Wilson99681882016-06-20 09:29:17 +01004984
4985 intel_dp_aux_fini(intel_dp);
4986
Imre Deakc8bd0e42014-12-12 17:57:38 +02004987 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004988 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004989}
4990
Imre Deakbf93ba62016-04-18 10:04:21 +03004991void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004992{
4993 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4994
Jani Nikula1853a9d2017-08-18 12:30:20 +03004995 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03004996 return;
4997
Ville Syrjälä951468f2014-09-04 14:55:31 +03004998 /*
4999 * vdd might still be enabled do to the delayed vdd off.
5000 * Make sure vdd is actually turned off here.
5001 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02005002 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005003 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03005004 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005005 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03005006}
5007
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005008static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
5009{
5010 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5011 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005012 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005013
5014 lockdep_assert_held(&dev_priv->pps_mutex);
5015
5016 if (!edp_have_panel_vdd(intel_dp))
5017 return;
5018
5019 /*
5020 * The VDD bit needs a power domain reference, so if the bit is
5021 * already enabled when we boot or resume, grab this reference and
5022 * schedule a vdd off, so we don't hold on to the reference
5023 * indefinitely.
5024 */
5025 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005026 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005027
5028 edp_panel_vdd_schedule_off(intel_dp);
5029}
5030
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005031static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5032{
5033 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5034
5035 if ((intel_dp->DP & DP_PORT_EN) == 0)
5036 return INVALID_PIPE;
5037
5038 if (IS_CHERRYVIEW(dev_priv))
5039 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5040 else
5041 return PORT_TO_PIPE(intel_dp->DP);
5042}
5043
Imre Deakbf93ba62016-04-18 10:04:21 +03005044void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005045{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005046 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005047 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5048 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005049
5050 if (!HAS_DDI(dev_priv))
5051 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005052
Imre Deakdd75f6d2016-11-21 21:15:05 +02005053 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305054 lspcon_resume(lspcon);
5055
Manasi Navared7e8ef02017-02-07 16:54:11 -08005056 intel_dp->reset_link_params = true;
5057
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005058 pps_lock(intel_dp);
5059
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005060 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5061 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5062
Jani Nikula1853a9d2017-08-18 12:30:20 +03005063 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005064 /* Reinit the power sequencer, in case BIOS did something with it. */
5065 intel_dp_pps_init(encoder->dev, intel_dp);
5066 intel_edp_panel_vdd_sanitize(intel_dp);
5067 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005068
5069 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005070}
5071
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005072static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005073 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005074 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005075 .atomic_get_property = intel_digital_connector_atomic_get_property,
5076 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005077 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005078 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005079 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005080 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005081 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005082};
5083
5084static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005085 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005086 .get_modes = intel_dp_get_modes,
5087 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005088 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005089};
5090
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005091static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005092 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005093 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005094};
5095
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005096enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005097intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5098{
5099 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005100 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005101 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005102 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005103
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005104 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5105 /*
5106 * vdd off can generate a long pulse on eDP which
5107 * would require vdd on to handle it, and thus we
5108 * would end up in an endless cycle of
5109 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5110 */
5111 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005112 port_name(intel_dig_port->base.port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005113 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005114 }
5115
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005116 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005117 port_name(intel_dig_port->base.port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005118 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005119
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005120 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005121 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005122 intel_dp->detect_done = false;
5123 return IRQ_NONE;
5124 }
5125
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005126 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005127
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005128 if (intel_dp->is_mst) {
5129 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5130 /*
5131 * If we were in MST mode, and device is not
5132 * there, get out of MST mode
5133 */
5134 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5135 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5136 intel_dp->is_mst = false;
5137 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5138 intel_dp->is_mst);
5139 intel_dp->detect_done = false;
5140 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005141 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005142 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005143
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005144 if (!intel_dp->is_mst) {
5145 if (!intel_dp_short_pulse(intel_dp)) {
5146 intel_dp->detect_done = false;
5147 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305148 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005149 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005150
5151 ret = IRQ_HANDLED;
5152
Imre Deak1c767b32014-08-18 14:42:42 +03005153put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005154 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005155
5156 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005157}
5158
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005159/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005160bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005161{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005162 /*
5163 * eDP not supported on g4x. so bail out early just
5164 * for a bit extra safety in case the VBT is bonkers.
5165 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005166 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005167 return false;
5168
Imre Deaka98d9c12016-12-21 12:17:24 +02005169 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005170 return true;
5171
Jani Nikula951d9ef2016-03-16 12:43:31 +02005172 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005173}
5174
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005175static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005176intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5177{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005178 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5179
Chris Wilson3f43c482011-05-12 22:17:24 +01005180 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005181 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005182
Jani Nikula1853a9d2017-08-18 12:30:20 +03005183 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005184 u32 allowed_scalers;
5185
5186 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5187 if (!HAS_GMCH_DISPLAY(dev_priv))
5188 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5189
5190 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5191
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005192 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005193
Yuly Novikov53b41832012-10-26 12:04:00 +03005194 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005195}
5196
Imre Deakdada1a92014-01-29 13:25:41 +02005197static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5198{
Abhay Kumard28d4732016-01-22 17:39:04 -08005199 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005200 intel_dp->last_power_on = jiffies;
5201 intel_dp->last_backlight_off = jiffies;
5202}
5203
Daniel Vetter67a54562012-10-20 20:57:45 +02005204static void
Imre Deak54648612016-06-16 16:37:22 +03005205intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5206 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005207{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305208 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005209 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005210
Imre Deak8e8232d2016-06-16 16:37:21 +03005211 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005212
5213 /* Workaround: Need to write PP_CONTROL with the unlock key as
5214 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305215 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005216
Imre Deak8e8232d2016-06-16 16:37:21 +03005217 pp_on = I915_READ(regs.pp_on);
5218 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005219 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005220 I915_WRITE(regs.pp_ctrl, pp_ctl);
5221 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305222 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005223
5224 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005225 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5226 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005227
Imre Deak54648612016-06-16 16:37:22 +03005228 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5229 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005230
Imre Deak54648612016-06-16 16:37:22 +03005231 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5232 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005233
Imre Deak54648612016-06-16 16:37:22 +03005234 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5235 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005236
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005237 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005238 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5239 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305240 } else {
Imre Deak54648612016-06-16 16:37:22 +03005241 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005242 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305243 }
Imre Deak54648612016-06-16 16:37:22 +03005244}
5245
5246static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005247intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5248{
5249 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5250 state_name,
5251 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5252}
5253
5254static void
5255intel_pps_verify_state(struct drm_i915_private *dev_priv,
5256 struct intel_dp *intel_dp)
5257{
5258 struct edp_power_seq hw;
5259 struct edp_power_seq *sw = &intel_dp->pps_delays;
5260
5261 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5262
5263 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5264 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5265 DRM_ERROR("PPS state mismatch\n");
5266 intel_pps_dump_state("sw", sw);
5267 intel_pps_dump_state("hw", &hw);
5268 }
5269}
5270
5271static void
Imre Deak54648612016-06-16 16:37:22 +03005272intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5273 struct intel_dp *intel_dp)
5274{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005275 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005276 struct edp_power_seq cur, vbt, spec,
5277 *final = &intel_dp->pps_delays;
5278
5279 lockdep_assert_held(&dev_priv->pps_mutex);
5280
5281 /* already initialized? */
5282 if (final->t11_t12 != 0)
5283 return;
5284
5285 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005286
Imre Deakde9c1b62016-06-16 20:01:46 +03005287 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005288
Jani Nikula6aa23e62016-03-24 17:50:20 +02005289 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005290 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5291 * of 500ms appears to be too short. Ocassionally the panel
5292 * just fails to power back on. Increasing the delay to 800ms
5293 * seems sufficient to avoid this problem.
5294 */
5295 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
Manasi Navarec02b8fb2017-10-03 16:37:25 -07005296 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
Manasi Navarec99a2592017-06-30 09:33:48 -07005297 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5298 vbt.t11_t12);
5299 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005300 /* T11_T12 delay is special and actually in units of 100ms, but zero
5301 * based in the hw (so we need to add 100 ms). But the sw vbt
5302 * table multiplies it with 1000 to make it in units of 100usec,
5303 * too. */
5304 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005305
5306 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5307 * our hw here, which are all in 100usec. */
5308 spec.t1_t3 = 210 * 10;
5309 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5310 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5311 spec.t10 = 500 * 10;
5312 /* This one is special and actually in units of 100ms, but zero
5313 * based in the hw (so we need to add 100 ms). But the sw vbt
5314 * table multiplies it with 1000 to make it in units of 100usec,
5315 * too. */
5316 spec.t11_t12 = (510 + 100) * 10;
5317
Imre Deakde9c1b62016-06-16 20:01:46 +03005318 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005319
5320 /* Use the max of the register settings and vbt. If both are
5321 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005322#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005323 spec.field : \
5324 max(cur.field, vbt.field))
5325 assign_final(t1_t3);
5326 assign_final(t8);
5327 assign_final(t9);
5328 assign_final(t10);
5329 assign_final(t11_t12);
5330#undef assign_final
5331
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005332#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005333 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5334 intel_dp->backlight_on_delay = get_delay(t8);
5335 intel_dp->backlight_off_delay = get_delay(t9);
5336 intel_dp->panel_power_down_delay = get_delay(t10);
5337 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5338#undef get_delay
5339
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005340 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5341 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5342 intel_dp->panel_power_cycle_delay);
5343
5344 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5345 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005346
5347 /*
5348 * We override the HW backlight delays to 1 because we do manual waits
5349 * on them. For T8, even BSpec recommends doing it. For T9, if we
5350 * don't do this, we'll end up waiting for the backlight off delay
5351 * twice: once when we do the manual sleep, and once when we disable
5352 * the panel and wait for the PP_STATUS bit to become zero.
5353 */
5354 final->t8 = 1;
5355 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005356}
5357
5358static void
5359intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005360 struct intel_dp *intel_dp,
5361 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005362{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005363 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005364 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005365 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005366 struct pps_registers regs;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005367 enum port port = dp_to_dig_port(intel_dp)->base.port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005368 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005369
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005370 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005371
Imre Deak8e8232d2016-06-16 16:37:21 +03005372 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005373
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005374 /*
5375 * On some VLV machines the BIOS can leave the VDD
5376 * enabled even on power seqeuencers which aren't
5377 * hooked up to any port. This would mess up the
5378 * power domain tracking the first time we pick
5379 * one of these power sequencers for use since
5380 * edp_panel_vdd_on() would notice that the VDD was
5381 * already on and therefore wouldn't grab the power
5382 * domain reference. Disable VDD first to avoid this.
5383 * This also avoids spuriously turning the VDD on as
5384 * soon as the new power seqeuencer gets initialized.
5385 */
5386 if (force_disable_vdd) {
5387 u32 pp = ironlake_get_pp_control(intel_dp);
5388
5389 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5390
5391 if (pp & EDP_FORCE_VDD)
5392 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5393
5394 pp &= ~EDP_FORCE_VDD;
5395
5396 I915_WRITE(regs.pp_ctrl, pp);
5397 }
5398
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005399 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005400 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5401 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005402 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005403 /* Compute the divisor for the pp clock, simply match the Bspec
5404 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005405 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005406 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305407 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005408 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305409 << BXT_POWER_CYCLE_DELAY_SHIFT);
5410 } else {
5411 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5412 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5413 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5414 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005415
5416 /* Haswell doesn't have any port selection bits for the panel
5417 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005418 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005419 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005420 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005421 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005422 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005423 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005424 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005425 }
5426
Jesse Barnes453c5422013-03-28 09:55:41 -07005427 pp_on |= port_sel;
5428
Imre Deak8e8232d2016-06-16 16:37:21 +03005429 I915_WRITE(regs.pp_on, pp_on);
5430 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005431 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005432 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305433 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005434 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005435
Daniel Vetter67a54562012-10-20 20:57:45 +02005436 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 +03005437 I915_READ(regs.pp_on),
5438 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005439 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005440 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5441 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005442}
5443
Imre Deak335f7522016-08-10 14:07:32 +03005444static void intel_dp_pps_init(struct drm_device *dev,
5445 struct intel_dp *intel_dp)
5446{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005447 struct drm_i915_private *dev_priv = to_i915(dev);
5448
5449 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005450 vlv_initial_power_sequencer_setup(intel_dp);
5451 } else {
5452 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005453 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005454 }
5455}
5456
Vandana Kannanb33a2812015-02-13 15:33:03 +05305457/**
5458 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005459 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005460 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305461 * @refresh_rate: RR to be programmed
5462 *
5463 * This function gets called when refresh rate (RR) has to be changed from
5464 * one frequency to another. Switches can be between high and low RR
5465 * supported by the panel or to any other RR based on media playback (in
5466 * this case, RR value needs to be passed from user space).
5467 *
5468 * The caller of this function needs to take a lock on dev_priv->drrs.
5469 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005470static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005471 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005472 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305474 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305475 struct intel_digital_port *dig_port = NULL;
5476 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005477 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305478 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305479
5480 if (refresh_rate <= 0) {
5481 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5482 return;
5483 }
5484
Vandana Kannan96178ee2015-01-10 02:25:56 +05305485 if (intel_dp == NULL) {
5486 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305487 return;
5488 }
5489
Vandana Kannan96178ee2015-01-10 02:25:56 +05305490 dig_port = dp_to_dig_port(intel_dp);
5491 encoder = &dig_port->base;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305492
5493 if (!intel_crtc) {
5494 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5495 return;
5496 }
5497
Vandana Kannan96178ee2015-01-10 02:25:56 +05305498 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305499 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5500 return;
5501 }
5502
Vandana Kannan96178ee2015-01-10 02:25:56 +05305503 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5504 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305505 index = DRRS_LOW_RR;
5506
Vandana Kannan96178ee2015-01-10 02:25:56 +05305507 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305508 DRM_DEBUG_KMS(
5509 "DRRS requested for previously set RR...ignoring\n");
5510 return;
5511 }
5512
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005513 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305514 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5515 return;
5516 }
5517
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005518 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305519 switch (index) {
5520 case DRRS_HIGH_RR:
5521 intel_dp_set_m_n(intel_crtc, M1_N1);
5522 break;
5523 case DRRS_LOW_RR:
5524 intel_dp_set_m_n(intel_crtc, M2_N2);
5525 break;
5526 case DRRS_MAX_RR:
5527 default:
5528 DRM_ERROR("Unsupported refreshrate type\n");
5529 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005530 } else if (INTEL_GEN(dev_priv) > 6) {
5531 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005532 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305533
Ville Syrjälä649636e2015-09-22 19:50:01 +03005534 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305535 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005536 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305537 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5538 else
5539 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305540 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005541 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305542 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5543 else
5544 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305545 }
5546 I915_WRITE(reg, val);
5547 }
5548
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305549 dev_priv->drrs.refresh_rate_type = index;
5550
5551 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5552}
5553
Vandana Kannanb33a2812015-02-13 15:33:03 +05305554/**
5555 * intel_edp_drrs_enable - init drrs struct if supported
5556 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005557 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305558 *
5559 * Initializes frontbuffer_bits and drrs.dp
5560 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005561void intel_edp_drrs_enable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005562 const struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305563{
5564 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005565 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305566
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005567 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305568 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5569 return;
5570 }
5571
Radhakrishna Sripadada83ef82017-09-14 11:16:41 -07005572 if (dev_priv->psr.enabled) {
5573 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5574 return;
5575 }
5576
Vandana Kannanc3955782015-01-22 15:17:40 +05305577 mutex_lock(&dev_priv->drrs.mutex);
5578 if (WARN_ON(dev_priv->drrs.dp)) {
5579 DRM_ERROR("DRRS already enabled\n");
5580 goto unlock;
5581 }
5582
5583 dev_priv->drrs.busy_frontbuffer_bits = 0;
5584
5585 dev_priv->drrs.dp = intel_dp;
5586
5587unlock:
5588 mutex_unlock(&dev_priv->drrs.mutex);
5589}
5590
Vandana Kannanb33a2812015-02-13 15:33:03 +05305591/**
5592 * intel_edp_drrs_disable - Disable DRRS
5593 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005594 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305595 *
5596 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005597void intel_edp_drrs_disable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005598 const struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305599{
5600 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005601 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305602
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005603 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305604 return;
5605
5606 mutex_lock(&dev_priv->drrs.mutex);
5607 if (!dev_priv->drrs.dp) {
5608 mutex_unlock(&dev_priv->drrs.mutex);
5609 return;
5610 }
5611
5612 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005613 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5614 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305615
5616 dev_priv->drrs.dp = NULL;
5617 mutex_unlock(&dev_priv->drrs.mutex);
5618
5619 cancel_delayed_work_sync(&dev_priv->drrs.work);
5620}
5621
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305622static void intel_edp_drrs_downclock_work(struct work_struct *work)
5623{
5624 struct drm_i915_private *dev_priv =
5625 container_of(work, typeof(*dev_priv), drrs.work.work);
5626 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305627
Vandana Kannan96178ee2015-01-10 02:25:56 +05305628 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305629
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305630 intel_dp = dev_priv->drrs.dp;
5631
5632 if (!intel_dp)
5633 goto unlock;
5634
5635 /*
5636 * The delayed work can race with an invalidate hence we need to
5637 * recheck.
5638 */
5639
5640 if (dev_priv->drrs.busy_frontbuffer_bits)
5641 goto unlock;
5642
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005643 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5644 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5645
5646 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5647 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5648 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305649
5650unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305651 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305652}
5653
Vandana Kannanb33a2812015-02-13 15:33:03 +05305654/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305655 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005656 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305657 * @frontbuffer_bits: frontbuffer plane tracking bits
5658 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305659 * This function gets called everytime rendering on the given planes start.
5660 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305661 *
5662 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5663 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005664void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5665 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305666{
Vandana Kannana93fad02015-01-10 02:25:59 +05305667 struct drm_crtc *crtc;
5668 enum pipe pipe;
5669
Daniel Vetter9da7d692015-04-09 16:44:15 +02005670 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305671 return;
5672
Daniel Vetter88f933a2015-04-09 16:44:16 +02005673 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305674
Vandana Kannana93fad02015-01-10 02:25:59 +05305675 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005676 if (!dev_priv->drrs.dp) {
5677 mutex_unlock(&dev_priv->drrs.mutex);
5678 return;
5679 }
5680
Vandana Kannana93fad02015-01-10 02:25:59 +05305681 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5682 pipe = to_intel_crtc(crtc)->pipe;
5683
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005684 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5685 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5686
Ramalingam C0ddfd202015-06-15 20:50:05 +05305687 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005688 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005689 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5690 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305691
Vandana Kannana93fad02015-01-10 02:25:59 +05305692 mutex_unlock(&dev_priv->drrs.mutex);
5693}
5694
Vandana Kannanb33a2812015-02-13 15:33:03 +05305695/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305696 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005697 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305698 * @frontbuffer_bits: frontbuffer plane tracking bits
5699 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305700 * This function gets called every time rendering on the given planes has
5701 * completed or flip on a crtc is completed. So DRRS should be upclocked
5702 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5703 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305704 *
5705 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5706 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005707void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5708 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305709{
Vandana Kannana93fad02015-01-10 02:25:59 +05305710 struct drm_crtc *crtc;
5711 enum pipe pipe;
5712
Daniel Vetter9da7d692015-04-09 16:44:15 +02005713 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305714 return;
5715
Daniel Vetter88f933a2015-04-09 16:44:16 +02005716 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305717
Vandana Kannana93fad02015-01-10 02:25:59 +05305718 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005719 if (!dev_priv->drrs.dp) {
5720 mutex_unlock(&dev_priv->drrs.mutex);
5721 return;
5722 }
5723
Vandana Kannana93fad02015-01-10 02:25:59 +05305724 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5725 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005726
5727 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305728 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5729
Ramalingam C0ddfd202015-06-15 20:50:05 +05305730 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005731 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005732 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5733 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305734
5735 /*
5736 * flush also means no more activity hence schedule downclock, if all
5737 * other fbs are quiescent too
5738 */
5739 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305740 schedule_delayed_work(&dev_priv->drrs.work,
5741 msecs_to_jiffies(1000));
5742 mutex_unlock(&dev_priv->drrs.mutex);
5743}
5744
Vandana Kannanb33a2812015-02-13 15:33:03 +05305745/**
5746 * DOC: Display Refresh Rate Switching (DRRS)
5747 *
5748 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5749 * which enables swtching between low and high refresh rates,
5750 * dynamically, based on the usage scenario. This feature is applicable
5751 * for internal panels.
5752 *
5753 * Indication that the panel supports DRRS is given by the panel EDID, which
5754 * would list multiple refresh rates for one resolution.
5755 *
5756 * DRRS is of 2 types - static and seamless.
5757 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5758 * (may appear as a blink on screen) and is used in dock-undock scenario.
5759 * Seamless DRRS involves changing RR without any visual effect to the user
5760 * and can be used during normal system usage. This is done by programming
5761 * certain registers.
5762 *
5763 * Support for static/seamless DRRS may be indicated in the VBT based on
5764 * inputs from the panel spec.
5765 *
5766 * DRRS saves power by switching to low RR based on usage scenarios.
5767 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005768 * The implementation is based on frontbuffer tracking implementation. When
5769 * there is a disturbance on the screen triggered by user activity or a periodic
5770 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5771 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5772 * made.
5773 *
5774 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5775 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305776 *
5777 * DRRS can be further extended to support other internal panels and also
5778 * the scenario of video playback wherein RR is set based on the rate
5779 * requested by userspace.
5780 */
5781
5782/**
5783 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5784 * @intel_connector: eDP connector
5785 * @fixed_mode: preferred mode of panel
5786 *
5787 * This function is called only once at driver load to initialize basic
5788 * DRRS stuff.
5789 *
5790 * Returns:
5791 * Downclock mode if panel supports it, else return NULL.
5792 * DRRS support is determined by the presence of downclock mode (apart
5793 * from VBT setting).
5794 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305795static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305796intel_dp_drrs_init(struct intel_connector *intel_connector,
5797 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305798{
5799 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305800 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005801 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305802 struct drm_display_mode *downclock_mode = NULL;
5803
Daniel Vetter9da7d692015-04-09 16:44:15 +02005804 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5805 mutex_init(&dev_priv->drrs.mutex);
5806
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005807 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305808 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5809 return NULL;
5810 }
5811
5812 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005813 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305814 return NULL;
5815 }
5816
5817 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005818 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305819
5820 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305821 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305822 return NULL;
5823 }
5824
Vandana Kannan96178ee2015-01-10 02:25:56 +05305825 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305826
Vandana Kannan96178ee2015-01-10 02:25:56 +05305827 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005828 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305829 return downclock_mode;
5830}
5831
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005832static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005833 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005834{
5835 struct drm_connector *connector = &intel_connector->base;
5836 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005837 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5838 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005839 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005840 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07005841 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305842 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005843 bool has_dpcd;
5844 struct drm_display_mode *scan;
5845 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005846 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005847
Jani Nikula1853a9d2017-08-18 12:30:20 +03005848 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005849 return true;
5850
Imre Deak97a824e12016-06-21 11:51:47 +03005851 /*
5852 * On IBX/CPT we may get here with LVDS already registered. Since the
5853 * driver uses the only internal power sequencer available for both
5854 * eDP and LVDS bail out early in this case to prevent interfering
5855 * with an already powered-on LVDS power sequencer.
5856 */
5857 if (intel_get_lvds_encoder(dev)) {
5858 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5859 DRM_INFO("LVDS was detected, not registering eDP\n");
5860
5861 return false;
5862 }
5863
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005864 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005865
5866 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005867 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005868 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005869
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005870 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005871
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005872 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005873 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005874
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005875 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005876 /* if this fails, presume the device is a ghost */
5877 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005878 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005879 }
5880
Daniel Vetter060c8772014-03-21 23:22:35 +01005881 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005882 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005883 if (edid) {
5884 if (drm_add_edid_modes(connector, edid)) {
5885 drm_mode_connector_update_edid_property(connector,
5886 edid);
5887 drm_edid_to_eld(connector, edid);
5888 } else {
5889 kfree(edid);
5890 edid = ERR_PTR(-EINVAL);
5891 }
5892 } else {
5893 edid = ERR_PTR(-ENOENT);
5894 }
5895 intel_connector->edid = edid;
5896
Jim Bridedc911f52017-08-09 12:48:53 -07005897 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005898 list_for_each_entry(scan, &connector->probed_modes, head) {
5899 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5900 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305901 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305902 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07005903 } else if (!alt_fixed_mode) {
5904 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005905 }
5906 }
5907
5908 /* fallback to VBT if available for eDP */
5909 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5910 fixed_mode = drm_mode_duplicate(dev,
5911 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005912 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005913 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005914 connector->display_info.width_mm = fixed_mode->width_mm;
5915 connector->display_info.height_mm = fixed_mode->height_mm;
5916 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005917 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005918 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005919
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005920 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005921 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5922 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005923
5924 /*
5925 * Figure out the current pipe for the initial backlight setup.
5926 * If the current pipe isn't valid, try the PPS pipe, and if that
5927 * fails just assume pipe A.
5928 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005929 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005930
5931 if (pipe != PIPE_A && pipe != PIPE_B)
5932 pipe = intel_dp->pps_pipe;
5933
5934 if (pipe != PIPE_A && pipe != PIPE_B)
5935 pipe = PIPE_A;
5936
5937 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5938 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005939 }
5940
Jim Bridedc911f52017-08-09 12:48:53 -07005941 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5942 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005943 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005944 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005945
5946 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005947
5948out_vdd_off:
5949 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5950 /*
5951 * vdd might still be enabled do to the delayed vdd off.
5952 * Make sure vdd is actually turned off here.
5953 */
5954 pps_lock(intel_dp);
5955 edp_panel_vdd_off_sync(intel_dp);
5956 pps_unlock(intel_dp);
5957
5958 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005959}
5960
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005961/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005962static void
5963intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5964{
5965 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005966 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005967
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005968 encoder->hpd_pin = intel_hpd_pin(encoder->port);
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005969
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005970 switch (encoder->port) {
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005971 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005972 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005973 break;
5974 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005975 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005976 break;
5977 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005978 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005979 break;
5980 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005981 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005982 break;
5983 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005984 /* FIXME: Check VBT for actual wiring of PORT E */
5985 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005986 break;
5987 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005988 MISSING_CASE(encoder->port);
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005989 }
5990}
5991
Manasi Navare93013972017-04-06 16:44:19 +03005992static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5993{
5994 struct intel_connector *intel_connector;
5995 struct drm_connector *connector;
5996
5997 intel_connector = container_of(work, typeof(*intel_connector),
5998 modeset_retry_work);
5999 connector = &intel_connector->base;
6000 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
6001 connector->name);
6002
6003 /* Grab the locks before changing connector property*/
6004 mutex_lock(&connector->dev->mode_config.mutex);
6005 /* Set connector link status to BAD and send a Uevent to notify
6006 * userspace to do a modeset.
6007 */
6008 drm_mode_connector_set_link_status_property(connector,
6009 DRM_MODE_LINK_STATUS_BAD);
6010 mutex_unlock(&connector->dev->mode_config.mutex);
6011 /* Send Hotplug uevent so userspace can reprobe */
6012 drm_kms_helper_hotplug_event(connector->dev);
6013}
6014
Paulo Zanoni16c25532013-06-12 17:27:25 -03006015bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006016intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6017 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006018{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006019 struct drm_connector *connector = &intel_connector->base;
6020 struct intel_dp *intel_dp = &intel_dig_port->dp;
6021 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6022 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006023 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02006024 enum port port = intel_encoder->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006025 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006026
Manasi Navare93013972017-04-06 16:44:19 +03006027 /* Initialize the work for modeset in case of link train failure */
6028 INIT_WORK(&intel_connector->modeset_retry_work,
6029 intel_dp_modeset_retry_work_fn);
6030
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006031 if (WARN(intel_dig_port->max_lanes < 1,
6032 "Not enough lanes (%d) for DP on port %c\n",
6033 intel_dig_port->max_lanes, port_name(port)))
6034 return false;
6035
Jani Nikula55cfc582017-03-28 17:59:04 +03006036 intel_dp_set_source_rates(intel_dp);
6037
Manasi Navared7e8ef02017-02-07 16:54:11 -08006038 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006039 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006040 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006041
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006042 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006043 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006044 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006045 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006046 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006047 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006048 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6049 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006050 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006051
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006052 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006053 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6054 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006055 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006056
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006057 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006058 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6059
Daniel Vetter07679352012-09-06 22:15:42 +02006060 /* Preserve the current hw state. */
6061 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006062 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006063
Jani Nikula7b91bf72017-08-18 12:30:19 +03006064 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306065 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006066 else
6067 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006068
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006069 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6070 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6071
Imre Deakf7d24902013-05-08 13:14:05 +03006072 /*
6073 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6074 * for DP the encoder type can be set by the caller to
6075 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6076 */
6077 if (type == DRM_MODE_CONNECTOR_eDP)
6078 intel_encoder->type = INTEL_OUTPUT_EDP;
6079
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006080 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006081 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006082 intel_dp_is_edp(intel_dp) &&
6083 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006084 return false;
6085
Imre Deake7281ea2013-05-08 13:14:08 +03006086 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6087 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6088 port_name(port));
6089
Adam Jacksonb3295302010-07-16 14:46:28 -04006090 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006091 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6092
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006093 connector->interlace_allowed = true;
6094 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006095
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006096 intel_dp_init_connector_port_info(intel_dig_port);
6097
Mika Kaholab6339582016-09-09 14:10:52 +03006098 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006099
Daniel Vetter66a92782012-07-12 20:08:18 +02006100 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006101 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006102
Chris Wilsondf0e9242010-09-09 16:20:55 +01006103 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006104
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006105 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006106 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6107 else
6108 intel_connector->get_hw_state = intel_connector_get_hw_state;
6109
Dave Airlie0e32b392014-05-02 14:02:48 +10006110 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006111 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006112 (port == PORT_B || port == PORT_C || port == PORT_D))
6113 intel_dp_mst_encoder_init(intel_dig_port,
6114 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006115
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006116 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006117 intel_dp_aux_fini(intel_dp);
6118 intel_dp_mst_encoder_cleanup(intel_dig_port);
6119 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006120 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006121
Chris Wilsonf6849602010-09-19 09:29:33 +01006122 intel_dp_add_properties(intel_dp, connector);
6123
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006124 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6125 * 0xd. Failure to do so will result in spurious interrupts being
6126 * generated on the port when a cable is not attached.
6127 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006128 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006129 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6130 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6131 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006132
6133 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006134
6135fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006136 drm_connector_cleanup(connector);
6137
6138 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006139}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006140
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006141bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006142 i915_reg_t output_reg,
6143 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006144{
6145 struct intel_digital_port *intel_dig_port;
6146 struct intel_encoder *intel_encoder;
6147 struct drm_encoder *encoder;
6148 struct intel_connector *intel_connector;
6149
Daniel Vetterb14c5672013-09-19 12:18:32 +02006150 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006151 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006152 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006153
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006154 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306155 if (!intel_connector)
6156 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006157
6158 intel_encoder = &intel_dig_port->base;
6159 encoder = &intel_encoder->base;
6160
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006161 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6162 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6163 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306164 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006165
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006166 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006167 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006168 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006169 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006170 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006171 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006172 intel_encoder->pre_enable = chv_pre_enable_dp;
6173 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006174 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006175 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006176 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006177 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006178 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006179 intel_encoder->pre_enable = vlv_pre_enable_dp;
6180 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006181 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006182 intel_encoder->post_disable = vlv_post_disable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006183 } else if (INTEL_GEN(dev_priv) >= 5) {
6184 intel_encoder->pre_enable = g4x_pre_enable_dp;
6185 intel_encoder->enable = g4x_enable_dp;
6186 intel_encoder->disable = ilk_disable_dp;
6187 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006188 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006189 intel_encoder->pre_enable = g4x_pre_enable_dp;
6190 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006191 intel_encoder->disable = g4x_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006192 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006193
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006194 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006195 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006196
Ville Syrjäläcca05022016-06-22 21:57:06 +03006197 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006198 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006199 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006200 if (port == PORT_D)
6201 intel_encoder->crtc_mask = 1 << 2;
6202 else
6203 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6204 } else {
6205 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6206 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006207 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006208 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006209
Dave Airlie13cf5502014-06-18 11:29:35 +10006210 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006211 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006212
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006213 if (port != PORT_A)
6214 intel_infoframe_init(intel_dig_port);
6215
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306216 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6217 goto err_init_connector;
6218
Chris Wilson457c52d2016-06-01 08:27:50 +01006219 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306220
6221err_init_connector:
6222 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306223err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306224 kfree(intel_connector);
6225err_connector_alloc:
6226 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006227 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006228}
Dave Airlie0e32b392014-05-02 14:02:48 +10006229
6230void intel_dp_mst_suspend(struct drm_device *dev)
6231{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006232 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006233 int i;
6234
6235 /* disable MST */
6236 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006237 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006238
6239 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006240 continue;
6241
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006242 if (intel_dig_port->dp.is_mst)
6243 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006244 }
6245}
6246
6247void intel_dp_mst_resume(struct drm_device *dev)
6248{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006249 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006250 int i;
6251
6252 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006253 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006254 int ret;
6255
6256 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006257 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006258
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006259 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6260 if (ret)
6261 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006262 }
6263}