blob: 37bfe8b272218a7072c775586219c641e9c0e4eb [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ä46bd8382017-10-31 22:51:22 +0200138static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300139 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
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200432intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300433static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200434intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200435 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300436static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200437intel_dp_pps_init(struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300438
Ville Syrjälä773538e82014-09-04 14:54:56 +0300439static void pps_lock(struct intel_dp *intel_dp)
440{
441 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
442 struct intel_encoder *encoder = &intel_dig_port->base;
443 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100444 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300445
446 /*
447 * See vlv_power_sequencer_reset() why we need
448 * a power domain reference here.
449 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200450 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300451
452 mutex_lock(&dev_priv->pps_mutex);
453}
454
455static void pps_unlock(struct intel_dp *intel_dp)
456{
457 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
458 struct intel_encoder *encoder = &intel_dig_port->base;
459 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100460 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300461
462 mutex_unlock(&dev_priv->pps_mutex);
463
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200464 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300465}
466
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300467static void
468vlv_power_sequencer_kick(struct intel_dp *intel_dp)
469{
470 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200471 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300472 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300473 bool pll_enabled, release_cl_override = false;
474 enum dpio_phy phy = DPIO_PHY(pipe);
475 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300476 uint32_t DP;
477
478 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
479 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200480 pipe_name(pipe), port_name(intel_dig_port->base.port)))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300481 return;
482
483 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200484 pipe_name(pipe), port_name(intel_dig_port->base.port));
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300485
486 /* Preserve the BIOS-computed detected bit. This is
487 * supposed to be read-only.
488 */
489 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
490 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
491 DP |= DP_PORT_WIDTH(1);
492 DP |= DP_LINK_TRAIN_PAT_1;
493
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100494 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300495 DP |= DP_PIPE_SELECT_CHV(pipe);
496 else if (pipe == PIPE_B)
497 DP |= DP_PIPEB_SELECT;
498
Ville Syrjäläd288f652014-10-28 13:20:22 +0200499 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
500
501 /*
502 * The DPLL for the pipe must be enabled for this to work.
503 * So enable temporarily it if it's not already enabled.
504 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300505 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100506 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300507 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
508
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200509 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000510 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
511 DRM_ERROR("Failed to force on pll for pipe %c!\n",
512 pipe_name(pipe));
513 return;
514 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300515 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200516
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300517 /*
518 * Similar magic as in intel_dp_enable_port().
519 * We _must_ do this port enable + disable trick
520 * to make this power seqeuencer lock onto the port.
521 * Otherwise even VDD force bit won't work.
522 */
523 I915_WRITE(intel_dp->output_reg, DP);
524 POSTING_READ(intel_dp->output_reg);
525
526 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
527 POSTING_READ(intel_dp->output_reg);
528
529 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
530 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200531
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300532 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200533 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300534
535 if (release_cl_override)
536 chv_phy_powergate_ch(dev_priv, phy, ch, false);
537 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300538}
539
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200540static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
541{
542 struct intel_encoder *encoder;
543 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
544
545 /*
546 * We don't have power sequencer currently.
547 * Pick one that's not used by other ports.
548 */
549 for_each_intel_encoder(&dev_priv->drm, encoder) {
550 struct intel_dp *intel_dp;
551
552 if (encoder->type != INTEL_OUTPUT_DP &&
553 encoder->type != INTEL_OUTPUT_EDP)
554 continue;
555
556 intel_dp = enc_to_intel_dp(&encoder->base);
557
558 if (encoder->type == INTEL_OUTPUT_EDP) {
559 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
560 intel_dp->active_pipe != intel_dp->pps_pipe);
561
562 if (intel_dp->pps_pipe != INVALID_PIPE)
563 pipes &= ~(1 << intel_dp->pps_pipe);
564 } else {
565 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
566
567 if (intel_dp->active_pipe != INVALID_PIPE)
568 pipes &= ~(1 << intel_dp->active_pipe);
569 }
570 }
571
572 if (pipes == 0)
573 return INVALID_PIPE;
574
575 return ffs(pipes) - 1;
576}
577
Jani Nikulabf13e812013-09-06 07:40:05 +0300578static enum pipe
579vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
580{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200581 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Jani Nikulabf13e812013-09-06 07:40:05 +0300582 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300583 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300584
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300585 lockdep_assert_held(&dev_priv->pps_mutex);
586
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300587 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300588 WARN_ON(!intel_dp_is_edp(intel_dp));
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300589
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200590 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
591 intel_dp->active_pipe != intel_dp->pps_pipe);
592
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300593 if (intel_dp->pps_pipe != INVALID_PIPE)
594 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300595
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200596 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300597
598 /*
599 * Didn't find one. This should not happen since there
600 * are two power sequencers and up to two eDP ports.
601 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200602 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300603 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300604
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200605 vlv_steal_power_sequencer(dev_priv, pipe);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300606 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300607
608 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
609 pipe_name(intel_dp->pps_pipe),
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200610 port_name(intel_dig_port->base.port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300611
612 /* init power sequencer on this pipe and port */
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200613 intel_dp_init_panel_power_sequencer(intel_dp);
614 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300615
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300616 /*
617 * Even vdd force doesn't work until we've made
618 * the power sequencer lock in on the port.
619 */
620 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300621
622 return intel_dp->pps_pipe;
623}
624
Imre Deak78597992016-06-16 16:37:20 +0300625static int
626bxt_power_sequencer_idx(struct intel_dp *intel_dp)
627{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200628 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300629
630 lockdep_assert_held(&dev_priv->pps_mutex);
631
632 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300633 WARN_ON(!intel_dp_is_edp(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300634
635 /*
636 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
637 * mapping needs to be retrieved from VBT, for now just hard-code to
638 * use instance #0 always.
639 */
640 if (!intel_dp->pps_reset)
641 return 0;
642
643 intel_dp->pps_reset = false;
644
645 /*
646 * Only the HW needs to be reprogrammed, the SW state is fixed and
647 * has been setup during connector init.
648 */
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200649 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300650
651 return 0;
652}
653
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300654typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
655 enum pipe pipe);
656
657static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
658 enum pipe pipe)
659{
Imre Deak44cb7342016-08-10 14:07:29 +0300660 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300661}
662
663static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
664 enum pipe pipe)
665{
Imre Deak44cb7342016-08-10 14:07:29 +0300666 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300667}
668
669static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
670 enum pipe pipe)
671{
672 return true;
673}
674
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300675static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300676vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
677 enum port port,
678 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300679{
Jani Nikulabf13e812013-09-06 07:40:05 +0300680 enum pipe pipe;
681
Jani Nikulabf13e812013-09-06 07:40:05 +0300682 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300683 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300684 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300685
686 if (port_sel != PANEL_PORT_SELECT_VLV(port))
687 continue;
688
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300689 if (!pipe_check(dev_priv, pipe))
690 continue;
691
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300692 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300693 }
694
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300695 return INVALID_PIPE;
696}
697
698static void
699vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
700{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200701 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300702 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200703 enum port port = intel_dig_port->base.port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300704
705 lockdep_assert_held(&dev_priv->pps_mutex);
706
707 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300708 /* first pick one where the panel is on */
709 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
710 vlv_pipe_has_pp_on);
711 /* didn't find one? pick one where vdd is on */
712 if (intel_dp->pps_pipe == INVALID_PIPE)
713 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
714 vlv_pipe_has_vdd_on);
715 /* didn't find one? pick one with just the correct port */
716 if (intel_dp->pps_pipe == INVALID_PIPE)
717 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
718 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300719
720 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
721 if (intel_dp->pps_pipe == INVALID_PIPE) {
722 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
723 port_name(port));
724 return;
725 }
726
727 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
728 port_name(port), pipe_name(intel_dp->pps_pipe));
729
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200730 intel_dp_init_panel_power_sequencer(intel_dp);
731 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300732}
733
Imre Deak78597992016-06-16 16:37:20 +0300734void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300735{
Chris Wilson91c8a322016-07-05 10:40:23 +0100736 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300737 struct intel_encoder *encoder;
738
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100739 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200740 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300741 return;
742
743 /*
744 * We can't grab pps_mutex here due to deadlock with power_domain
745 * mutex when power_domain functions are called while holding pps_mutex.
746 * That also means that in order to use pps_pipe the code needs to
747 * hold both a power domain reference and pps_mutex, and the power domain
748 * reference get/put must be done while _not_ holding pps_mutex.
749 * pps_{lock,unlock}() do these steps in the correct order, so one
750 * should use them always.
751 */
752
Jani Nikula19c80542015-12-16 12:48:16 +0200753 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300754 struct intel_dp *intel_dp;
755
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200756 if (encoder->type != INTEL_OUTPUT_DP &&
Ville Syrjälä7e732ca2017-10-27 22:31:24 +0300757 encoder->type != INTEL_OUTPUT_EDP &&
758 encoder->type != INTEL_OUTPUT_DDI)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300759 continue;
760
761 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200762
Ville Syrjälä7e732ca2017-10-27 22:31:24 +0300763 /* Skip pure DVI/HDMI DDI encoders */
764 if (!i915_mmio_reg_valid(intel_dp->output_reg))
765 continue;
766
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200767 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
768
769 if (encoder->type != INTEL_OUTPUT_EDP)
770 continue;
771
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200772 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300773 intel_dp->pps_reset = true;
774 else
775 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300776 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300777}
778
Imre Deak8e8232d2016-06-16 16:37:21 +0300779struct pps_registers {
780 i915_reg_t pp_ctrl;
781 i915_reg_t pp_stat;
782 i915_reg_t pp_on;
783 i915_reg_t pp_off;
784 i915_reg_t pp_div;
785};
786
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200787static void intel_pps_get_registers(struct intel_dp *intel_dp,
Imre Deak8e8232d2016-06-16 16:37:21 +0300788 struct pps_registers *regs)
789{
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200790 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak44cb7342016-08-10 14:07:29 +0300791 int pps_idx = 0;
792
Imre Deak8e8232d2016-06-16 16:37:21 +0300793 memset(regs, 0, sizeof(*regs));
794
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200795 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300796 pps_idx = bxt_power_sequencer_idx(intel_dp);
797 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
798 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300799
Imre Deak44cb7342016-08-10 14:07:29 +0300800 regs->pp_ctrl = PP_CONTROL(pps_idx);
801 regs->pp_stat = PP_STATUS(pps_idx);
802 regs->pp_on = PP_ON_DELAYS(pps_idx);
803 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700804 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300805 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300806}
807
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200808static i915_reg_t
809_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300810{
Imre Deak8e8232d2016-06-16 16:37:21 +0300811 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300812
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200813 intel_pps_get_registers(intel_dp, &regs);
Imre Deak8e8232d2016-06-16 16:37:21 +0300814
815 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300816}
817
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200818static i915_reg_t
819_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300820{
Imre Deak8e8232d2016-06-16 16:37:21 +0300821 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300822
Ville Syrjälä46bd8382017-10-31 22:51:22 +0200823 intel_pps_get_registers(intel_dp, &regs);
Imre Deak8e8232d2016-06-16 16:37:21 +0300824
825 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300826}
827
Clint Taylor01527b32014-07-07 13:01:46 -0700828/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
829 This function only applicable when panel PM state is not to be tracked */
830static int edp_notify_handler(struct notifier_block *this, unsigned long code,
831 void *unused)
832{
833 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
834 edp_notifier);
835 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100836 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700837
Jani Nikula1853a9d2017-08-18 12:30:20 +0300838 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
Clint Taylor01527b32014-07-07 13:01:46 -0700839 return 0;
840
Ville Syrjälä773538e82014-09-04 14:54:56 +0300841 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300842
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100843 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300844 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200845 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300846 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300847
Imre Deak44cb7342016-08-10 14:07:29 +0300848 pp_ctrl_reg = PP_CONTROL(pipe);
849 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700850 pp_div = I915_READ(pp_div_reg);
851 pp_div &= PP_REFERENCE_DIVIDER_MASK;
852
853 /* 0x1F write to PP_DIV_REG sets max cycle delay */
854 I915_WRITE(pp_div_reg, pp_div | 0x1F);
855 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
856 msleep(intel_dp->panel_power_cycle_delay);
857 }
858
Ville Syrjälä773538e82014-09-04 14:54:56 +0300859 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300860
Clint Taylor01527b32014-07-07 13:01:46 -0700861 return 0;
862}
863
Daniel Vetter4be73782014-01-17 14:39:48 +0100864static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700865{
Paulo Zanoni30add222012-10-26 19:05:45 -0200866 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100867 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700868
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300869 lockdep_assert_held(&dev_priv->pps_mutex);
870
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100871 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300872 intel_dp->pps_pipe == INVALID_PIPE)
873 return false;
874
Jani Nikulabf13e812013-09-06 07:40:05 +0300875 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700876}
877
Daniel Vetter4be73782014-01-17 14:39:48 +0100878static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700879{
Paulo Zanoni30add222012-10-26 19:05:45 -0200880 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100881 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700882
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300883 lockdep_assert_held(&dev_priv->pps_mutex);
884
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100885 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300886 intel_dp->pps_pipe == INVALID_PIPE)
887 return false;
888
Ville Syrjälä773538e82014-09-04 14:54:56 +0300889 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700890}
891
Keith Packard9b984da2011-09-19 13:54:47 -0700892static void
893intel_dp_check_edp(struct intel_dp *intel_dp)
894{
Paulo Zanoni30add222012-10-26 19:05:45 -0200895 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100896 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700897
Jani Nikula1853a9d2017-08-18 12:30:20 +0300898 if (!intel_dp_is_edp(intel_dp))
Keith Packard9b984da2011-09-19 13:54:47 -0700899 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700900
Daniel Vetter4be73782014-01-17 14:39:48 +0100901 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700902 WARN(1, "eDP powered off while attempting aux channel communication.\n");
903 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300904 I915_READ(_pp_stat_reg(intel_dp)),
905 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700906 }
907}
908
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100909static uint32_t
910intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
911{
912 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
913 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100914 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200915 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100916 uint32_t status;
917 bool done;
918
Daniel Vetteref04f002012-12-01 21:03:59 +0100919#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100920 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300921 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300922 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100923 else
Imre Deak713a6b662016-06-28 13:37:33 +0300924 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100925 if (!done)
926 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
927 has_aux_irq);
928#undef C
929
930 return status;
931}
932
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200933static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000934{
935 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200936 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000937
Ville Syrjäläa457f542016-03-02 17:22:17 +0200938 if (index)
939 return 0;
940
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000941 /*
942 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200943 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000944 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200945 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000946}
947
948static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
949{
950 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200951 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000952
953 if (index)
954 return 0;
955
Ville Syrjäläa457f542016-03-02 17:22:17 +0200956 /*
957 * The clock divider is based off the cdclk or PCH rawclk, and would
958 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
959 * divide by 2000 and use that
960 */
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200961 if (intel_dig_port->base.port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200962 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200963 else
964 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000965}
966
967static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300968{
969 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200970 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300971
Ville Syrjälä8f4f2792017-11-09 17:24:34 +0200972 if (intel_dig_port->base.port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300973 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100974 switch (index) {
975 case 0: return 63;
976 case 1: return 72;
977 default: return 0;
978 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300979 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200980
981 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300982}
983
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000984static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
985{
986 /*
987 * SKL doesn't need us to program the AUX clock divider (Hardware will
988 * derive the clock from CDCLK automatically). We still implement the
989 * get_aux_clock_divider vfunc to plug-in into the existing code.
990 */
991 return index ? 0 : 1;
992}
993
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200994static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
995 bool has_aux_irq,
996 int send_bytes,
997 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000998{
999 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001000 struct drm_i915_private *dev_priv =
1001 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001002 uint32_t precharge, timeout;
1003
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001004 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001005 precharge = 3;
1006 else
1007 precharge = 5;
1008
James Ausmus8f5f63d2017-10-12 14:30:37 -07001009 if (IS_BROADWELL(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001010 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1011 else
1012 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1013
1014 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001015 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001016 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001017 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001018 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001019 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001020 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1021 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001022 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001023}
1024
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001025static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1026 bool has_aux_irq,
1027 int send_bytes,
1028 uint32_t unused)
1029{
1030 return DP_AUX_CH_CTL_SEND_BUSY |
1031 DP_AUX_CH_CTL_DONE |
1032 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1033 DP_AUX_CH_CTL_TIME_OUT_ERROR |
James Ausmus6fa228b2017-10-12 14:30:36 -07001034 DP_AUX_CH_CTL_TIME_OUT_MAX |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001035 DP_AUX_CH_CTL_RECEIVE_ERROR |
1036 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001037 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001038 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1039}
1040
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001041static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001042intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001043 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001044 uint8_t *recv, int recv_size)
1045{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001046 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001047 struct drm_i915_private *dev_priv =
1048 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001049 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001050 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001051 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001052 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001053 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001054 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001055 bool vdd;
1056
Ville Syrjälä773538e82014-09-04 14:54:56 +03001057 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001058
Ville Syrjälä72c35002014-08-18 22:16:00 +03001059 /*
1060 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1061 * In such cases we want to leave VDD enabled and it's up to upper layers
1062 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1063 * ourselves.
1064 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001065 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001066
1067 /* dp aux is extremely sensitive to irq latency, hence request the
1068 * lowest possible wakeup latency and so prevent the cpu from going into
1069 * deep sleep states.
1070 */
1071 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001072
Keith Packard9b984da2011-09-19 13:54:47 -07001073 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001074
Jesse Barnes11bee432011-08-01 15:02:20 -07001075 /* Try to wait for any previous AUX channel activity */
1076 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001077 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001078 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1079 break;
1080 msleep(1);
1081 }
1082
1083 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001084 static u32 last_status = -1;
1085 const u32 status = I915_READ(ch_ctl);
1086
1087 if (status != last_status) {
1088 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1089 status);
1090 last_status = status;
1091 }
1092
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001093 ret = -EBUSY;
1094 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001095 }
1096
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001097 /* Only 5 data registers! */
1098 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1099 ret = -E2BIG;
1100 goto out;
1101 }
1102
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001103 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001104 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1105 has_aux_irq,
1106 send_bytes,
1107 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001108
Chris Wilsonbc866252013-07-21 16:00:03 +01001109 /* Must try at least 3 times according to DP spec */
1110 for (try = 0; try < 5; try++) {
1111 /* Load the send data into the aux channel data registers */
1112 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001113 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001114 intel_dp_pack_aux(send + i,
1115 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001116
Chris Wilsonbc866252013-07-21 16:00:03 +01001117 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001118 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001119
Chris Wilsonbc866252013-07-21 16:00:03 +01001120 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001121
Chris Wilsonbc866252013-07-21 16:00:03 +01001122 /* Clear done status and any errors */
1123 I915_WRITE(ch_ctl,
1124 status |
1125 DP_AUX_CH_CTL_DONE |
1126 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1127 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001128
Todd Previte74ebf292015-04-15 08:38:41 -07001129 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001130 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001131
1132 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1133 * 400us delay required for errors and timeouts
1134 * Timeout errors from the HW already meet this
1135 * requirement so skip to next iteration
1136 */
1137 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1138 usleep_range(400, 500);
1139 continue;
1140 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001141 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001142 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001143 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001144 }
1145
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001146 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001147 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001148 ret = -EBUSY;
1149 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001150 }
1151
Jim Bridee058c942015-05-27 10:21:48 -07001152done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001153 /* Check for timeout or receive error.
1154 * Timeouts occur when the sink is not connected
1155 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001156 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001157 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001158 ret = -EIO;
1159 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001160 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001161
1162 /* Timeouts occur when the device isn't connected, so they're
1163 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001164 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001165 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001166 ret = -ETIMEDOUT;
1167 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001168 }
1169
1170 /* Unload any bytes sent back from the other side */
1171 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1172 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001173
1174 /*
1175 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1176 * We have no idea of what happened so we return -EBUSY so
1177 * drm layer takes care for the necessary retries.
1178 */
1179 if (recv_bytes == 0 || recv_bytes > 20) {
1180 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1181 recv_bytes);
1182 /*
1183 * FIXME: This patch was created on top of a series that
1184 * organize the retries at drm level. There EBUSY should
1185 * also take care for 1ms wait before retrying.
1186 * That aux retries re-org is still needed and after that is
1187 * merged we remove this sleep from here.
1188 */
1189 usleep_range(1000, 1500);
1190 ret = -EBUSY;
1191 goto out;
1192 }
1193
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001194 if (recv_bytes > recv_size)
1195 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001196
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001197 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001198 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001199 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001200
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001201 ret = recv_bytes;
1202out:
1203 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1204
Jani Nikula884f19e2014-03-14 16:51:14 +02001205 if (vdd)
1206 edp_panel_vdd_off(intel_dp, false);
1207
Ville Syrjälä773538e82014-09-04 14:54:56 +03001208 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001209
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001210 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001211}
1212
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001213#define BARE_ADDRESS_SIZE 3
1214#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001215static ssize_t
1216intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001217{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001218 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1219 uint8_t txbuf[20], rxbuf[20];
1220 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001221 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001222
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001223 txbuf[0] = (msg->request << 4) |
1224 ((msg->address >> 16) & 0xf);
1225 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001226 txbuf[2] = msg->address & 0xff;
1227 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001228
Jani Nikula9d1a1032014-03-14 16:51:15 +02001229 switch (msg->request & ~DP_AUX_I2C_MOT) {
1230 case DP_AUX_NATIVE_WRITE:
1231 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001232 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001233 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001234 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001235
Jani Nikula9d1a1032014-03-14 16:51:15 +02001236 if (WARN_ON(txsize > 20))
1237 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001238
Ville Syrjälädd788092016-07-28 17:55:04 +03001239 WARN_ON(!msg->buffer != !msg->size);
1240
Imre Deakd81a67c2016-01-29 14:52:26 +02001241 if (msg->buffer)
1242 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001243
Jani Nikula9d1a1032014-03-14 16:51:15 +02001244 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1245 if (ret > 0) {
1246 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001247
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001248 if (ret > 1) {
1249 /* Number of bytes written in a short write. */
1250 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1251 } else {
1252 /* Return payload size. */
1253 ret = msg->size;
1254 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001255 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001256 break;
1257
1258 case DP_AUX_NATIVE_READ:
1259 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001260 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001261 rxsize = msg->size + 1;
1262
1263 if (WARN_ON(rxsize > 20))
1264 return -E2BIG;
1265
1266 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1267 if (ret > 0) {
1268 msg->reply = rxbuf[0] >> 4;
1269 /*
1270 * Assume happy day, and copy the data. The caller is
1271 * expected to check msg->reply before touching it.
1272 *
1273 * Return payload size.
1274 */
1275 ret--;
1276 memcpy(msg->buffer, rxbuf + 1, ret);
1277 }
1278 break;
1279
1280 default:
1281 ret = -EINVAL;
1282 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001283 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001284
Jani Nikula9d1a1032014-03-14 16:51:15 +02001285 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001286}
1287
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001288static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1289 enum port port)
1290{
1291 const struct ddi_vbt_port_info *info =
1292 &dev_priv->vbt.ddi_port_info[port];
1293 enum port aux_port;
1294
1295 if (!info->alternate_aux_channel) {
1296 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1297 port_name(port), port_name(port));
1298 return port;
1299 }
1300
1301 switch (info->alternate_aux_channel) {
1302 case DP_AUX_A:
1303 aux_port = PORT_A;
1304 break;
1305 case DP_AUX_B:
1306 aux_port = PORT_B;
1307 break;
1308 case DP_AUX_C:
1309 aux_port = PORT_C;
1310 break;
1311 case DP_AUX_D:
1312 aux_port = PORT_D;
1313 break;
1314 default:
1315 MISSING_CASE(info->alternate_aux_channel);
1316 aux_port = PORT_A;
1317 break;
1318 }
1319
1320 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1321 port_name(aux_port), port_name(port));
1322
1323 return aux_port;
1324}
1325
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001326static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001327 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001328{
1329 switch (port) {
1330 case PORT_B:
1331 case PORT_C:
1332 case PORT_D:
1333 return DP_AUX_CH_CTL(port);
1334 default:
1335 MISSING_CASE(port);
1336 return DP_AUX_CH_CTL(PORT_B);
1337 }
1338}
1339
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001340static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001341 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001342{
1343 switch (port) {
1344 case PORT_B:
1345 case PORT_C:
1346 case PORT_D:
1347 return DP_AUX_CH_DATA(port, index);
1348 default:
1349 MISSING_CASE(port);
1350 return DP_AUX_CH_DATA(PORT_B, index);
1351 }
1352}
1353
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001354static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001355 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001356{
1357 switch (port) {
1358 case PORT_A:
1359 return DP_AUX_CH_CTL(port);
1360 case PORT_B:
1361 case PORT_C:
1362 case PORT_D:
1363 return PCH_DP_AUX_CH_CTL(port);
1364 default:
1365 MISSING_CASE(port);
1366 return DP_AUX_CH_CTL(PORT_A);
1367 }
1368}
1369
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001370static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001371 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001372{
1373 switch (port) {
1374 case PORT_A:
1375 return DP_AUX_CH_DATA(port, index);
1376 case PORT_B:
1377 case PORT_C:
1378 case PORT_D:
1379 return PCH_DP_AUX_CH_DATA(port, index);
1380 default:
1381 MISSING_CASE(port);
1382 return DP_AUX_CH_DATA(PORT_A, index);
1383 }
1384}
1385
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001386static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001387 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001388{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001389 switch (port) {
1390 case PORT_A:
1391 case PORT_B:
1392 case PORT_C:
1393 case PORT_D:
1394 return DP_AUX_CH_CTL(port);
1395 default:
1396 MISSING_CASE(port);
1397 return DP_AUX_CH_CTL(PORT_A);
1398 }
1399}
1400
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001401static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001402 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001403{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001404 switch (port) {
1405 case PORT_A:
1406 case PORT_B:
1407 case PORT_C:
1408 case PORT_D:
1409 return DP_AUX_CH_DATA(port, index);
1410 default:
1411 MISSING_CASE(port);
1412 return DP_AUX_CH_DATA(PORT_A, index);
1413 }
1414}
1415
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001416static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001417 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001418{
1419 if (INTEL_INFO(dev_priv)->gen >= 9)
1420 return skl_aux_ctl_reg(dev_priv, port);
1421 else if (HAS_PCH_SPLIT(dev_priv))
1422 return ilk_aux_ctl_reg(dev_priv, port);
1423 else
1424 return g4x_aux_ctl_reg(dev_priv, port);
1425}
1426
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001427static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001428 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001429{
1430 if (INTEL_INFO(dev_priv)->gen >= 9)
1431 return skl_aux_data_reg(dev_priv, port, index);
1432 else if (HAS_PCH_SPLIT(dev_priv))
1433 return ilk_aux_data_reg(dev_priv, port, index);
1434 else
1435 return g4x_aux_data_reg(dev_priv, port, index);
1436}
1437
1438static void intel_aux_reg_init(struct intel_dp *intel_dp)
1439{
1440 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001441 enum port port = intel_aux_port(dev_priv,
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001442 dp_to_dig_port(intel_dp)->base.port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001443 int i;
1444
1445 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1446 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1447 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1448}
1449
Jani Nikula9d1a1032014-03-14 16:51:15 +02001450static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001451intel_dp_aux_fini(struct intel_dp *intel_dp)
1452{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001453 kfree(intel_dp->aux.name);
1454}
1455
Chris Wilson7a418e32016-06-24 14:00:14 +01001456static void
Mika Kaholab6339582016-09-09 14:10:52 +03001457intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001458{
Jani Nikula33ad6622014-03-14 16:51:16 +02001459 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001460 enum port port = intel_dig_port->base.port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001461
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001462 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001463 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001464
Chris Wilson7a418e32016-06-24 14:00:14 +01001465 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001466 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001467 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001468}
1469
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001470bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301471{
Jani Nikulafc603ca2017-10-09 12:29:58 +03001472 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001473
Jani Nikulafc603ca2017-10-09 12:29:58 +03001474 return max_rate >= 540000;
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301475}
1476
Daniel Vetter0e503382014-07-04 11:26:04 -03001477static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001478intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001479 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001480{
1481 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001482 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001483 const struct dp_link_dpll *divisor = NULL;
1484 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001485
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001486 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001487 divisor = gen4_dpll;
1488 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001489 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001490 divisor = pch_dpll;
1491 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001492 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001493 divisor = chv_dpll;
1494 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001495 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001496 divisor = vlv_dpll;
1497 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001498 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001499
1500 if (divisor && count) {
1501 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001502 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001503 pipe_config->dpll = divisor[i].dpll;
1504 pipe_config->clock_set = true;
1505 break;
1506 }
1507 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001508 }
1509}
1510
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001511static void snprintf_int_array(char *str, size_t len,
1512 const int *array, int nelem)
1513{
1514 int i;
1515
1516 str[0] = '\0';
1517
1518 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001519 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001520 if (r >= len)
1521 return;
1522 str += r;
1523 len -= r;
1524 }
1525}
1526
1527static void intel_dp_print_rates(struct intel_dp *intel_dp)
1528{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001529 char str[128]; /* FIXME: too big for stack? */
1530
1531 if ((drm_debug & DRM_UT_KMS) == 0)
1532 return;
1533
Jani Nikula55cfc582017-03-28 17:59:04 +03001534 snprintf_int_array(str, sizeof(str),
1535 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001536 DRM_DEBUG_KMS("source rates: %s\n", str);
1537
Jani Nikula68f357c2017-03-28 17:59:05 +03001538 snprintf_int_array(str, sizeof(str),
1539 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001540 DRM_DEBUG_KMS("sink rates: %s\n", str);
1541
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001542 snprintf_int_array(str, sizeof(str),
1543 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001544 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001545}
1546
Ville Syrjälä50fec212015-03-12 17:10:34 +02001547int
1548intel_dp_max_link_rate(struct intel_dp *intel_dp)
1549{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001550 int len;
1551
Jani Nikulae6c0c642017-04-06 16:44:12 +03001552 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001553 if (WARN_ON(len <= 0))
1554 return 162000;
1555
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001556 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001557}
1558
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001559int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1560{
Jani Nikula8001b752017-03-28 17:59:03 +03001561 int i = intel_dp_rate_index(intel_dp->sink_rates,
1562 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001563
1564 if (WARN_ON(i < 0))
1565 i = 0;
1566
1567 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001568}
1569
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001570void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1571 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001572{
Jani Nikula68f357c2017-03-28 17:59:05 +03001573 /* eDP 1.4 rate select method. */
1574 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001575 *link_bw = 0;
1576 *rate_select =
1577 intel_dp_rate_select(intel_dp, port_clock);
1578 } else {
1579 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1580 *rate_select = 0;
1581 }
1582}
1583
Jani Nikulaf580bea2016-09-15 16:28:52 +03001584static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1585 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001586{
1587 int bpp, bpc;
1588
1589 bpp = pipe_config->pipe_bpp;
1590 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1591
1592 if (bpc > 0)
1593 bpp = min(bpp, 3*bpc);
1594
Manasi Navare611032b2017-01-24 08:21:49 -08001595 /* For DP Compliance we override the computed bpp for the pipe */
1596 if (intel_dp->compliance.test_data.bpc != 0) {
1597 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1598 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1599 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1600 pipe_config->pipe_bpp);
1601 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001602 return bpp;
1603}
1604
Jim Bridedc911f52017-08-09 12:48:53 -07001605static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1606 struct drm_display_mode *m2)
1607{
1608 bool bres = false;
1609
1610 if (m1 && m2)
1611 bres = (m1->hdisplay == m2->hdisplay &&
1612 m1->hsync_start == m2->hsync_start &&
1613 m1->hsync_end == m2->hsync_end &&
1614 m1->htotal == m2->htotal &&
1615 m1->vdisplay == m2->vdisplay &&
1616 m1->vsync_start == m2->vsync_start &&
1617 m1->vsync_end == m2->vsync_end &&
1618 m1->vtotal == m2->vtotal);
1619 return bres;
1620}
1621
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001622bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001623intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001624 struct intel_crtc_state *pipe_config,
1625 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001626{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001627 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001628 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001629 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001630 enum port port = encoder->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001631 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001632 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001633 struct intel_digital_connector_state *intel_conn_state =
1634 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001635 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001636 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001637 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001638 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001639 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301640 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001641 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001642 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001643 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001644 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001645 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1646 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301647
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001648 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001649 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301650
1651 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001652 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301653
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001654 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001655
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001656 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001657 pipe_config->has_pch_encoder = true;
1658
Vandana Kannanf769cd22014-08-05 07:51:22 -07001659 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001660 if (port == PORT_A)
1661 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001662 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001663 pipe_config->has_audio = intel_dp->has_audio;
1664 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001665 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001666
Jani Nikula1853a9d2017-08-18 12:30:20 +03001667 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jim Bridedc911f52017-08-09 12:48:53 -07001668 struct drm_display_mode *panel_mode =
1669 intel_connector->panel.alt_fixed_mode;
1670 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1671
1672 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1673 panel_mode = intel_connector->panel.fixed_mode;
1674
1675 drm_mode_debug_printmodeline(panel_mode);
1676
1677 intel_fixed_panel_mode(panel_mode, adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001678
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001679 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001680 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001681 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001682 if (ret)
1683 return ret;
1684 }
1685
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001686 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001687 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001688 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001689 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001690 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001691 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001692 }
1693
Daniel Vettercb1793c2012-06-04 18:39:21 +02001694 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001695 return false;
1696
Manasi Navareda15f7c2017-01-24 08:16:34 -08001697 /* Use values requested by Compliance Test Request */
1698 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001699 int index;
1700
Manasi Navare140ef132017-06-08 13:41:03 -07001701 /* Validate the compliance test data since max values
1702 * might have changed due to link train fallback.
1703 */
1704 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1705 intel_dp->compliance.test_lane_count)) {
1706 index = intel_dp_rate_index(intel_dp->common_rates,
1707 intel_dp->num_common_rates,
1708 intel_dp->compliance.test_link_rate);
1709 if (index >= 0)
1710 min_clock = max_clock = index;
1711 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1712 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08001713 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001714 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301715 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001716 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001717 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001718
Daniel Vetter36008362013-03-27 00:44:59 +01001719 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1720 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001721 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula1853a9d2017-08-18 12:30:20 +03001722 if (intel_dp_is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301723
1724 /* Get bpp from vbt only for panels that dont have bpp in edid */
1725 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001726 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001727 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001728 dev_priv->vbt.edp.bpp);
1729 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001730 }
1731
Jani Nikula344c5bb2014-09-09 11:25:13 +03001732 /*
1733 * Use the maximum clock and number of lanes the eDP panel
1734 * advertizes being capable of. The panels are generally
1735 * designed to support only a single clock and lane
1736 * configuration, and typically these values correspond to the
1737 * native resolution of the panel.
1738 */
1739 min_lane_count = max_lane_count;
1740 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001741 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001742
Daniel Vetter36008362013-03-27 00:44:59 +01001743 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001744 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1745 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001746
Dave Airliec6930992014-07-14 11:04:39 +10001747 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301748 for (lane_count = min_lane_count;
1749 lane_count <= max_lane_count;
1750 lane_count <<= 1) {
1751
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001752 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001753 link_avail = intel_dp_max_data_rate(link_clock,
1754 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001755
Daniel Vetter36008362013-03-27 00:44:59 +01001756 if (mode_rate <= link_avail) {
1757 goto found;
1758 }
1759 }
1760 }
1761 }
1762
1763 return false;
1764
1765found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001766 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001767 /*
1768 * See:
1769 * CEA-861-E - 5.1 Default Encoding Parameters
1770 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1771 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001772 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001773 bpp != 18 &&
1774 drm_default_rgb_quant_range(adjusted_mode) ==
1775 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001776 } else {
1777 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001778 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001779 }
1780
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001781 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301782
Daniel Vetter657445f2013-05-04 10:09:18 +02001783 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001784 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001785
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001786 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1787 &link_bw, &rate_select);
1788
1789 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1790 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001791 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001792 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1793 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001794
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001795 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001796 adjusted_mode->crtc_clock,
1797 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001798 &pipe_config->dp_m_n,
1799 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001800
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301801 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301802 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001803 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301804 intel_link_compute_m_n(bpp, lane_count,
1805 intel_connector->panel.downclock_mode->clock,
1806 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001807 &pipe_config->dp_m2_n2,
1808 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301809 }
1810
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001811 /*
1812 * DPLL0 VCO may need to be adjusted to get the correct
1813 * clock for eDP. This will affect cdclk as well.
1814 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03001815 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001816 int vco;
1817
1818 switch (pipe_config->port_clock / 2) {
1819 case 108000:
1820 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001821 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001822 break;
1823 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001824 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001825 break;
1826 }
1827
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001828 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001829 }
1830
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001831 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001832 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001833
Ville Syrjälä4d90f2d2017-10-12 16:02:01 +03001834 intel_psr_compute_config(intel_dp, pipe_config);
1835
Daniel Vetter36008362013-03-27 00:44:59 +01001836 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001837}
1838
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001839void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001840 int link_rate, uint8_t lane_count,
1841 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001842{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001843 intel_dp->link_rate = link_rate;
1844 intel_dp->lane_count = lane_count;
1845 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001846}
1847
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001848static void intel_dp_prepare(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03001849 const struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001850{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001851 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001852 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001853 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001854 enum port port = encoder->port;
Ville Syrjäläadc10302017-10-31 22:51:14 +02001855 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001856 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001857
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001858 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1859 pipe_config->lane_count,
1860 intel_crtc_has_type(pipe_config,
1861 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001862
Keith Packard417e8222011-11-01 19:54:11 -07001863 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001864 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001865 *
1866 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001867 * SNB CPU
1868 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001869 * CPT PCH
1870 *
1871 * IBX PCH and CPU are the same for almost everything,
1872 * except that the CPU DP PLL is configured in this
1873 * register
1874 *
1875 * CPT PCH is quite different, having many bits moved
1876 * to the TRANS_DP_CTL register instead. That
1877 * configuration happens (oddly) in ironlake_pch_enable
1878 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001879
Keith Packard417e8222011-11-01 19:54:11 -07001880 /* Preserve the BIOS-computed detected bit. This is
1881 * supposed to be read-only.
1882 */
1883 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001884
Keith Packard417e8222011-11-01 19:54:11 -07001885 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001886 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001887 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001888
Keith Packard417e8222011-11-01 19:54:11 -07001889 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001890
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001891 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001892 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1893 intel_dp->DP |= DP_SYNC_HS_HIGH;
1894 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1895 intel_dp->DP |= DP_SYNC_VS_HIGH;
1896 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1897
Jani Nikula6aba5b62013-10-04 15:08:10 +03001898 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001899 intel_dp->DP |= DP_ENHANCED_FRAMING;
1900
Daniel Vetter7c62a162013-06-01 17:16:20 +02001901 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001902 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001903 u32 trans_dp;
1904
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001905 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001906
1907 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1908 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1909 trans_dp |= TRANS_DP_ENH_FRAMING;
1910 else
1911 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1912 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001913 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001914 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001915 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001916
1917 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1918 intel_dp->DP |= DP_SYNC_HS_HIGH;
1919 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1920 intel_dp->DP |= DP_SYNC_VS_HIGH;
1921 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1922
Jani Nikula6aba5b62013-10-04 15:08:10 +03001923 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001924 intel_dp->DP |= DP_ENHANCED_FRAMING;
1925
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001926 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001927 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001928 else if (crtc->pipe == PIPE_B)
1929 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001930 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001931}
1932
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001933#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1934#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001935
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001936#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1937#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001938
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001939#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1940#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001941
Ville Syrjälä46bd8382017-10-31 22:51:22 +02001942static void intel_pps_verify_state(struct intel_dp *intel_dp);
Imre Deakde9c1b62016-06-16 20:01:46 +03001943
Daniel Vetter4be73782014-01-17 14:39:48 +01001944static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001945 u32 mask,
1946 u32 value)
1947{
Paulo Zanoni30add222012-10-26 19:05:45 -02001948 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001949 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001950 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001951
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001952 lockdep_assert_held(&dev_priv->pps_mutex);
1953
Ville Syrjälä46bd8382017-10-31 22:51:22 +02001954 intel_pps_verify_state(intel_dp);
Imre Deakde9c1b62016-06-16 20:01:46 +03001955
Jani Nikulabf13e812013-09-06 07:40:05 +03001956 pp_stat_reg = _pp_stat_reg(intel_dp);
1957 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001958
1959 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001960 mask, value,
1961 I915_READ(pp_stat_reg),
1962 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001963
Chris Wilson9036ff02016-06-30 15:33:09 +01001964 if (intel_wait_for_register(dev_priv,
1965 pp_stat_reg, mask, value,
1966 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001967 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001968 I915_READ(pp_stat_reg),
1969 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001970
1971 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001972}
1973
Daniel Vetter4be73782014-01-17 14:39:48 +01001974static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001975{
1976 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001977 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001978}
1979
Daniel Vetter4be73782014-01-17 14:39:48 +01001980static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001981{
Keith Packardbd943152011-09-18 23:09:52 -07001982 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001983 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001984}
Keith Packardbd943152011-09-18 23:09:52 -07001985
Daniel Vetter4be73782014-01-17 14:39:48 +01001986static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001987{
Abhay Kumard28d4732016-01-22 17:39:04 -08001988 ktime_t panel_power_on_time;
1989 s64 panel_power_off_duration;
1990
Keith Packard99ea7122011-11-01 19:57:50 -07001991 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001992
Abhay Kumard28d4732016-01-22 17:39:04 -08001993 /* take the difference of currrent time and panel power off time
1994 * and then make panel wait for t11_t12 if needed. */
1995 panel_power_on_time = ktime_get_boottime();
1996 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1997
Paulo Zanonidce56b32013-12-19 14:29:40 -02001998 /* When we disable the VDD override bit last we have to do the manual
1999 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08002000 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2001 wait_remaining_ms_from_jiffies(jiffies,
2002 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002003
Daniel Vetter4be73782014-01-17 14:39:48 +01002004 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002005}
Keith Packardbd943152011-09-18 23:09:52 -07002006
Daniel Vetter4be73782014-01-17 14:39:48 +01002007static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002008{
2009 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2010 intel_dp->backlight_on_delay);
2011}
2012
Daniel Vetter4be73782014-01-17 14:39:48 +01002013static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002014{
2015 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2016 intel_dp->backlight_off_delay);
2017}
Keith Packard99ea7122011-11-01 19:57:50 -07002018
Keith Packard832dd3c2011-11-01 19:34:06 -07002019/* Read the current pp_control value, unlocking the register if it
2020 * is locked
2021 */
2022
Jesse Barnes453c5422013-03-28 09:55:41 -07002023static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002024{
Jesse Barnes453c5422013-03-28 09:55:41 -07002025 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002026 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002027 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002028
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002029 lockdep_assert_held(&dev_priv->pps_mutex);
2030
Jani Nikulabf13e812013-09-06 07:40:05 +03002031 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002032 if (WARN_ON(!HAS_DDI(dev_priv) &&
2033 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302034 control &= ~PANEL_UNLOCK_MASK;
2035 control |= PANEL_UNLOCK_REGS;
2036 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002037 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002038}
2039
Ville Syrjälä951468f2014-09-04 14:55:31 +03002040/*
2041 * Must be paired with edp_panel_vdd_off().
2042 * Must hold pps_mutex around the whole on/off sequence.
2043 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2044 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002045static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002046{
Paulo Zanoni30add222012-10-26 19:05:45 -02002047 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002048 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002049 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002050 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002051 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002052 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002053
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002054 lockdep_assert_held(&dev_priv->pps_mutex);
2055
Jani Nikula1853a9d2017-08-18 12:30:20 +03002056 if (!intel_dp_is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002057 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002058
Egbert Eich2c623c12014-11-25 12:54:57 +01002059 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002060 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002061
Daniel Vetter4be73782014-01-17 14:39:48 +01002062 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002063 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002064
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002065 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002066
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002067 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002068 port_name(intel_dig_port->base.port));
Keith Packardbd943152011-09-18 23:09:52 -07002069
Daniel Vetter4be73782014-01-17 14:39:48 +01002070 if (!edp_have_panel_power(intel_dp))
2071 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002072
Jesse Barnes453c5422013-03-28 09:55:41 -07002073 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002074 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002075
Jani Nikulabf13e812013-09-06 07:40:05 +03002076 pp_stat_reg = _pp_stat_reg(intel_dp);
2077 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002078
2079 I915_WRITE(pp_ctrl_reg, pp);
2080 POSTING_READ(pp_ctrl_reg);
2081 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2082 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002083 /*
2084 * If the panel wasn't on, delay before accessing aux channel
2085 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002086 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002087 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002088 port_name(intel_dig_port->base.port));
Keith Packardf01eca22011-09-28 16:48:10 -07002089 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002090 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002091
2092 return need_to_disable;
2093}
2094
Ville Syrjälä951468f2014-09-04 14:55:31 +03002095/*
2096 * Must be paired with intel_edp_panel_vdd_off() or
2097 * intel_edp_panel_off().
2098 * Nested calls to these functions are not allowed since
2099 * we drop the lock. Caller must use some higher level
2100 * locking to prevent nested calls from other threads.
2101 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002102void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002103{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002104 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002105
Jani Nikula1853a9d2017-08-18 12:30:20 +03002106 if (!intel_dp_is_edp(intel_dp))
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002107 return;
2108
Ville Syrjälä773538e82014-09-04 14:54:56 +03002109 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002110 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002111 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002112
Rob Clarke2c719b2014-12-15 13:56:32 -05002113 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002114 port_name(dp_to_dig_port(intel_dp)->base.port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002115}
2116
Daniel Vetter4be73782014-01-17 14:39:48 +01002117static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002118{
Paulo Zanoni30add222012-10-26 19:05:45 -02002119 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002120 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002121 struct intel_digital_port *intel_dig_port =
2122 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002123 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002124 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002125
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002126 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002127
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002128 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002129
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002130 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002131 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002132
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002133 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002134 port_name(intel_dig_port->base.port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002135
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002136 pp = ironlake_get_pp_control(intel_dp);
2137 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002138
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002139 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2140 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002141
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002142 I915_WRITE(pp_ctrl_reg, pp);
2143 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002144
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002145 /* Make sure sequencer is idle before allowing subsequent activity */
2146 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2147 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002148
Imre Deak5a162e22016-08-10 14:07:30 +03002149 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002150 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002151
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002152 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002153}
2154
Daniel Vetter4be73782014-01-17 14:39:48 +01002155static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002156{
2157 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2158 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002159
Ville Syrjälä773538e82014-09-04 14:54:56 +03002160 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002161 if (!intel_dp->want_panel_vdd)
2162 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002163 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002164}
2165
Imre Deakaba86892014-07-30 15:57:31 +03002166static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2167{
2168 unsigned long delay;
2169
2170 /*
2171 * Queue the timer to fire a long time from now (relative to the power
2172 * down delay) to keep the panel power up across a sequence of
2173 * operations.
2174 */
2175 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2176 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2177}
2178
Ville Syrjälä951468f2014-09-04 14:55:31 +03002179/*
2180 * Must be paired with edp_panel_vdd_on().
2181 * Must hold pps_mutex around the whole on/off sequence.
2182 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2183 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002184static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002185{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002186 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002187
2188 lockdep_assert_held(&dev_priv->pps_mutex);
2189
Jani Nikula1853a9d2017-08-18 12:30:20 +03002190 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002191 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002192
Rob Clarke2c719b2014-12-15 13:56:32 -05002193 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002194 port_name(dp_to_dig_port(intel_dp)->base.port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002195
Keith Packardbd943152011-09-18 23:09:52 -07002196 intel_dp->want_panel_vdd = false;
2197
Imre Deakaba86892014-07-30 15:57:31 +03002198 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002199 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002200 else
2201 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002202}
2203
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002204static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002205{
Paulo Zanoni30add222012-10-26 19:05:45 -02002206 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002207 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002208 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002209 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002210
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002211 lockdep_assert_held(&dev_priv->pps_mutex);
2212
Jani Nikula1853a9d2017-08-18 12:30:20 +03002213 if (!intel_dp_is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002214 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002215
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002216 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002217 port_name(dp_to_dig_port(intel_dp)->base.port));
Keith Packard99ea7122011-11-01 19:57:50 -07002218
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002219 if (WARN(edp_have_panel_power(intel_dp),
2220 "eDP port %c panel power already on\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002221 port_name(dp_to_dig_port(intel_dp)->base.port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002222 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002223
Daniel Vetter4be73782014-01-17 14:39:48 +01002224 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002225
Jani Nikulabf13e812013-09-06 07:40:05 +03002226 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002227 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002228 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002229 /* ILK workaround: disable reset around power sequence */
2230 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002231 I915_WRITE(pp_ctrl_reg, pp);
2232 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002233 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002234
Imre Deak5a162e22016-08-10 14:07:30 +03002235 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002236 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002237 pp |= PANEL_POWER_RESET;
2238
Jesse Barnes453c5422013-03-28 09:55:41 -07002239 I915_WRITE(pp_ctrl_reg, pp);
2240 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002241
Daniel Vetter4be73782014-01-17 14:39:48 +01002242 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002243 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002244
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002245 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002246 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002247 I915_WRITE(pp_ctrl_reg, pp);
2248 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002249 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002250}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002251
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002252void intel_edp_panel_on(struct intel_dp *intel_dp)
2253{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002254 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002255 return;
2256
2257 pps_lock(intel_dp);
2258 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002259 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002260}
2261
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002262
2263static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002264{
Paulo Zanoni30add222012-10-26 19:05:45 -02002265 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002266 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002267 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002268 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002269
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002270 lockdep_assert_held(&dev_priv->pps_mutex);
2271
Jani Nikula1853a9d2017-08-18 12:30:20 +03002272 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002273 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002274
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002275 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002276 port_name(dp_to_dig_port(intel_dp)->base.port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002277
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002278 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 +02002279 port_name(dp_to_dig_port(intel_dp)->base.port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002280
Jesse Barnes453c5422013-03-28 09:55:41 -07002281 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002282 /* We need to switch off panel power _and_ force vdd, for otherwise some
2283 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002284 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002285 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002286
Jani Nikulabf13e812013-09-06 07:40:05 +03002287 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002288
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002289 intel_dp->want_panel_vdd = false;
2290
Jesse Barnes453c5422013-03-28 09:55:41 -07002291 I915_WRITE(pp_ctrl_reg, pp);
2292 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002293
Daniel Vetter4be73782014-01-17 14:39:48 +01002294 wait_panel_off(intel_dp);
Manasi Navarecbacf022017-10-04 09:48:26 -07002295 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002296
2297 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002298 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002299}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002300
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002301void intel_edp_panel_off(struct intel_dp *intel_dp)
2302{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002303 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002304 return;
2305
2306 pps_lock(intel_dp);
2307 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002308 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002309}
2310
Jani Nikula1250d102014-08-12 17:11:39 +03002311/* Enable backlight in the panel power control. */
2312static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002313{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002314 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2315 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002316 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002317 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002318 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002319
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002320 /*
2321 * If we enable the backlight right away following a panel power
2322 * on, we may see slight flicker as the panel syncs with the eDP
2323 * link. So delay a bit to make sure the image is solid before
2324 * allowing it to appear.
2325 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002326 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002327
Ville Syrjälä773538e82014-09-04 14:54:56 +03002328 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002329
Jesse Barnes453c5422013-03-28 09:55:41 -07002330 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002331 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002332
Jani Nikulabf13e812013-09-06 07:40:05 +03002333 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002334
2335 I915_WRITE(pp_ctrl_reg, pp);
2336 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002337
Ville Syrjälä773538e82014-09-04 14:54:56 +03002338 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002339}
2340
Jani Nikula1250d102014-08-12 17:11:39 +03002341/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002342void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2343 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002344{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002345 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2346
Jani Nikula1853a9d2017-08-18 12:30:20 +03002347 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002348 return;
2349
2350 DRM_DEBUG_KMS("\n");
2351
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002352 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002353 _intel_edp_backlight_on(intel_dp);
2354}
2355
2356/* Disable backlight in the panel power control. */
2357static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002358{
Paulo Zanoni30add222012-10-26 19:05:45 -02002359 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002360 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002361 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002362 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002363
Jani Nikula1853a9d2017-08-18 12:30:20 +03002364 if (!intel_dp_is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07002365 return;
2366
Ville Syrjälä773538e82014-09-04 14:54:56 +03002367 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002368
Jesse Barnes453c5422013-03-28 09:55:41 -07002369 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002370 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002371
Jani Nikulabf13e812013-09-06 07:40:05 +03002372 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002373
2374 I915_WRITE(pp_ctrl_reg, pp);
2375 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002376
Ville Syrjälä773538e82014-09-04 14:54:56 +03002377 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002378
Paulo Zanonidce56b32013-12-19 14:29:40 -02002379 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002380 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002381}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002382
Jani Nikula1250d102014-08-12 17:11:39 +03002383/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002384void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002385{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002386 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2387
Jani Nikula1853a9d2017-08-18 12:30:20 +03002388 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002389 return;
2390
2391 DRM_DEBUG_KMS("\n");
2392
2393 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002394 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002395}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002396
Jani Nikula73580fb72014-08-12 17:11:41 +03002397/*
2398 * Hook for controlling the panel power control backlight through the bl_power
2399 * sysfs attribute. Take care to handle multiple calls.
2400 */
2401static void intel_edp_backlight_power(struct intel_connector *connector,
2402 bool enable)
2403{
2404 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002405 bool is_enabled;
2406
Ville Syrjälä773538e82014-09-04 14:54:56 +03002407 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002408 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002409 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002410
2411 if (is_enabled == enable)
2412 return;
2413
Jani Nikula23ba9372014-08-27 14:08:43 +03002414 DRM_DEBUG_KMS("panel power control backlight %s\n",
2415 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002416
2417 if (enable)
2418 _intel_edp_backlight_on(intel_dp);
2419 else
2420 _intel_edp_backlight_off(intel_dp);
2421}
2422
Ville Syrjälä64e10772015-10-29 21:26:01 +02002423static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2424{
2425 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2426 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2427 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2428
2429 I915_STATE_WARN(cur_state != state,
2430 "DP port %c state assertion failure (expected %s, current %s)\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002431 port_name(dig_port->base.port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002432 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002433}
2434#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2435
2436static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2437{
2438 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2439
2440 I915_STATE_WARN(cur_state != state,
2441 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002442 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002443}
2444#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2445#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2446
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002447static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002448 const struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002449{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002450 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002451 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002452
Ville Syrjälä64e10772015-10-29 21:26:01 +02002453 assert_pipe_disabled(dev_priv, crtc->pipe);
2454 assert_dp_port_disabled(intel_dp);
2455 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002456
Ville Syrjäläabfce942015-10-29 21:26:03 +02002457 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002458 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002459
2460 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2461
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002462 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002463 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2464 else
2465 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2466
2467 I915_WRITE(DP_A, intel_dp->DP);
2468 POSTING_READ(DP_A);
2469 udelay(500);
2470
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002471 /*
2472 * [DevILK] Work around required when enabling DP PLL
2473 * while a pipe is enabled going to FDI:
2474 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2475 * 2. Program DP PLL enable
2476 */
2477 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002478 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002479
Daniel Vetter07679352012-09-06 22:15:42 +02002480 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002481
Daniel Vetter07679352012-09-06 22:15:42 +02002482 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002483 POSTING_READ(DP_A);
2484 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002485}
2486
Ville Syrjäläadc10302017-10-31 22:51:14 +02002487static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2488 const struct intel_crtc_state *old_crtc_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002489{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002490 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002491 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002492
Ville Syrjälä64e10772015-10-29 21:26:01 +02002493 assert_pipe_disabled(dev_priv, crtc->pipe);
2494 assert_dp_port_disabled(intel_dp);
2495 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002496
Ville Syrjäläabfce942015-10-29 21:26:03 +02002497 DRM_DEBUG_KMS("disabling eDP PLL\n");
2498
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002499 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002500
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002501 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002502 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002503 udelay(200);
2504}
2505
Ville Syrjälä857c4162017-10-27 12:45:23 +03002506static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2507{
2508 /*
2509 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2510 * be capable of signalling downstream hpd with a long pulse.
2511 * Whether or not that means D3 is safe to use is not clear,
2512 * but let's assume so until proven otherwise.
2513 *
2514 * FIXME should really check all downstream ports...
2515 */
2516 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2517 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2518 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2519}
2520
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002521/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002522void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002523{
2524 int ret, i;
2525
2526 /* Should have a valid DPCD by this point */
2527 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2528 return;
2529
2530 if (mode != DRM_MODE_DPMS_ON) {
Ville Syrjälä857c4162017-10-27 12:45:23 +03002531 if (downstream_hpd_needs_d0(intel_dp))
2532 return;
2533
Jani Nikula9d1a1032014-03-14 16:51:15 +02002534 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2535 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002536 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002537 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2538
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002539 /*
2540 * When turning on, we need to retry for 1ms to give the sink
2541 * time to wake up.
2542 */
2543 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002544 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2545 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002546 if (ret == 1)
2547 break;
2548 msleep(1);
2549 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002550
2551 if (ret == 1 && lspcon->active)
2552 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002553 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002554
2555 if (ret != 1)
2556 DRM_DEBUG_KMS("failed to %s sink power state\n",
2557 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002558}
2559
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002560static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2561 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002562{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002563 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002564 enum port port = encoder->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002565 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002566 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002567 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002568 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002569
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002570 if (!intel_display_power_get_if_enabled(dev_priv,
2571 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002572 return false;
2573
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002574 ret = false;
2575
Imre Deak6d129be2014-03-05 16:20:54 +02002576 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002577
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002578 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002579 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002580
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002581 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002582 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002583 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002584 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002585
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002586 for_each_pipe(dev_priv, p) {
2587 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2588 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2589 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002590 ret = true;
2591
2592 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002593 }
2594 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002595
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002596 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002597 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002598 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002599 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2600 } else {
2601 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002602 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002603
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002604 ret = true;
2605
2606out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002607 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002608
2609 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002610}
2611
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002612static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002613 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002614{
2615 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002616 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002617 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002618 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002619 enum port port = encoder->port;
Ville Syrjäläadc10302017-10-31 22:51:14 +02002620 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002621
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002622 if (encoder->type == INTEL_OUTPUT_EDP)
2623 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2624 else
2625 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2626
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002627 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002628
2629 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002630
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002631 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002632 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2633
2634 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002635 flags |= DRM_MODE_FLAG_PHSYNC;
2636 else
2637 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002638
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002639 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002640 flags |= DRM_MODE_FLAG_PVSYNC;
2641 else
2642 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002643 } else {
2644 if (tmp & DP_SYNC_HS_HIGH)
2645 flags |= DRM_MODE_FLAG_PHSYNC;
2646 else
2647 flags |= DRM_MODE_FLAG_NHSYNC;
2648
2649 if (tmp & DP_SYNC_VS_HIGH)
2650 flags |= DRM_MODE_FLAG_PVSYNC;
2651 else
2652 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002653 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002654
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002655 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002656
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002657 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002658 pipe_config->limited_color_range = true;
2659
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002660 pipe_config->lane_count =
2661 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2662
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002663 intel_dp_get_m_n(crtc, pipe_config);
2664
Ville Syrjälä18442d02013-09-13 16:00:08 +03002665 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002666 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002667 pipe_config->port_clock = 162000;
2668 else
2669 pipe_config->port_clock = 270000;
2670 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002671
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002672 pipe_config->base.adjusted_mode.crtc_clock =
2673 intel_dotclock_calculate(pipe_config->port_clock,
2674 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002675
Jani Nikula1853a9d2017-08-18 12:30:20 +03002676 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02002677 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002678 /*
2679 * This is a big fat ugly hack.
2680 *
2681 * Some machines in UEFI boot mode provide us a VBT that has 18
2682 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2683 * unknown we fail to light up. Yet the same BIOS boots up with
2684 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2685 * max, not what it tells us to use.
2686 *
2687 * Note: This will still be broken if the eDP panel is not lit
2688 * up by the BIOS, and thus we can't get the mode at module
2689 * load.
2690 */
2691 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002692 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2693 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002694 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002695}
2696
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002697static void intel_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002698 const struct intel_crtc_state *old_crtc_state,
2699 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002700{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002701 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002702
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002703 if (old_crtc_state->has_audio)
Ville Syrjälä8ec47de2017-10-30 20:46:53 +02002704 intel_audio_codec_disable(encoder,
2705 old_crtc_state, old_conn_state);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002706
2707 /* Make sure the panel is off before trying to change the mode. But also
2708 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002709 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002710 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002711 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002712 intel_edp_panel_off(intel_dp);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002713}
2714
2715static void g4x_disable_dp(struct intel_encoder *encoder,
2716 const struct intel_crtc_state *old_crtc_state,
2717 const struct drm_connector_state *old_conn_state)
2718{
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002719 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Daniel Vetter37398502012-09-06 22:15:44 +02002720
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002721 /* disable the port before the pipe on g4x */
Ville Syrjäläadc10302017-10-31 22:51:14 +02002722 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002723}
2724
2725static void ilk_disable_dp(struct intel_encoder *encoder,
2726 const struct intel_crtc_state *old_crtc_state,
2727 const struct drm_connector_state *old_conn_state)
2728{
2729 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2730}
2731
2732static void vlv_disable_dp(struct intel_encoder *encoder,
2733 const struct intel_crtc_state *old_crtc_state,
2734 const struct drm_connector_state *old_conn_state)
2735{
2736 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2737
2738 intel_psr_disable(intel_dp, old_crtc_state);
2739
2740 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Jesse Barnesd240f202010-08-13 15:43:26 -07002741}
2742
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002743static void ilk_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002744 const struct intel_crtc_state *old_crtc_state,
2745 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002746{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002747 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläadc10302017-10-31 22:51:14 +02002748 enum port port = encoder->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002749
Ville Syrjäläadc10302017-10-31 22:51:14 +02002750 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002751
2752 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002753 if (port == PORT_A)
Ville Syrjäläadc10302017-10-31 22:51:14 +02002754 ironlake_edp_pll_off(intel_dp, old_crtc_state);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002755}
2756
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002757static void vlv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002758 const struct intel_crtc_state *old_crtc_state,
2759 const struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002760{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002761 intel_dp_link_down(encoder, old_crtc_state);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002762}
2763
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002764static void chv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002765 const struct intel_crtc_state *old_crtc_state,
2766 const struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002767{
Ville Syrjäläadc10302017-10-31 22:51:14 +02002768 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002769
Ville Syrjäläadc10302017-10-31 22:51:14 +02002770 intel_dp_link_down(encoder, old_crtc_state);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002771
Ville Syrjäläa5805162015-05-26 20:42:30 +03002772 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002773
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002774 /* Assert data lane reset */
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02002775 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002776
Ville Syrjäläa5805162015-05-26 20:42:30 +03002777 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002778}
2779
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002780static void
2781_intel_dp_set_link_train(struct intel_dp *intel_dp,
2782 uint32_t *DP,
2783 uint8_t dp_train_pat)
2784{
2785 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2786 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002787 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002788 enum port port = intel_dig_port->base.port;
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002789
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002790 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2791 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2792 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2793
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002794 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795 uint32_t temp = I915_READ(DP_TP_CTL(port));
2796
2797 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2798 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2799 else
2800 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2801
2802 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2803 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2804 case DP_TRAINING_PATTERN_DISABLE:
2805 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2806
2807 break;
2808 case DP_TRAINING_PATTERN_1:
2809 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2810 break;
2811 case DP_TRAINING_PATTERN_2:
2812 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2813 break;
2814 case DP_TRAINING_PATTERN_3:
2815 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2816 break;
2817 }
2818 I915_WRITE(DP_TP_CTL(port), temp);
2819
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002820 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002821 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002822 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2823
2824 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2825 case DP_TRAINING_PATTERN_DISABLE:
2826 *DP |= DP_LINK_TRAIN_OFF_CPT;
2827 break;
2828 case DP_TRAINING_PATTERN_1:
2829 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2830 break;
2831 case DP_TRAINING_PATTERN_2:
2832 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2833 break;
2834 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002835 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002836 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2837 break;
2838 }
2839
2840 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002841 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002842 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2843 else
2844 *DP &= ~DP_LINK_TRAIN_MASK;
2845
2846 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2847 case DP_TRAINING_PATTERN_DISABLE:
2848 *DP |= DP_LINK_TRAIN_OFF;
2849 break;
2850 case DP_TRAINING_PATTERN_1:
2851 *DP |= DP_LINK_TRAIN_PAT_1;
2852 break;
2853 case DP_TRAINING_PATTERN_2:
2854 *DP |= DP_LINK_TRAIN_PAT_2;
2855 break;
2856 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002857 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002858 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2859 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002860 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002861 *DP |= DP_LINK_TRAIN_PAT_2;
2862 }
2863 break;
2864 }
2865 }
2866}
2867
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002868static void intel_dp_enable_port(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002869 const struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002870{
2871 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002872 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002873
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002874 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002875
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002876 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002877
2878 /*
2879 * Magic for VLV/CHV. We _must_ first set up the register
2880 * without actually enabling the port, and then do another
2881 * write to enable the port. Otherwise link training will
2882 * fail when the power sequencer is freshly used for this port.
2883 */
2884 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002885 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002886 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002887
2888 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2889 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002890}
2891
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002892static void intel_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002893 const struct intel_crtc_state *pipe_config,
2894 const struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002895{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002896 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2897 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002898 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläadc10302017-10-31 22:51:14 +02002899 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002900 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002901 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002902
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002903 if (WARN_ON(dp_reg & DP_PORT_EN))
2904 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002905
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002906 pps_lock(intel_dp);
2907
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002908 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläadc10302017-10-31 22:51:14 +02002909 vlv_init_panel_power_sequencer(encoder, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002910
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002911 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002912
2913 edp_panel_vdd_on(intel_dp);
2914 edp_panel_on(intel_dp);
2915 edp_panel_vdd_off(intel_dp, true);
2916
2917 pps_unlock(intel_dp);
2918
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002919 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002920 unsigned int lane_mask = 0x0;
2921
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002922 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002923 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002924
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002925 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2926 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002927 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002928
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002929 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2930 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002931 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002932
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002933 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002934 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002935 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002936 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002937 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002938}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002939
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002940static void g4x_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002941 const struct intel_crtc_state *pipe_config,
2942 const struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002943{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002944 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002945 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002946}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002947
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002948static void vlv_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002949 const struct intel_crtc_state *pipe_config,
2950 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002951{
Jani Nikula828f5c62013-09-05 16:44:45 +03002952 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2953
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002954 intel_edp_backlight_on(pipe_config, conn_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002955 intel_psr_enable(intel_dp, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002956}
2957
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002958static void g4x_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002959 const struct intel_crtc_state *pipe_config,
2960 const struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002961{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002962 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002963 enum port port = encoder->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002964
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002965 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002966
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002967 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002968 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002969 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002970}
2971
Ville Syrjälä83b84592014-10-16 21:29:51 +03002972static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2973{
2974 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002975 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002976 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002977 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002978
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002979 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2980
Ville Syrjäläd1586942017-02-08 19:52:54 +02002981 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2982 return;
2983
Ville Syrjälä83b84592014-10-16 21:29:51 +03002984 edp_panel_vdd_off_sync(intel_dp);
2985
2986 /*
2987 * VLV seems to get confused when multiple power seqeuencers
2988 * have the same port selected (even if only one has power/vdd
2989 * enabled). The failure manifests as vlv_wait_port_ready() failing
2990 * CHV on the other hand doesn't seem to mind having the same port
2991 * selected in multiple power seqeuencers, but let's clear the
2992 * port select always when logically disconnecting a power sequencer
2993 * from a port.
2994 */
2995 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02002996 pipe_name(pipe), port_name(intel_dig_port->base.port));
Ville Syrjälä83b84592014-10-16 21:29:51 +03002997 I915_WRITE(pp_on_reg, 0);
2998 POSTING_READ(pp_on_reg);
2999
3000 intel_dp->pps_pipe = INVALID_PIPE;
3001}
3002
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003003static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003004 enum pipe pipe)
3005{
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003006 struct intel_encoder *encoder;
3007
3008 lockdep_assert_held(&dev_priv->pps_mutex);
3009
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003010 for_each_intel_encoder(&dev_priv->drm, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003011 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03003012 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003013
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003014 if (encoder->type != INTEL_OUTPUT_DP &&
3015 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003016 continue;
3017
3018 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003019 port = dp_to_dig_port(intel_dp)->base.port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003020
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003021 WARN(intel_dp->active_pipe == pipe,
3022 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3023 pipe_name(pipe), port_name(port));
3024
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003025 if (intel_dp->pps_pipe != pipe)
3026 continue;
3027
3028 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03003029 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003030
3031 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003032 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003033 }
3034}
3035
Ville Syrjäläadc10302017-10-31 22:51:14 +02003036static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3037 const struct intel_crtc_state *crtc_state)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003038{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003039 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjäläadc10302017-10-31 22:51:14 +02003040 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläadc10302017-10-31 22:51:14 +02003041 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003042
3043 lockdep_assert_held(&dev_priv->pps_mutex);
3044
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003045 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003046
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003047 if (intel_dp->pps_pipe != INVALID_PIPE &&
3048 intel_dp->pps_pipe != crtc->pipe) {
3049 /*
3050 * If another power sequencer was being used on this
3051 * port previously make sure to turn off vdd there while
3052 * we still have control of it.
3053 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003054 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003055 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003056
3057 /*
3058 * We may be stealing the power
3059 * sequencer from another port.
3060 */
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003061 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003062
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003063 intel_dp->active_pipe = crtc->pipe;
3064
Jani Nikula1853a9d2017-08-18 12:30:20 +03003065 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003066 return;
3067
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003068 /* now it's all ours */
3069 intel_dp->pps_pipe = crtc->pipe;
3070
3071 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
Ville Syrjäläadc10302017-10-31 22:51:14 +02003072 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003073
3074 /* init power sequencer on this pipe and port */
Ville Syrjälä46bd8382017-10-31 22:51:22 +02003075 intel_dp_init_panel_power_sequencer(intel_dp);
3076 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003077}
3078
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003079static void vlv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003080 const struct intel_crtc_state *pipe_config,
3081 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003082{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003083 vlv_phy_pre_encoder_enable(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003084
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003085 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003086}
3087
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003088static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003089 const struct intel_crtc_state *pipe_config,
3090 const struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003091{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003092 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003093
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003094 vlv_phy_pre_pll_enable(encoder, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003095}
3096
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003097static void chv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003098 const struct intel_crtc_state *pipe_config,
3099 const struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003100{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003101 chv_phy_pre_encoder_enable(encoder, pipe_config);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003102
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003103 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003104
3105 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003106 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003107}
3108
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003109static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003110 const struct intel_crtc_state *pipe_config,
3111 const struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003112{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003113 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003114
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003115 chv_phy_pre_pll_enable(encoder, pipe_config);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003116}
3117
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003118static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003119 const struct intel_crtc_state *old_crtc_state,
3120 const struct drm_connector_state *old_conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003121{
Ville Syrjälä2e1029c2017-10-31 22:51:18 +02003122 chv_phy_post_pll_disable(encoder, old_crtc_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003123}
3124
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003125/*
3126 * Fetch AUX CH registers 0x202 - 0x207 which contain
3127 * link status information
3128 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003129bool
Keith Packard93f62da2011-11-01 19:45:03 -07003130intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003131{
Lyude9f085eb2016-04-13 10:58:33 -04003132 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3133 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003134}
3135
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303136static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3137{
3138 uint8_t psr_caps = 0;
3139
Imre Deak9bacd4b2017-05-10 12:21:48 +03003140 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3141 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303142 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3143}
3144
3145static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3146{
3147 uint8_t dprx = 0;
3148
Imre Deak9bacd4b2017-05-10 12:21:48 +03003149 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3150 &dprx) != 1)
3151 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303152 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3153}
3154
Chris Wilsona76f73d2017-01-14 10:51:13 +00003155static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303156{
3157 uint8_t alpm_caps = 0;
3158
Imre Deak9bacd4b2017-05-10 12:21:48 +03003159 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3160 &alpm_caps) != 1)
3161 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303162 return alpm_caps & DP_ALPM_CAP;
3163}
3164
Paulo Zanoni11002442014-06-13 18:45:41 -03003165/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003166uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003167intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003168{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003169 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003170 enum port port = dp_to_dig_port(intel_dp)->base.port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003171
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03003172 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003173 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3174 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003175 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003177 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303178 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003179 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303180 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003181 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303182 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003183}
3184
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003185uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003186intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3187{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003188 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003189 enum port port = dp_to_dig_port(intel_dp)->base.port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003190
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003191 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003192 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3193 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3194 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3196 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3198 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303199 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3200 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003201 default:
3202 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3203 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003204 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003205 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303206 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3207 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3209 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3211 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3212 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003213 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303214 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003215 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003216 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3219 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3220 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3221 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3223 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3224 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003225 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303226 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003227 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003228 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003229 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303230 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3231 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3232 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3233 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3234 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003235 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303236 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003237 }
3238 } else {
3239 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303240 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3241 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3242 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3243 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3244 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3245 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3246 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003247 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303248 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003249 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003250 }
3251}
3252
Daniel Vetter5829975c2015-04-16 11:36:52 +02003253static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003254{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003255 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003256 unsigned long demph_reg_value, preemph_reg_value,
3257 uniqtranscale_reg_value;
3258 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003259
3260 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303261 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003262 preemph_reg_value = 0x0004000;
3263 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303264 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003265 demph_reg_value = 0x2B405555;
3266 uniqtranscale_reg_value = 0x552AB83A;
3267 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003269 demph_reg_value = 0x2B404040;
3270 uniqtranscale_reg_value = 0x5548B83A;
3271 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003273 demph_reg_value = 0x2B245555;
3274 uniqtranscale_reg_value = 0x5560B83A;
3275 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303276 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003277 demph_reg_value = 0x2B405555;
3278 uniqtranscale_reg_value = 0x5598DA3A;
3279 break;
3280 default:
3281 return 0;
3282 }
3283 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003285 preemph_reg_value = 0x0002000;
3286 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003288 demph_reg_value = 0x2B404040;
3289 uniqtranscale_reg_value = 0x5552B83A;
3290 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003292 demph_reg_value = 0x2B404848;
3293 uniqtranscale_reg_value = 0x5580B83A;
3294 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003296 demph_reg_value = 0x2B404040;
3297 uniqtranscale_reg_value = 0x55ADDA3A;
3298 break;
3299 default:
3300 return 0;
3301 }
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003304 preemph_reg_value = 0x0000000;
3305 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303306 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003307 demph_reg_value = 0x2B305555;
3308 uniqtranscale_reg_value = 0x5570B83A;
3309 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003311 demph_reg_value = 0x2B2B4040;
3312 uniqtranscale_reg_value = 0x55ADDA3A;
3313 break;
3314 default:
3315 return 0;
3316 }
3317 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003319 preemph_reg_value = 0x0006000;
3320 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003322 demph_reg_value = 0x1B405555;
3323 uniqtranscale_reg_value = 0x55ADDA3A;
3324 break;
3325 default:
3326 return 0;
3327 }
3328 break;
3329 default:
3330 return 0;
3331 }
3332
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003333 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3334 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003335
3336 return 0;
3337}
3338
Daniel Vetter5829975c2015-04-16 11:36:52 +02003339static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003340{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003341 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3342 u32 deemph_reg_value, margin_reg_value;
3343 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003344 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003345
3346 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303347 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003348 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303349 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003350 deemph_reg_value = 128;
3351 margin_reg_value = 52;
3352 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303353 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003354 deemph_reg_value = 128;
3355 margin_reg_value = 77;
3356 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303357 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003358 deemph_reg_value = 128;
3359 margin_reg_value = 102;
3360 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303361 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003362 deemph_reg_value = 128;
3363 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003364 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003365 break;
3366 default:
3367 return 0;
3368 }
3369 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303370 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003371 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303372 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003373 deemph_reg_value = 85;
3374 margin_reg_value = 78;
3375 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303376 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003377 deemph_reg_value = 85;
3378 margin_reg_value = 116;
3379 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003381 deemph_reg_value = 85;
3382 margin_reg_value = 154;
3383 break;
3384 default:
3385 return 0;
3386 }
3387 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303388 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003389 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303390 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003391 deemph_reg_value = 64;
3392 margin_reg_value = 104;
3393 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303394 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003395 deemph_reg_value = 64;
3396 margin_reg_value = 154;
3397 break;
3398 default:
3399 return 0;
3400 }
3401 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303402 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003403 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303404 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003405 deemph_reg_value = 43;
3406 margin_reg_value = 154;
3407 break;
3408 default:
3409 return 0;
3410 }
3411 break;
3412 default:
3413 return 0;
3414 }
3415
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003416 chv_set_phy_signal_level(encoder, deemph_reg_value,
3417 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003418
3419 return 0;
3420}
3421
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003422static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003423gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003424{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003425 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003426
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003427 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303428 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003429 default:
3430 signal_levels |= DP_VOLTAGE_0_4;
3431 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303432 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003433 signal_levels |= DP_VOLTAGE_0_6;
3434 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303435 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003436 signal_levels |= DP_VOLTAGE_0_8;
3437 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303438 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003439 signal_levels |= DP_VOLTAGE_1_2;
3440 break;
3441 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003442 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303443 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003444 default:
3445 signal_levels |= DP_PRE_EMPHASIS_0;
3446 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303447 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003448 signal_levels |= DP_PRE_EMPHASIS_3_5;
3449 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303450 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003451 signal_levels |= DP_PRE_EMPHASIS_6;
3452 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303453 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003454 signal_levels |= DP_PRE_EMPHASIS_9_5;
3455 break;
3456 }
3457 return signal_levels;
3458}
3459
Zhenyu Wange3421a12010-04-08 09:43:27 +08003460/* Gen6's DP voltage swing and pre-emphasis control */
3461static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003462gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003463{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003464 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3465 DP_TRAIN_PRE_EMPHASIS_MASK);
3466 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303467 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3468 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003469 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303470 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003471 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303472 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3473 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003474 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303475 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3476 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003477 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303478 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003480 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003481 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003482 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3483 "0x%x\n", signal_levels);
3484 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003485 }
3486}
3487
Keith Packard1a2eb462011-11-16 16:26:07 -08003488/* Gen7's DP voltage swing and pre-emphasis control */
3489static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003490gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003491{
3492 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3493 DP_TRAIN_PRE_EMPHASIS_MASK);
3494 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303495 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003496 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303497 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003498 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303499 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003500 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3501
Sonika Jindalbd600182014-08-08 16:23:41 +05303502 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003503 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303504 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003505 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3506
Sonika Jindalbd600182014-08-08 16:23:41 +05303507 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003508 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303509 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003510 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3511
3512 default:
3513 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3514 "0x%x\n", signal_levels);
3515 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3516 }
3517}
3518
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003519void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003520intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003521{
3522 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003523 enum port port = intel_dig_port->base.port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003524 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003525 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003526 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003527 uint8_t train_set = intel_dp->train_set[0];
3528
Rodrigo Vivid509af62017-08-29 16:22:24 -07003529 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3530 signal_levels = bxt_signal_levels(intel_dp);
3531 } else if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003532 signal_levels = ddi_signal_levels(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07003533 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003534 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003535 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003536 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003537 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003538 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003539 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003540 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003541 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003542 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003543 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3544 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003545 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003546 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3547 }
3548
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303549 if (mask)
3550 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3551
3552 DRM_DEBUG_KMS("Using vswing level %d\n",
3553 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3554 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3555 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3556 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003557
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003558 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003559
3560 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3561 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003562}
3563
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003564void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003565intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3566 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003567{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003568 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003569 struct drm_i915_private *dev_priv =
3570 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003571
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003572 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003573
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003574 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003575 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003576}
3577
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003578void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003579{
3580 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3581 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003582 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003583 enum port port = intel_dig_port->base.port;
Imre Deak3ab9c632013-05-03 12:57:41 +03003584 uint32_t val;
3585
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003586 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003587 return;
3588
3589 val = I915_READ(DP_TP_CTL(port));
3590 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3591 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3592 I915_WRITE(DP_TP_CTL(port), val);
3593
3594 /*
3595 * On PORT_A we can have only eDP in SST mode. There the only reason
3596 * we need to set idle transmission mode is to work around a HW issue
3597 * where we enable the pipe while not in idle link-training mode.
3598 * In this case there is requirement to wait for a minimum number of
3599 * idle patterns to be sent.
3600 */
3601 if (port == PORT_A)
3602 return;
3603
Chris Wilsona7670172016-06-30 15:33:10 +01003604 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3605 DP_TP_STATUS_IDLE_DONE,
3606 DP_TP_STATUS_IDLE_DONE,
3607 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003608 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3609}
3610
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003611static void
Ville Syrjäläadc10302017-10-31 22:51:14 +02003612intel_dp_link_down(struct intel_encoder *encoder,
3613 const struct intel_crtc_state *old_crtc_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003614{
Ville Syrjäläadc10302017-10-31 22:51:14 +02003615 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3616 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3617 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3618 enum port port = encoder->port;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003619 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003620
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003621 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003622 return;
3623
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003624 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003625 return;
3626
Zhao Yakui28c97732009-10-09 11:39:41 +08003627 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003628
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003629 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003630 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003631 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003632 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003633 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003634 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003635 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3636 else
3637 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003638 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003639 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003640 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003641 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003642
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003643 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3644 I915_WRITE(intel_dp->output_reg, DP);
3645 POSTING_READ(intel_dp->output_reg);
3646
3647 /*
3648 * HW workaround for IBX, we need to move the port
3649 * to transcoder A after disabling it to allow the
3650 * matching HDMI port to be enabled on transcoder A.
3651 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003652 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003653 /*
3654 * We get CPU/PCH FIFO underruns on the other pipe when
3655 * doing the workaround. Sweep them under the rug.
3656 */
3657 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3658 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3659
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003660 /* always enable with pattern 1 (as per spec) */
3661 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3662 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3663 I915_WRITE(intel_dp->output_reg, DP);
3664 POSTING_READ(intel_dp->output_reg);
3665
3666 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003667 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003668 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003669
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003670 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003671 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3672 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003673 }
3674
Keith Packardf01eca22011-09-28 16:48:10 -07003675 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003676
3677 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003678
3679 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3680 pps_lock(intel_dp);
3681 intel_dp->active_pipe = INVALID_PIPE;
3682 pps_unlock(intel_dp);
3683 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003684}
3685
Imre Deak24e807e2016-10-24 19:33:28 +03003686bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003687intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003688{
Lyude9f085eb2016-04-13 10:58:33 -04003689 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3690 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003691 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003692
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003693 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003694
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003695 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3696}
3697
3698static bool
3699intel_edp_init_dpcd(struct intel_dp *intel_dp)
3700{
3701 struct drm_i915_private *dev_priv =
3702 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3703
3704 /* this function is meant to be called only once */
3705 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3706
3707 if (!intel_dp_read_dpcd(intel_dp))
3708 return false;
3709
Jani Nikula84c36752017-05-18 14:10:23 +03003710 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3711 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003712
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003713 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3714 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3715 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3716
3717 /* Check if the panel supports PSR */
3718 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3719 intel_dp->psr_dpcd,
3720 sizeof(intel_dp->psr_dpcd));
3721 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3722 dev_priv->psr.sink_support = true;
3723 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3724 }
3725
3726 if (INTEL_GEN(dev_priv) >= 9 &&
3727 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3728 uint8_t frame_sync_cap;
3729
3730 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003731 if (drm_dp_dpcd_readb(&intel_dp->aux,
3732 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3733 &frame_sync_cap) != 1)
3734 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003735 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3736 /* PSR2 needs frame sync as well */
3737 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3738 DRM_DEBUG_KMS("PSR2 %s on sink",
3739 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303740
3741 if (dev_priv->psr.psr2_support) {
3742 dev_priv->psr.y_cord_support =
3743 intel_dp_get_y_cord_status(intel_dp);
3744 dev_priv->psr.colorimetry_support =
3745 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303746 dev_priv->psr.alpm =
3747 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303748 }
3749
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003750 }
3751
Jani Nikula0501a3b2017-10-26 17:29:31 +03003752 /*
3753 * Read the eDP display control registers.
3754 *
3755 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3756 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3757 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3758 * method). The display control registers should read zero if they're
3759 * not supported anyway.
3760 */
3761 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003762 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3763 sizeof(intel_dp->edp_dpcd))
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003764 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003765 intel_dp->edp_dpcd);
3766
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003767 /* Read the eDP 1.4+ supported link rates. */
3768 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003769 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3770 int i;
3771
3772 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3773 sink_rates, sizeof(sink_rates));
3774
3775 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3776 int val = le16_to_cpu(sink_rates[i]);
3777
3778 if (val == 0)
3779 break;
3780
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003781 /* Value read multiplied by 200kHz gives the per-lane
3782 * link rate in kHz. The source rates are, however,
3783 * stored in terms of LS_Clk kHz. The full conversion
3784 * back to symbols is
3785 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3786 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003787 intel_dp->sink_rates[i] = (val * 200) / 10;
3788 }
3789 intel_dp->num_sink_rates = i;
3790 }
3791
Jani Nikulae6ed2a12017-10-26 17:29:32 +03003792 /*
3793 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3794 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3795 */
Jani Nikula68f357c2017-03-28 17:59:05 +03003796 if (intel_dp->num_sink_rates)
3797 intel_dp->use_rate_select = true;
3798 else
3799 intel_dp_set_sink_rates(intel_dp);
3800
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003801 intel_dp_set_common_rates(intel_dp);
3802
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003803 return true;
3804}
3805
3806
3807static bool
3808intel_dp_get_dpcd(struct intel_dp *intel_dp)
3809{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003810 u8 sink_count;
3811
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003812 if (!intel_dp_read_dpcd(intel_dp))
3813 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003814
Jani Nikula68f357c2017-03-28 17:59:05 +03003815 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003816 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003817 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003818 intel_dp_set_common_rates(intel_dp);
3819 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003820
Jani Nikula27dbefb2017-04-06 16:44:17 +03003821 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303822 return false;
3823
3824 /*
3825 * Sink count can change between short pulse hpd hence
3826 * a member variable in intel_dp will track any changes
3827 * between short pulse interrupts.
3828 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003829 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303830
3831 /*
3832 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3833 * a dongle is present but no display. Unless we require to know
3834 * if a dongle is present or not, we don't need to update
3835 * downstream port information. So, an early return here saves
3836 * time from performing other operations which are not required.
3837 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003838 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303839 return false;
3840
Imre Deakc726ad02016-10-24 19:33:24 +03003841 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003842 return true; /* native DP sink */
3843
3844 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3845 return true; /* no per-port downstream info */
3846
Lyude9f085eb2016-04-13 10:58:33 -04003847 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3848 intel_dp->downstream_ports,
3849 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003850 return false; /* downstream port status fetch failed */
3851
3852 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003853}
3854
Dave Airlie0e32b392014-05-02 14:02:48 +10003855static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003856intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003857{
Jani Nikula010b9b32017-04-06 16:44:16 +03003858 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003859
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003860 if (!i915_modparams.enable_dp_mst)
Nathan Schulte7cc96132016-03-15 10:14:05 -05003861 return false;
3862
Dave Airlie0e32b392014-05-02 14:02:48 +10003863 if (!intel_dp->can_mst)
3864 return false;
3865
3866 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3867 return false;
3868
Jani Nikula010b9b32017-04-06 16:44:16 +03003869 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003870 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003871
Jani Nikula010b9b32017-04-06 16:44:16 +03003872 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003873}
3874
3875static void
3876intel_dp_configure_mst(struct intel_dp *intel_dp)
3877{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003878 if (!i915_modparams.enable_dp_mst)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003879 return;
3880
3881 if (!intel_dp->can_mst)
3882 return;
3883
3884 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3885
3886 if (intel_dp->is_mst)
3887 DRM_DEBUG_KMS("Sink is MST capable\n");
3888 else
3889 DRM_DEBUG_KMS("Sink is not MST capable\n");
3890
3891 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3892 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003893}
3894
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003895static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003896{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003897 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003898 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003899 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003900 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003901 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003902 int count = 0;
3903 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003904
3905 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003906 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003907 ret = -EIO;
3908 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003909 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003910
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003911 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003912 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003913 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003914 ret = -EIO;
3915 goto out;
3916 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003917
Rodrigo Vivic6297842015-11-05 10:50:20 -08003918 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003919 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003920
3921 if (drm_dp_dpcd_readb(&intel_dp->aux,
3922 DP_TEST_SINK_MISC, &buf) < 0) {
3923 ret = -EIO;
3924 goto out;
3925 }
3926 count = buf & DP_TEST_COUNT_MASK;
3927 } while (--attempts && count);
3928
3929 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003930 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003931 ret = -ETIMEDOUT;
3932 }
3933
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003934 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003935 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003936 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003937}
3938
3939static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3940{
3941 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003942 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003943 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3944 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003945 int ret;
3946
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003947 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3948 return -EIO;
3949
3950 if (!(buf & DP_TEST_CRC_SUPPORTED))
3951 return -ENOTTY;
3952
3953 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3954 return -EIO;
3955
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003956 if (buf & DP_TEST_SINK_START) {
3957 ret = intel_dp_sink_crc_stop(intel_dp);
3958 if (ret)
3959 return ret;
3960 }
3961
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003962 hsw_disable_ips(intel_crtc);
3963
3964 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3965 buf | DP_TEST_SINK_START) < 0) {
3966 hsw_enable_ips(intel_crtc);
3967 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003968 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003969
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003970 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003971 return 0;
3972}
3973
3974int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3975{
3976 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003977 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003978 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3979 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003980 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003981 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003982
3983 ret = intel_dp_sink_crc_start(intel_dp);
3984 if (ret)
3985 return ret;
3986
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003987 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003988 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003989
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003990 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003991 DP_TEST_SINK_MISC, &buf) < 0) {
3992 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003993 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003994 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003995 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003996
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003997 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003998
3999 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004000 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4001 ret = -ETIMEDOUT;
4002 goto stop;
4003 }
4004
4005 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4006 ret = -EIO;
4007 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004008 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004009
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004010stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004011 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004012 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004013}
4014
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004015static bool
4016intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4017{
Jani Nikula010b9b32017-04-06 16:44:16 +03004018 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4019 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004020}
4021
Dave Airlie0e32b392014-05-02 14:02:48 +10004022static bool
4023intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4024{
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004025 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4026 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4027 DP_DPRX_ESI_LEN;
Dave Airlie0e32b392014-05-02 14:02:48 +10004028}
4029
Todd Previtec5d5ab72015-04-15 08:38:38 -07004030static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004031{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004032 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004033 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004034 uint8_t test_lane_count, test_link_bw;
4035 /* (DP CTS 1.2)
4036 * 4.3.1.11
4037 */
4038 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4039 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4040 &test_lane_count);
4041
4042 if (status <= 0) {
4043 DRM_DEBUG_KMS("Lane count read failed\n");
4044 return DP_TEST_NAK;
4045 }
4046 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004047
4048 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4049 &test_link_bw);
4050 if (status <= 0) {
4051 DRM_DEBUG_KMS("Link Rate read failed\n");
4052 return DP_TEST_NAK;
4053 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004054 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004055
4056 /* Validate the requested link rate and lane count */
4057 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4058 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004059 return DP_TEST_NAK;
4060
4061 intel_dp->compliance.test_lane_count = test_lane_count;
4062 intel_dp->compliance.test_link_rate = test_link_rate;
4063
4064 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004065}
4066
4067static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4068{
Manasi Navare611032b2017-01-24 08:21:49 -08004069 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004070 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004071 __be16 h_width, v_height;
4072 int status = 0;
4073
4074 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004075 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4076 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004077 if (status <= 0) {
4078 DRM_DEBUG_KMS("Test pattern read failed\n");
4079 return DP_TEST_NAK;
4080 }
4081 if (test_pattern != DP_COLOR_RAMP)
4082 return DP_TEST_NAK;
4083
4084 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4085 &h_width, 2);
4086 if (status <= 0) {
4087 DRM_DEBUG_KMS("H Width read failed\n");
4088 return DP_TEST_NAK;
4089 }
4090
4091 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4092 &v_height, 2);
4093 if (status <= 0) {
4094 DRM_DEBUG_KMS("V Height read failed\n");
4095 return DP_TEST_NAK;
4096 }
4097
Jani Nikula010b9b32017-04-06 16:44:16 +03004098 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4099 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004100 if (status <= 0) {
4101 DRM_DEBUG_KMS("TEST MISC read failed\n");
4102 return DP_TEST_NAK;
4103 }
4104 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4105 return DP_TEST_NAK;
4106 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4107 return DP_TEST_NAK;
4108 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4109 case DP_TEST_BIT_DEPTH_6:
4110 intel_dp->compliance.test_data.bpc = 6;
4111 break;
4112 case DP_TEST_BIT_DEPTH_8:
4113 intel_dp->compliance.test_data.bpc = 8;
4114 break;
4115 default:
4116 return DP_TEST_NAK;
4117 }
4118
4119 intel_dp->compliance.test_data.video_pattern = test_pattern;
4120 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4121 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4122 /* Set test active flag here so userspace doesn't interrupt things */
4123 intel_dp->compliance.test_active = 1;
4124
4125 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004126}
4127
4128static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4129{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004130 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004131 struct intel_connector *intel_connector = intel_dp->attached_connector;
4132 struct drm_connector *connector = &intel_connector->base;
4133
4134 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004135 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004136 intel_dp->aux.i2c_defer_count > 6) {
4137 /* Check EDID read for NACKs, DEFERs and corruption
4138 * (DP CTS 1.2 Core r1.1)
4139 * 4.2.2.4 : Failed EDID read, I2C_NAK
4140 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4141 * 4.2.2.6 : EDID corruption detected
4142 * Use failsafe mode for all cases
4143 */
4144 if (intel_dp->aux.i2c_nack_count > 0 ||
4145 intel_dp->aux.i2c_defer_count > 0)
4146 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4147 intel_dp->aux.i2c_nack_count,
4148 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004149 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004150 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304151 struct edid *block = intel_connector->detect_edid;
4152
4153 /* We have to write the checksum
4154 * of the last block read
4155 */
4156 block += intel_connector->detect_edid->extensions;
4157
Jani Nikula010b9b32017-04-06 16:44:16 +03004158 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4159 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004160 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4161
4162 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004163 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004164 }
4165
4166 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004167 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004168
Todd Previtec5d5ab72015-04-15 08:38:38 -07004169 return test_result;
4170}
4171
4172static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4173{
4174 uint8_t test_result = DP_TEST_NAK;
4175 return test_result;
4176}
4177
4178static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4179{
4180 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004181 uint8_t request = 0;
4182 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004183
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004184 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004185 if (status <= 0) {
4186 DRM_DEBUG_KMS("Could not read test request from sink\n");
4187 goto update_status;
4188 }
4189
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004190 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004191 case DP_TEST_LINK_TRAINING:
4192 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004193 response = intel_dp_autotest_link_training(intel_dp);
4194 break;
4195 case DP_TEST_LINK_VIDEO_PATTERN:
4196 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004197 response = intel_dp_autotest_video_pattern(intel_dp);
4198 break;
4199 case DP_TEST_LINK_EDID_READ:
4200 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004201 response = intel_dp_autotest_edid(intel_dp);
4202 break;
4203 case DP_TEST_LINK_PHY_TEST_PATTERN:
4204 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004205 response = intel_dp_autotest_phy_pattern(intel_dp);
4206 break;
4207 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004208 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004209 break;
4210 }
4211
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004212 if (response & DP_TEST_ACK)
4213 intel_dp->compliance.test_type = request;
4214
Todd Previtec5d5ab72015-04-15 08:38:38 -07004215update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004216 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004217 if (status <= 0)
4218 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004219}
4220
Dave Airlie0e32b392014-05-02 14:02:48 +10004221static int
4222intel_dp_check_mst_status(struct intel_dp *intel_dp)
4223{
4224 bool bret;
4225
4226 if (intel_dp->is_mst) {
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004227 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
Dave Airlie0e32b392014-05-02 14:02:48 +10004228 int ret = 0;
4229 int retry;
4230 bool handled;
4231 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4232go_again:
4233 if (bret == true) {
4234
4235 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004236 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004237 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004238 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4239 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004240 intel_dp_stop_link_train(intel_dp);
4241 }
4242
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004243 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004244 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4245
4246 if (handled) {
4247 for (retry = 0; retry < 3; retry++) {
4248 int wret;
4249 wret = drm_dp_dpcd_write(&intel_dp->aux,
4250 DP_SINK_COUNT_ESI+1,
4251 &esi[1], 3);
4252 if (wret == 3) {
4253 break;
4254 }
4255 }
4256
4257 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4258 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004259 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004260 goto go_again;
4261 }
4262 } else
4263 ret = 0;
4264
4265 return ret;
4266 } else {
4267 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4268 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4269 intel_dp->is_mst = false;
4270 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4271 /* send a hotplug event */
4272 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4273 }
4274 }
4275 return -EINVAL;
4276}
4277
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304278static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004279intel_dp_retrain_link(struct intel_dp *intel_dp)
4280{
4281 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4282 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4283 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4284
4285 /* Suppress underruns caused by re-training */
4286 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4287 if (crtc->config->has_pch_encoder)
4288 intel_set_pch_fifo_underrun_reporting(dev_priv,
4289 intel_crtc_pch_transcoder(crtc), false);
4290
4291 intel_dp_start_link_train(intel_dp);
4292 intel_dp_stop_link_train(intel_dp);
4293
4294 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004295 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004296
4297 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4298 if (crtc->config->has_pch_encoder)
4299 intel_set_pch_fifo_underrun_reporting(dev_priv,
4300 intel_crtc_pch_transcoder(crtc), true);
4301}
4302
4303static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304304intel_dp_check_link_status(struct intel_dp *intel_dp)
4305{
4306 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4307 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4308 u8 link_status[DP_LINK_STATUS_SIZE];
4309
4310 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4311
4312 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4313 DRM_ERROR("Failed to get link status\n");
4314 return;
4315 }
4316
4317 if (!intel_encoder->base.crtc)
4318 return;
4319
4320 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4321 return;
4322
Manasi Navare14c562c2017-04-06 14:00:12 -07004323 /*
4324 * Validate the cached values of intel_dp->link_rate and
4325 * intel_dp->lane_count before attempting to retrain.
4326 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004327 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4328 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004329 return;
4330
Manasi Navareda15f7c2017-01-24 08:16:34 -08004331 /* Retrain if Channel EQ or CR not ok */
4332 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304333 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4334 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004335
4336 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304337 }
4338}
4339
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004340/*
4341 * According to DP spec
4342 * 5.1.2:
4343 * 1. Read DPCD
4344 * 2. Configure link according to Receiver Capabilities
4345 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4346 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304347 *
4348 * intel_dp_short_pulse - handles short pulse interrupts
4349 * when full detection is not required.
4350 * Returns %true if short pulse is handled and full detection
4351 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004352 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304353static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304354intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004355{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004356 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004357 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004358 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304359 u8 old_sink_count = intel_dp->sink_count;
4360 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004361
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304362 /*
4363 * Clearing compliance test variables to allow capturing
4364 * of values for next automated test request.
4365 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004366 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304367
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304368 /*
4369 * Now read the DPCD to see if it's actually running
4370 * If the current value of sink count doesn't match with
4371 * the value that was stored earlier or dpcd read failed
4372 * we need to do full detection
4373 */
4374 ret = intel_dp_get_dpcd(intel_dp);
4375
4376 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4377 /* No need to proceed if we are going to do full detect */
4378 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004379 }
4380
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004381 /* Try to read the source of the interrupt */
4382 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004383 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4384 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004385 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004386 drm_dp_dpcd_writeb(&intel_dp->aux,
4387 DP_DEVICE_SERVICE_IRQ_VECTOR,
4388 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004389
4390 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004391 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004392 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4393 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4394 }
4395
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304396 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4397 intel_dp_check_link_status(intel_dp);
4398 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004399 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4400 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4401 /* Send a Hotplug Uevent to userspace to start modeset */
4402 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4403 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304404
4405 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004406}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004407
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004408/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004409static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004410intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004411{
Imre Deake393d0d2017-02-22 17:10:52 +02004412 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004413 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004414 uint8_t type;
4415
Imre Deake393d0d2017-02-22 17:10:52 +02004416 if (lspcon->active)
4417 lspcon_resume(lspcon);
4418
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004419 if (!intel_dp_get_dpcd(intel_dp))
4420 return connector_status_disconnected;
4421
Jani Nikula1853a9d2017-08-18 12:30:20 +03004422 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304423 return connector_status_connected;
4424
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004425 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004426 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004427 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004428
4429 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004430 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4431 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004432
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304433 return intel_dp->sink_count ?
4434 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004435 }
4436
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004437 if (intel_dp_can_mst(intel_dp))
4438 return connector_status_connected;
4439
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004440 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004441 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004442 return connector_status_connected;
4443
4444 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004445 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4446 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4447 if (type == DP_DS_PORT_TYPE_VGA ||
4448 type == DP_DS_PORT_TYPE_NON_EDID)
4449 return connector_status_unknown;
4450 } else {
4451 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4452 DP_DWN_STRM_PORT_TYPE_MASK;
4453 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4454 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4455 return connector_status_unknown;
4456 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004457
4458 /* Anything else is out of spec, warn and ignore */
4459 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004460 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004461}
4462
4463static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004464edp_detect(struct intel_dp *intel_dp)
4465{
4466 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004467 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004468 enum drm_connector_status status;
4469
Mika Kahola1650be72016-12-13 10:02:47 +02004470 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004471 if (status == connector_status_unknown)
4472 status = connector_status_connected;
4473
4474 return status;
4475}
4476
Jani Nikulab93433c2015-08-20 10:47:36 +03004477static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4478 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004479{
Jani Nikulab93433c2015-08-20 10:47:36 +03004480 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004481
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004482 switch (port->base.port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004483 case PORT_B:
4484 bit = SDE_PORTB_HOTPLUG;
4485 break;
4486 case PORT_C:
4487 bit = SDE_PORTC_HOTPLUG;
4488 break;
4489 case PORT_D:
4490 bit = SDE_PORTD_HOTPLUG;
4491 break;
4492 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004493 MISSING_CASE(port->base.port);
Jani Nikula0df53b72015-08-20 10:47:40 +03004494 return false;
4495 }
4496
4497 return I915_READ(SDEISR) & bit;
4498}
4499
4500static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4501 struct intel_digital_port *port)
4502{
4503 u32 bit;
4504
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004505 switch (port->base.port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004506 case PORT_B:
4507 bit = SDE_PORTB_HOTPLUG_CPT;
4508 break;
4509 case PORT_C:
4510 bit = SDE_PORTC_HOTPLUG_CPT;
4511 break;
4512 case PORT_D:
4513 bit = SDE_PORTD_HOTPLUG_CPT;
4514 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004515 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004516 MISSING_CASE(port->base.port);
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004517 return false;
4518 }
4519
4520 return I915_READ(SDEISR) & bit;
4521}
4522
4523static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4524 struct intel_digital_port *port)
4525{
4526 u32 bit;
4527
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004528 switch (port->base.port) {
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004529 case PORT_A:
4530 bit = SDE_PORTA_HOTPLUG_SPT;
4531 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004532 case PORT_E:
4533 bit = SDE_PORTE_HOTPLUG_SPT;
4534 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004535 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004536 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004537 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004538
Jani Nikulab93433c2015-08-20 10:47:36 +03004539 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004540}
4541
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004542static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004543 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004544{
Jani Nikula9642c812015-08-20 10:47:41 +03004545 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004546
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004547 switch (port->base.port) {
Jani Nikula9642c812015-08-20 10:47:41 +03004548 case PORT_B:
4549 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4550 break;
4551 case PORT_C:
4552 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4553 break;
4554 case PORT_D:
4555 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4556 break;
4557 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004558 MISSING_CASE(port->base.port);
Jani Nikula9642c812015-08-20 10:47:41 +03004559 return false;
4560 }
4561
4562 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4563}
4564
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004565static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4566 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004567{
4568 u32 bit;
4569
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004570 switch (port->base.port) {
Jani Nikula9642c812015-08-20 10:47:41 +03004571 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004572 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004573 break;
4574 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004575 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004576 break;
4577 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004578 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004579 break;
4580 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004581 MISSING_CASE(port->base.port);
Jani Nikula9642c812015-08-20 10:47:41 +03004582 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004583 }
4584
Jani Nikula1d245982015-08-20 10:47:37 +03004585 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004586}
4587
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004588static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4589 struct intel_digital_port *port)
4590{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004591 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004592 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4593 else
4594 return ibx_digital_port_connected(dev_priv, port);
4595}
4596
4597static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4598 struct intel_digital_port *port)
4599{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004600 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004601 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4602 else
4603 return cpt_digital_port_connected(dev_priv, port);
4604}
4605
4606static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4607 struct intel_digital_port *port)
4608{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004609 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004610 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4611 else
4612 return cpt_digital_port_connected(dev_priv, port);
4613}
4614
4615static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4616 struct intel_digital_port *port)
4617{
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02004618 if (port->base.port == PORT_A)
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004619 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4620 else
4621 return cpt_digital_port_connected(dev_priv, port);
4622}
4623
Jani Nikulae464bfd2015-08-20 10:47:42 +03004624static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304625 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004626{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304627 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4628 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004629 u32 bit;
4630
Rodrigo Vivi256cfdde2017-08-11 11:26:49 -07004631 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304632 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004633 case PORT_A:
4634 bit = BXT_DE_PORT_HP_DDIA;
4635 break;
4636 case PORT_B:
4637 bit = BXT_DE_PORT_HP_DDIB;
4638 break;
4639 case PORT_C:
4640 bit = BXT_DE_PORT_HP_DDIC;
4641 break;
4642 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304643 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004644 return false;
4645 }
4646
4647 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4648}
4649
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004650/*
4651 * intel_digital_port_connected - is the specified port connected?
4652 * @dev_priv: i915 private structure
4653 * @port: the port to test
4654 *
4655 * Return %true if @port is connected, %false otherwise.
4656 */
Imre Deak390b4e02017-01-27 11:39:19 +02004657bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4658 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004659{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004660 if (HAS_GMCH_DISPLAY(dev_priv)) {
4661 if (IS_GM45(dev_priv))
4662 return gm45_digital_port_connected(dev_priv, port);
4663 else
4664 return g4x_digital_port_connected(dev_priv, port);
4665 }
4666
4667 if (IS_GEN5(dev_priv))
4668 return ilk_digital_port_connected(dev_priv, port);
4669 else if (IS_GEN6(dev_priv))
4670 return snb_digital_port_connected(dev_priv, port);
4671 else if (IS_GEN7(dev_priv))
4672 return ivb_digital_port_connected(dev_priv, port);
4673 else if (IS_GEN8(dev_priv))
4674 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004675 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004676 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004677 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004678 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004679}
4680
Keith Packard8c241fe2011-09-28 16:38:44 -07004681static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004682intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004683{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004684 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004685
Jani Nikula9cd300e2012-10-19 14:51:52 +03004686 /* use cached edid if we have one */
4687 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004688 /* invalid edid */
4689 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004690 return NULL;
4691
Jani Nikula55e9ede2013-10-01 10:38:54 +03004692 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004693 } else
4694 return drm_get_edid(&intel_connector->base,
4695 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004696}
4697
Chris Wilsonbeb60602014-09-02 20:04:00 +01004698static void
4699intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004700{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004701 struct intel_connector *intel_connector = intel_dp->attached_connector;
4702 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004703
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304704 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004705 edid = intel_dp_get_edid(intel_dp);
4706 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004707
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004708 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004709}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004710
Chris Wilsonbeb60602014-09-02 20:04:00 +01004711static void
4712intel_dp_unset_edid(struct intel_dp *intel_dp)
4713{
4714 struct intel_connector *intel_connector = intel_dp->attached_connector;
4715
4716 kfree(intel_connector->detect_edid);
4717 intel_connector->detect_edid = NULL;
4718
4719 intel_dp->has_audio = false;
4720}
4721
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004722static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304723intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004724{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304725 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004726 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004727 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004728 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004729 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004730
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004731 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4732
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004733 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004734
Chris Wilsond410b562014-09-02 20:03:59 +01004735 /* Can't disconnect eDP, but you can close the lid... */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004736 if (intel_dp_is_edp(intel_dp))
Chris Wilsond410b562014-09-02 20:03:59 +01004737 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004738 else if (intel_digital_port_connected(to_i915(dev),
4739 dp_to_dig_port(intel_dp)))
4740 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004741 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004742 status = connector_status_disconnected;
4743
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004744 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004745 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304746
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004747 if (intel_dp->is_mst) {
4748 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4749 intel_dp->is_mst,
4750 intel_dp->mst_mgr.mst_state);
4751 intel_dp->is_mst = false;
4752 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4753 intel_dp->is_mst);
4754 }
4755
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004756 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304757 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004758
Manasi Navared7e8ef02017-02-07 16:54:11 -08004759 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004760 /* Initial max link lane count */
4761 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004762
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004763 /* Initial max link rate */
4764 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004765
4766 intel_dp->reset_link_params = false;
4767 }
Manasi Navaref4829842016-12-05 16:27:36 -08004768
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004769 intel_dp_print_rates(intel_dp);
4770
Jani Nikula84c36752017-05-18 14:10:23 +03004771 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4772 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004773
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004774 intel_dp_configure_mst(intel_dp);
4775
4776 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304777 /*
4778 * If we are in MST mode then this connector
4779 * won't appear connected or have anything
4780 * with EDID on it
4781 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004782 status = connector_status_disconnected;
4783 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004784 } else {
4785 /*
4786 * If display is now connected check links status,
4787 * there has been known issues of link loss triggerring
4788 * long pulse.
4789 *
4790 * Some sinks (eg. ASUS PB287Q) seem to perform some
4791 * weird HPD ping pong during modesets. So we can apparently
4792 * end up with HPD going low during a modeset, and then
4793 * going back up soon after. And once that happens we must
4794 * retrain the link to get a picture. That's in case no
4795 * userspace component reacted to intermittent HPD dip.
4796 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304797 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004798 }
4799
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304800 /*
4801 * Clearing NACK and defer counts to get their exact values
4802 * while reading EDID which are required by Compliance tests
4803 * 4.2.2.4 and 4.2.2.5
4804 */
4805 intel_dp->aux.i2c_nack_count = 0;
4806 intel_dp->aux.i2c_defer_count = 0;
4807
Chris Wilsonbeb60602014-09-02 20:04:00 +01004808 intel_dp_set_edid(intel_dp);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004809 if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004810 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304811 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004812
Todd Previte09b1eb12015-04-20 15:27:34 -07004813 /* Try to read the source of the interrupt */
4814 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004815 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4816 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004817 /* Clear interrupt source */
4818 drm_dp_dpcd_writeb(&intel_dp->aux,
4819 DP_DEVICE_SERVICE_IRQ_VECTOR,
4820 sink_irq_vector);
4821
4822 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4823 intel_dp_handle_test_request(intel_dp);
4824 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4825 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4826 }
4827
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004828out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004829 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304830 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304831
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004832 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004833 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304834}
4835
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004836static int
4837intel_dp_detect(struct drm_connector *connector,
4838 struct drm_modeset_acquire_ctx *ctx,
4839 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304840{
4841 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004842 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304843
4844 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4845 connector->base.id, connector->name);
4846
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304847 /* If full detect is not performed yet, do a full detect */
4848 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004849 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304850
4851 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304852
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004853 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004854}
4855
Chris Wilsonbeb60602014-09-02 20:04:00 +01004856static void
4857intel_dp_force(struct drm_connector *connector)
4858{
4859 struct intel_dp *intel_dp = intel_attached_dp(connector);
4860 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004861 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004862
4863 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4864 connector->base.id, connector->name);
4865 intel_dp_unset_edid(intel_dp);
4866
4867 if (connector->status != connector_status_connected)
4868 return;
4869
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004870 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004871
4872 intel_dp_set_edid(intel_dp);
4873
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004874 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004875}
4876
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004877static int intel_dp_get_modes(struct drm_connector *connector)
4878{
Jani Nikuladd06f902012-10-19 14:51:50 +03004879 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004880 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004881
Chris Wilsonbeb60602014-09-02 20:04:00 +01004882 edid = intel_connector->detect_edid;
4883 if (edid) {
4884 int ret = intel_connector_update_modes(connector, edid);
4885 if (ret)
4886 return ret;
4887 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004888
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004889 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004890 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004891 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004892 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004893
4894 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004895 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004896 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004897 drm_mode_probed_add(connector, mode);
4898 return 1;
4899 }
4900 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004901
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004902 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004903}
4904
Chris Wilsonf6849602010-09-19 09:29:33 +01004905static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004906intel_dp_connector_register(struct drm_connector *connector)
4907{
4908 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004909 int ret;
4910
4911 ret = intel_connector_register(connector);
4912 if (ret)
4913 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004914
4915 i915_debugfs_connector_add(connector);
4916
4917 DRM_DEBUG_KMS("registering %s bus for %s\n",
4918 intel_dp->aux.name, connector->kdev->kobj.name);
4919
4920 intel_dp->aux.dev = connector->kdev;
4921 return drm_dp_aux_register(&intel_dp->aux);
4922}
4923
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004924static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004925intel_dp_connector_unregister(struct drm_connector *connector)
4926{
4927 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4928 intel_connector_unregister(connector);
4929}
4930
4931static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004932intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004933{
Jani Nikula1d508702012-10-19 14:51:49 +03004934 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004935
Chris Wilson10e972d2014-09-04 21:43:45 +01004936 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004937
Jani Nikula9cd300e2012-10-19 14:51:52 +03004938 if (!IS_ERR_OR_NULL(intel_connector->edid))
4939 kfree(intel_connector->edid);
4940
Jani Nikula1853a9d2017-08-18 12:30:20 +03004941 /*
4942 * Can't call intel_dp_is_edp() since the encoder may have been
4943 * destroyed already.
4944 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004945 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004946 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004947
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004948 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004949 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004950}
4951
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004952void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004953{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004954 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4955 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004956
Dave Airlie0e32b392014-05-02 14:02:48 +10004957 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004958 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004959 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004960 /*
4961 * vdd might still be enabled do to the delayed vdd off.
4962 * Make sure vdd is actually turned off here.
4963 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004964 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004965 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004966 pps_unlock(intel_dp);
4967
Clint Taylor01527b32014-07-07 13:01:46 -07004968 if (intel_dp->edp_notifier.notifier_call) {
4969 unregister_reboot_notifier(&intel_dp->edp_notifier);
4970 intel_dp->edp_notifier.notifier_call = NULL;
4971 }
Keith Packardbd943152011-09-18 23:09:52 -07004972 }
Chris Wilson99681882016-06-20 09:29:17 +01004973
4974 intel_dp_aux_fini(intel_dp);
4975
Imre Deakc8bd0e42014-12-12 17:57:38 +02004976 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004977 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004978}
4979
Imre Deakbf93ba62016-04-18 10:04:21 +03004980void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004981{
4982 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4983
Jani Nikula1853a9d2017-08-18 12:30:20 +03004984 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03004985 return;
4986
Ville Syrjälä951468f2014-09-04 14:55:31 +03004987 /*
4988 * vdd might still be enabled do to the delayed vdd off.
4989 * Make sure vdd is actually turned off here.
4990 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004991 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004992 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004993 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004994 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004995}
4996
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004997static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4998{
4999 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5000 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005001 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005002
5003 lockdep_assert_held(&dev_priv->pps_mutex);
5004
5005 if (!edp_have_panel_vdd(intel_dp))
5006 return;
5007
5008 /*
5009 * The VDD bit needs a power domain reference, so if the bit is
5010 * already enabled when we boot or resume, grab this reference and
5011 * schedule a vdd off, so we don't hold on to the reference
5012 * indefinitely.
5013 */
5014 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005015 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005016
5017 edp_panel_vdd_schedule_off(intel_dp);
5018}
5019
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005020static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5021{
5022 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5023
5024 if ((intel_dp->DP & DP_PORT_EN) == 0)
5025 return INVALID_PIPE;
5026
5027 if (IS_CHERRYVIEW(dev_priv))
5028 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5029 else
5030 return PORT_TO_PIPE(intel_dp->DP);
5031}
5032
Imre Deakbf93ba62016-04-18 10:04:21 +03005033void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005034{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005035 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005036 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5037 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005038
5039 if (!HAS_DDI(dev_priv))
5040 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005041
Imre Deakdd75f6d2016-11-21 21:15:05 +02005042 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305043 lspcon_resume(lspcon);
5044
Manasi Navared7e8ef02017-02-07 16:54:11 -08005045 intel_dp->reset_link_params = true;
5046
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005047 pps_lock(intel_dp);
5048
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005049 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5050 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5051
Jani Nikula1853a9d2017-08-18 12:30:20 +03005052 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005053 /* Reinit the power sequencer, in case BIOS did something with it. */
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005054 intel_dp_pps_init(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005055 intel_edp_panel_vdd_sanitize(intel_dp);
5056 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005057
5058 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005059}
5060
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005061static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005062 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005063 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005064 .atomic_get_property = intel_digital_connector_atomic_get_property,
5065 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005066 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005067 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005068 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005069 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005070 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005071};
5072
5073static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005074 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005075 .get_modes = intel_dp_get_modes,
5076 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005077 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005078};
5079
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005080static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005081 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005082 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005083};
5084
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005085enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005086intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5087{
5088 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005089 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005090 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005091 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005092
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005093 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5094 /*
5095 * vdd off can generate a long pulse on eDP which
5096 * would require vdd on to handle it, and thus we
5097 * would end up in an endless cycle of
5098 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5099 */
5100 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005101 port_name(intel_dig_port->base.port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005102 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005103 }
5104
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005105 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005106 port_name(intel_dig_port->base.port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005107 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005108
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005109 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005110 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005111 intel_dp->detect_done = false;
5112 return IRQ_NONE;
5113 }
5114
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005115 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005116
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005117 if (intel_dp->is_mst) {
5118 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5119 /*
5120 * If we were in MST mode, and device is not
5121 * there, get out of MST mode
5122 */
5123 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5124 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5125 intel_dp->is_mst = false;
5126 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5127 intel_dp->is_mst);
5128 intel_dp->detect_done = false;
5129 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005130 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005131 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005132
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005133 if (!intel_dp->is_mst) {
5134 if (!intel_dp_short_pulse(intel_dp)) {
5135 intel_dp->detect_done = false;
5136 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305137 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005138 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005139
5140 ret = IRQ_HANDLED;
5141
Imre Deak1c767b32014-08-18 14:42:42 +03005142put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005143 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005144
5145 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005146}
5147
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005148/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005149bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005150{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005151 /*
5152 * eDP not supported on g4x. so bail out early just
5153 * for a bit extra safety in case the VBT is bonkers.
5154 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005155 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005156 return false;
5157
Imre Deaka98d9c12016-12-21 12:17:24 +02005158 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005159 return true;
5160
Jani Nikula951d9ef2016-03-16 12:43:31 +02005161 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005162}
5163
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005164static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005165intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5166{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005167 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5168
Chris Wilson3f43c482011-05-12 22:17:24 +01005169 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005170 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005171
Jani Nikula1853a9d2017-08-18 12:30:20 +03005172 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005173 u32 allowed_scalers;
5174
5175 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5176 if (!HAS_GMCH_DISPLAY(dev_priv))
5177 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5178
5179 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5180
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005181 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005182
Yuly Novikov53b41832012-10-26 12:04:00 +03005183 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005184}
5185
Imre Deakdada1a92014-01-29 13:25:41 +02005186static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5187{
Abhay Kumard28d4732016-01-22 17:39:04 -08005188 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005189 intel_dp->last_power_on = jiffies;
5190 intel_dp->last_backlight_off = jiffies;
5191}
5192
Daniel Vetter67a54562012-10-20 20:57:45 +02005193static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005194intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005195{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005196 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305197 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005198 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005199
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005200 intel_pps_get_registers(intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005201
5202 /* Workaround: Need to write PP_CONTROL with the unlock key as
5203 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305204 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005205
Imre Deak8e8232d2016-06-16 16:37:21 +03005206 pp_on = I915_READ(regs.pp_on);
5207 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005208 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005209 I915_WRITE(regs.pp_ctrl, pp_ctl);
5210 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305211 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005212
5213 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005214 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5215 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005216
Imre Deak54648612016-06-16 16:37:22 +03005217 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5218 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005219
Imre Deak54648612016-06-16 16:37:22 +03005220 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5221 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005222
Imre Deak54648612016-06-16 16:37:22 +03005223 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5224 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005225
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005226 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005227 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5228 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305229 } else {
Imre Deak54648612016-06-16 16:37:22 +03005230 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005231 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305232 }
Imre Deak54648612016-06-16 16:37:22 +03005233}
5234
5235static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005236intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5237{
5238 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5239 state_name,
5240 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5241}
5242
5243static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005244intel_pps_verify_state(struct intel_dp *intel_dp)
Imre Deakde9c1b62016-06-16 20:01:46 +03005245{
5246 struct edp_power_seq hw;
5247 struct edp_power_seq *sw = &intel_dp->pps_delays;
5248
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005249 intel_pps_readout_hw_state(intel_dp, &hw);
Imre Deakde9c1b62016-06-16 20:01:46 +03005250
5251 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5252 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5253 DRM_ERROR("PPS state mismatch\n");
5254 intel_pps_dump_state("sw", sw);
5255 intel_pps_dump_state("hw", &hw);
5256 }
5257}
5258
5259static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005260intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
Imre Deak54648612016-06-16 16:37:22 +03005261{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005262 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deak54648612016-06-16 16:37:22 +03005263 struct edp_power_seq cur, vbt, spec,
5264 *final = &intel_dp->pps_delays;
5265
5266 lockdep_assert_held(&dev_priv->pps_mutex);
5267
5268 /* already initialized? */
5269 if (final->t11_t12 != 0)
5270 return;
5271
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005272 intel_pps_readout_hw_state(intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005273
Imre Deakde9c1b62016-06-16 20:01:46 +03005274 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005275
Jani Nikula6aa23e62016-03-24 17:50:20 +02005276 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005277 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5278 * of 500ms appears to be too short. Ocassionally the panel
5279 * just fails to power back on. Increasing the delay to 800ms
5280 * seems sufficient to avoid this problem.
5281 */
5282 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
Manasi Navarec02b8fb2017-10-03 16:37:25 -07005283 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
Manasi Navarec99a2592017-06-30 09:33:48 -07005284 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5285 vbt.t11_t12);
5286 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005287 /* T11_T12 delay is special and actually in units of 100ms, but zero
5288 * based in the hw (so we need to add 100 ms). But the sw vbt
5289 * table multiplies it with 1000 to make it in units of 100usec,
5290 * too. */
5291 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005292
5293 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5294 * our hw here, which are all in 100usec. */
5295 spec.t1_t3 = 210 * 10;
5296 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5297 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5298 spec.t10 = 500 * 10;
5299 /* This one is special and actually in units of 100ms, but zero
5300 * based in the hw (so we need to add 100 ms). But the sw vbt
5301 * table multiplies it with 1000 to make it in units of 100usec,
5302 * too. */
5303 spec.t11_t12 = (510 + 100) * 10;
5304
Imre Deakde9c1b62016-06-16 20:01:46 +03005305 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005306
5307 /* Use the max of the register settings and vbt. If both are
5308 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005309#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005310 spec.field : \
5311 max(cur.field, vbt.field))
5312 assign_final(t1_t3);
5313 assign_final(t8);
5314 assign_final(t9);
5315 assign_final(t10);
5316 assign_final(t11_t12);
5317#undef assign_final
5318
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005319#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005320 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5321 intel_dp->backlight_on_delay = get_delay(t8);
5322 intel_dp->backlight_off_delay = get_delay(t9);
5323 intel_dp->panel_power_down_delay = get_delay(t10);
5324 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5325#undef get_delay
5326
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005327 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5328 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5329 intel_dp->panel_power_cycle_delay);
5330
5331 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5332 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005333
5334 /*
5335 * We override the HW backlight delays to 1 because we do manual waits
5336 * on them. For T8, even BSpec recommends doing it. For T9, if we
5337 * don't do this, we'll end up waiting for the backlight off delay
5338 * twice: once when we do the manual sleep, and once when we disable
5339 * the panel and wait for the PP_STATUS bit to become zero.
5340 */
5341 final->t8 = 1;
5342 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005343}
5344
5345static void
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005346intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005347 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005348{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005349 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Jesse Barnes453c5422013-03-28 09:55:41 -07005350 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005351 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005352 struct pps_registers regs;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005353 enum port port = dp_to_dig_port(intel_dp)->base.port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005354 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005355
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005356 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005357
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005358 intel_pps_get_registers(intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005359
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005360 /*
5361 * On some VLV machines the BIOS can leave the VDD
5362 * enabled even on power seqeuencers which aren't
5363 * hooked up to any port. This would mess up the
5364 * power domain tracking the first time we pick
5365 * one of these power sequencers for use since
5366 * edp_panel_vdd_on() would notice that the VDD was
5367 * already on and therefore wouldn't grab the power
5368 * domain reference. Disable VDD first to avoid this.
5369 * This also avoids spuriously turning the VDD on as
5370 * soon as the new power seqeuencer gets initialized.
5371 */
5372 if (force_disable_vdd) {
5373 u32 pp = ironlake_get_pp_control(intel_dp);
5374
5375 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5376
5377 if (pp & EDP_FORCE_VDD)
5378 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5379
5380 pp &= ~EDP_FORCE_VDD;
5381
5382 I915_WRITE(regs.pp_ctrl, pp);
5383 }
5384
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005385 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005386 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5387 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005388 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005389 /* Compute the divisor for the pp clock, simply match the Bspec
5390 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005391 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005392 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305393 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005394 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305395 << BXT_POWER_CYCLE_DELAY_SHIFT);
5396 } else {
5397 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5398 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5399 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5400 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005401
5402 /* Haswell doesn't have any port selection bits for the panel
5403 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005404 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005405 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005406 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005407 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005408 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005409 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005410 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005411 }
5412
Jesse Barnes453c5422013-03-28 09:55:41 -07005413 pp_on |= port_sel;
5414
Imre Deak8e8232d2016-06-16 16:37:21 +03005415 I915_WRITE(regs.pp_on, pp_on);
5416 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005417 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005418 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305419 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005420 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005421
Daniel Vetter67a54562012-10-20 20:57:45 +02005422 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 +03005423 I915_READ(regs.pp_on),
5424 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005425 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005426 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5427 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005428}
5429
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005430static void intel_dp_pps_init(struct intel_dp *intel_dp)
Imre Deak335f7522016-08-10 14:07:32 +03005431{
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005432 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005433
5434 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005435 vlv_initial_power_sequencer_setup(intel_dp);
5436 } else {
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005437 intel_dp_init_panel_power_sequencer(intel_dp);
5438 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005439 }
5440}
5441
Vandana Kannanb33a2812015-02-13 15:33:03 +05305442/**
5443 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005444 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005445 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305446 * @refresh_rate: RR to be programmed
5447 *
5448 * This function gets called when refresh rate (RR) has to be changed from
5449 * one frequency to another. Switches can be between high and low RR
5450 * supported by the panel or to any other RR based on media playback (in
5451 * this case, RR value needs to be passed from user space).
5452 *
5453 * The caller of this function needs to take a lock on dev_priv->drrs.
5454 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005455static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005456 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005457 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305459 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305460 struct intel_digital_port *dig_port = NULL;
5461 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005462 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305463 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305464
5465 if (refresh_rate <= 0) {
5466 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5467 return;
5468 }
5469
Vandana Kannan96178ee2015-01-10 02:25:56 +05305470 if (intel_dp == NULL) {
5471 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305472 return;
5473 }
5474
Vandana Kannan96178ee2015-01-10 02:25:56 +05305475 dig_port = dp_to_dig_port(intel_dp);
5476 encoder = &dig_port->base;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305477
5478 if (!intel_crtc) {
5479 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5480 return;
5481 }
5482
Vandana Kannan96178ee2015-01-10 02:25:56 +05305483 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305484 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5485 return;
5486 }
5487
Vandana Kannan96178ee2015-01-10 02:25:56 +05305488 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5489 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305490 index = DRRS_LOW_RR;
5491
Vandana Kannan96178ee2015-01-10 02:25:56 +05305492 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305493 DRM_DEBUG_KMS(
5494 "DRRS requested for previously set RR...ignoring\n");
5495 return;
5496 }
5497
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005498 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305499 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5500 return;
5501 }
5502
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005503 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305504 switch (index) {
5505 case DRRS_HIGH_RR:
5506 intel_dp_set_m_n(intel_crtc, M1_N1);
5507 break;
5508 case DRRS_LOW_RR:
5509 intel_dp_set_m_n(intel_crtc, M2_N2);
5510 break;
5511 case DRRS_MAX_RR:
5512 default:
5513 DRM_ERROR("Unsupported refreshrate type\n");
5514 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005515 } else if (INTEL_GEN(dev_priv) > 6) {
5516 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005517 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305518
Ville Syrjälä649636e2015-09-22 19:50:01 +03005519 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305520 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005521 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305522 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5523 else
5524 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305525 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005526 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305527 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5528 else
5529 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305530 }
5531 I915_WRITE(reg, val);
5532 }
5533
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305534 dev_priv->drrs.refresh_rate_type = index;
5535
5536 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5537}
5538
Vandana Kannanb33a2812015-02-13 15:33:03 +05305539/**
5540 * intel_edp_drrs_enable - init drrs struct if supported
5541 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005542 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305543 *
5544 * Initializes frontbuffer_bits and drrs.dp
5545 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005546void intel_edp_drrs_enable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005547 const struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305548{
5549 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005550 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305551
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005552 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305553 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5554 return;
5555 }
5556
Radhakrishna Sripadada83ef82017-09-14 11:16:41 -07005557 if (dev_priv->psr.enabled) {
5558 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5559 return;
5560 }
5561
Vandana Kannanc3955782015-01-22 15:17:40 +05305562 mutex_lock(&dev_priv->drrs.mutex);
5563 if (WARN_ON(dev_priv->drrs.dp)) {
5564 DRM_ERROR("DRRS already enabled\n");
5565 goto unlock;
5566 }
5567
5568 dev_priv->drrs.busy_frontbuffer_bits = 0;
5569
5570 dev_priv->drrs.dp = intel_dp;
5571
5572unlock:
5573 mutex_unlock(&dev_priv->drrs.mutex);
5574}
5575
Vandana Kannanb33a2812015-02-13 15:33:03 +05305576/**
5577 * intel_edp_drrs_disable - Disable DRRS
5578 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005579 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305580 *
5581 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005582void intel_edp_drrs_disable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005583 const struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305584{
5585 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005586 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305587
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005588 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305589 return;
5590
5591 mutex_lock(&dev_priv->drrs.mutex);
5592 if (!dev_priv->drrs.dp) {
5593 mutex_unlock(&dev_priv->drrs.mutex);
5594 return;
5595 }
5596
5597 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005598 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5599 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305600
5601 dev_priv->drrs.dp = NULL;
5602 mutex_unlock(&dev_priv->drrs.mutex);
5603
5604 cancel_delayed_work_sync(&dev_priv->drrs.work);
5605}
5606
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305607static void intel_edp_drrs_downclock_work(struct work_struct *work)
5608{
5609 struct drm_i915_private *dev_priv =
5610 container_of(work, typeof(*dev_priv), drrs.work.work);
5611 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305612
Vandana Kannan96178ee2015-01-10 02:25:56 +05305613 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305614
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305615 intel_dp = dev_priv->drrs.dp;
5616
5617 if (!intel_dp)
5618 goto unlock;
5619
5620 /*
5621 * The delayed work can race with an invalidate hence we need to
5622 * recheck.
5623 */
5624
5625 if (dev_priv->drrs.busy_frontbuffer_bits)
5626 goto unlock;
5627
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005628 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5629 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5630
5631 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5632 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5633 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305634
5635unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305636 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305637}
5638
Vandana Kannanb33a2812015-02-13 15:33:03 +05305639/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305640 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005641 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305642 * @frontbuffer_bits: frontbuffer plane tracking bits
5643 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305644 * This function gets called everytime rendering on the given planes start.
5645 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305646 *
5647 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5648 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005649void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5650 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305651{
Vandana Kannana93fad02015-01-10 02:25:59 +05305652 struct drm_crtc *crtc;
5653 enum pipe pipe;
5654
Daniel Vetter9da7d692015-04-09 16:44:15 +02005655 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305656 return;
5657
Daniel Vetter88f933a2015-04-09 16:44:16 +02005658 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305659
Vandana Kannana93fad02015-01-10 02:25:59 +05305660 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005661 if (!dev_priv->drrs.dp) {
5662 mutex_unlock(&dev_priv->drrs.mutex);
5663 return;
5664 }
5665
Vandana Kannana93fad02015-01-10 02:25:59 +05305666 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5667 pipe = to_intel_crtc(crtc)->pipe;
5668
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005669 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5670 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5671
Ramalingam C0ddfd202015-06-15 20:50:05 +05305672 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005673 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005674 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5675 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305676
Vandana Kannana93fad02015-01-10 02:25:59 +05305677 mutex_unlock(&dev_priv->drrs.mutex);
5678}
5679
Vandana Kannanb33a2812015-02-13 15:33:03 +05305680/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305681 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005682 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305683 * @frontbuffer_bits: frontbuffer plane tracking bits
5684 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305685 * This function gets called every time rendering on the given planes has
5686 * completed or flip on a crtc is completed. So DRRS should be upclocked
5687 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5688 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305689 *
5690 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5691 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005692void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5693 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305694{
Vandana Kannana93fad02015-01-10 02:25:59 +05305695 struct drm_crtc *crtc;
5696 enum pipe pipe;
5697
Daniel Vetter9da7d692015-04-09 16:44:15 +02005698 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305699 return;
5700
Daniel Vetter88f933a2015-04-09 16:44:16 +02005701 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305702
Vandana Kannana93fad02015-01-10 02:25:59 +05305703 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005704 if (!dev_priv->drrs.dp) {
5705 mutex_unlock(&dev_priv->drrs.mutex);
5706 return;
5707 }
5708
Vandana Kannana93fad02015-01-10 02:25:59 +05305709 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5710 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005711
5712 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305713 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5714
Ramalingam C0ddfd202015-06-15 20:50:05 +05305715 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005716 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005717 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5718 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305719
5720 /*
5721 * flush also means no more activity hence schedule downclock, if all
5722 * other fbs are quiescent too
5723 */
5724 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305725 schedule_delayed_work(&dev_priv->drrs.work,
5726 msecs_to_jiffies(1000));
5727 mutex_unlock(&dev_priv->drrs.mutex);
5728}
5729
Vandana Kannanb33a2812015-02-13 15:33:03 +05305730/**
5731 * DOC: Display Refresh Rate Switching (DRRS)
5732 *
5733 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5734 * which enables swtching between low and high refresh rates,
5735 * dynamically, based on the usage scenario. This feature is applicable
5736 * for internal panels.
5737 *
5738 * Indication that the panel supports DRRS is given by the panel EDID, which
5739 * would list multiple refresh rates for one resolution.
5740 *
5741 * DRRS is of 2 types - static and seamless.
5742 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5743 * (may appear as a blink on screen) and is used in dock-undock scenario.
5744 * Seamless DRRS involves changing RR without any visual effect to the user
5745 * and can be used during normal system usage. This is done by programming
5746 * certain registers.
5747 *
5748 * Support for static/seamless DRRS may be indicated in the VBT based on
5749 * inputs from the panel spec.
5750 *
5751 * DRRS saves power by switching to low RR based on usage scenarios.
5752 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005753 * The implementation is based on frontbuffer tracking implementation. When
5754 * there is a disturbance on the screen triggered by user activity or a periodic
5755 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5756 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5757 * made.
5758 *
5759 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5760 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305761 *
5762 * DRRS can be further extended to support other internal panels and also
5763 * the scenario of video playback wherein RR is set based on the rate
5764 * requested by userspace.
5765 */
5766
5767/**
5768 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5769 * @intel_connector: eDP connector
5770 * @fixed_mode: preferred mode of panel
5771 *
5772 * This function is called only once at driver load to initialize basic
5773 * DRRS stuff.
5774 *
5775 * Returns:
5776 * Downclock mode if panel supports it, else return NULL.
5777 * DRRS support is determined by the presence of downclock mode (apart
5778 * from VBT setting).
5779 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305780static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305781intel_dp_drrs_init(struct intel_connector *intel_connector,
5782 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305783{
5784 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305785 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005786 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305787 struct drm_display_mode *downclock_mode = NULL;
5788
Daniel Vetter9da7d692015-04-09 16:44:15 +02005789 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5790 mutex_init(&dev_priv->drrs.mutex);
5791
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005792 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305793 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5794 return NULL;
5795 }
5796
5797 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005798 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305799 return NULL;
5800 }
5801
5802 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005803 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305804
5805 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305806 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305807 return NULL;
5808 }
5809
Vandana Kannan96178ee2015-01-10 02:25:56 +05305810 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305811
Vandana Kannan96178ee2015-01-10 02:25:56 +05305812 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005813 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305814 return downclock_mode;
5815}
5816
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005817static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005818 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005819{
5820 struct drm_connector *connector = &intel_connector->base;
5821 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005822 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5823 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005824 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005825 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07005826 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305827 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005828 bool has_dpcd;
5829 struct drm_display_mode *scan;
5830 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005831 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005832
Jani Nikula1853a9d2017-08-18 12:30:20 +03005833 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005834 return true;
5835
Imre Deak97a824e12016-06-21 11:51:47 +03005836 /*
5837 * On IBX/CPT we may get here with LVDS already registered. Since the
5838 * driver uses the only internal power sequencer available for both
5839 * eDP and LVDS bail out early in this case to prevent interfering
5840 * with an already powered-on LVDS power sequencer.
5841 */
5842 if (intel_get_lvds_encoder(dev)) {
5843 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5844 DRM_INFO("LVDS was detected, not registering eDP\n");
5845
5846 return false;
5847 }
5848
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005849 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005850
5851 intel_dp_init_panel_power_timestamps(intel_dp);
Ville Syrjälä46bd8382017-10-31 22:51:22 +02005852 intel_dp_pps_init(intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005853 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005854
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005855 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005856
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005857 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005858 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005859
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005860 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005861 /* if this fails, presume the device is a ghost */
5862 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005863 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005864 }
5865
Daniel Vetter060c8772014-03-21 23:22:35 +01005866 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005867 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005868 if (edid) {
5869 if (drm_add_edid_modes(connector, edid)) {
5870 drm_mode_connector_update_edid_property(connector,
5871 edid);
5872 drm_edid_to_eld(connector, edid);
5873 } else {
5874 kfree(edid);
5875 edid = ERR_PTR(-EINVAL);
5876 }
5877 } else {
5878 edid = ERR_PTR(-ENOENT);
5879 }
5880 intel_connector->edid = edid;
5881
Jim Bridedc911f52017-08-09 12:48:53 -07005882 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005883 list_for_each_entry(scan, &connector->probed_modes, head) {
5884 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5885 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305886 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305887 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07005888 } else if (!alt_fixed_mode) {
5889 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005890 }
5891 }
5892
5893 /* fallback to VBT if available for eDP */
5894 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5895 fixed_mode = drm_mode_duplicate(dev,
5896 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005897 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005898 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005899 connector->display_info.width_mm = fixed_mode->width_mm;
5900 connector->display_info.height_mm = fixed_mode->height_mm;
5901 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005902 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005903 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005904
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005905 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005906 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5907 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005908
5909 /*
5910 * Figure out the current pipe for the initial backlight setup.
5911 * If the current pipe isn't valid, try the PPS pipe, and if that
5912 * fails just assume pipe A.
5913 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005914 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005915
5916 if (pipe != PIPE_A && pipe != PIPE_B)
5917 pipe = intel_dp->pps_pipe;
5918
5919 if (pipe != PIPE_A && pipe != PIPE_B)
5920 pipe = PIPE_A;
5921
5922 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5923 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005924 }
5925
Jim Bridedc911f52017-08-09 12:48:53 -07005926 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5927 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005928 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005929 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005930
5931 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005932
5933out_vdd_off:
5934 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5935 /*
5936 * vdd might still be enabled do to the delayed vdd off.
5937 * Make sure vdd is actually turned off here.
5938 */
5939 pps_lock(intel_dp);
5940 edp_panel_vdd_off_sync(intel_dp);
5941 pps_unlock(intel_dp);
5942
5943 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005944}
5945
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005946/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005947static void
5948intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5949{
5950 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005951 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005952
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005953 encoder->hpd_pin = intel_hpd_pin(encoder->port);
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005954
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005955 switch (encoder->port) {
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005956 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005957 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005958 break;
5959 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005960 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005961 break;
5962 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005963 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005964 break;
5965 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005966 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005967 break;
5968 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005969 /* FIXME: Check VBT for actual wiring of PORT E */
5970 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005971 break;
5972 default:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02005973 MISSING_CASE(encoder->port);
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005974 }
5975}
5976
Manasi Navare93013972017-04-06 16:44:19 +03005977static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5978{
5979 struct intel_connector *intel_connector;
5980 struct drm_connector *connector;
5981
5982 intel_connector = container_of(work, typeof(*intel_connector),
5983 modeset_retry_work);
5984 connector = &intel_connector->base;
5985 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5986 connector->name);
5987
5988 /* Grab the locks before changing connector property*/
5989 mutex_lock(&connector->dev->mode_config.mutex);
5990 /* Set connector link status to BAD and send a Uevent to notify
5991 * userspace to do a modeset.
5992 */
5993 drm_mode_connector_set_link_status_property(connector,
5994 DRM_MODE_LINK_STATUS_BAD);
5995 mutex_unlock(&connector->dev->mode_config.mutex);
5996 /* Send Hotplug uevent so userspace can reprobe */
5997 drm_kms_helper_hotplug_event(connector->dev);
5998}
5999
Paulo Zanoni16c25532013-06-12 17:27:25 -03006000bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006001intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6002 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006003{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006004 struct drm_connector *connector = &intel_connector->base;
6005 struct intel_dp *intel_dp = &intel_dig_port->dp;
6006 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6007 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006008 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02006009 enum port port = intel_encoder->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006010 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006011
Manasi Navare93013972017-04-06 16:44:19 +03006012 /* Initialize the work for modeset in case of link train failure */
6013 INIT_WORK(&intel_connector->modeset_retry_work,
6014 intel_dp_modeset_retry_work_fn);
6015
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006016 if (WARN(intel_dig_port->max_lanes < 1,
6017 "Not enough lanes (%d) for DP on port %c\n",
6018 intel_dig_port->max_lanes, port_name(port)))
6019 return false;
6020
Jani Nikula55cfc582017-03-28 17:59:04 +03006021 intel_dp_set_source_rates(intel_dp);
6022
Manasi Navared7e8ef02017-02-07 16:54:11 -08006023 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006024 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006025 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006026
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006027 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006028 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006029 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006030 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006031 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006032 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006033 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6034 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006035 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006036
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006037 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006038 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6039 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006040 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006041
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006042 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006043 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6044
Daniel Vetter07679352012-09-06 22:15:42 +02006045 /* Preserve the current hw state. */
6046 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006047 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006048
Jani Nikula7b91bf72017-08-18 12:30:19 +03006049 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306050 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006051 else
6052 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006053
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006054 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6055 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6056
Imre Deakf7d24902013-05-08 13:14:05 +03006057 /*
6058 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6059 * for DP the encoder type can be set by the caller to
6060 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6061 */
6062 if (type == DRM_MODE_CONNECTOR_eDP)
6063 intel_encoder->type = INTEL_OUTPUT_EDP;
6064
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006065 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006066 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006067 intel_dp_is_edp(intel_dp) &&
6068 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006069 return false;
6070
Imre Deake7281ea2013-05-08 13:14:08 +03006071 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6072 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6073 port_name(port));
6074
Adam Jacksonb3295302010-07-16 14:46:28 -04006075 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006076 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6077
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006078 connector->interlace_allowed = true;
6079 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006080
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006081 intel_dp_init_connector_port_info(intel_dig_port);
6082
Mika Kaholab6339582016-09-09 14:10:52 +03006083 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006084
Daniel Vetter66a92782012-07-12 20:08:18 +02006085 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006086 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006087
Chris Wilsondf0e9242010-09-09 16:20:55 +01006088 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006089
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006090 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006091 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6092 else
6093 intel_connector->get_hw_state = intel_connector_get_hw_state;
6094
Dave Airlie0e32b392014-05-02 14:02:48 +10006095 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006096 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006097 (port == PORT_B || port == PORT_C || port == PORT_D))
6098 intel_dp_mst_encoder_init(intel_dig_port,
6099 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006100
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006101 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006102 intel_dp_aux_fini(intel_dp);
6103 intel_dp_mst_encoder_cleanup(intel_dig_port);
6104 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006105 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006106
Chris Wilsonf6849602010-09-19 09:29:33 +01006107 intel_dp_add_properties(intel_dp, connector);
6108
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006109 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6110 * 0xd. Failure to do so will result in spurious interrupts being
6111 * generated on the port when a cable is not attached.
6112 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006113 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006114 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6115 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6116 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006117
6118 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006119
6120fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006121 drm_connector_cleanup(connector);
6122
6123 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006124}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006125
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006126bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006127 i915_reg_t output_reg,
6128 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006129{
6130 struct intel_digital_port *intel_dig_port;
6131 struct intel_encoder *intel_encoder;
6132 struct drm_encoder *encoder;
6133 struct intel_connector *intel_connector;
6134
Daniel Vetterb14c5672013-09-19 12:18:32 +02006135 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006136 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006137 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006138
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006139 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306140 if (!intel_connector)
6141 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006142
6143 intel_encoder = &intel_dig_port->base;
6144 encoder = &intel_encoder->base;
6145
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006146 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6147 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6148 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306149 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006150
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006151 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006152 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006153 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006154 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006155 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006156 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006157 intel_encoder->pre_enable = chv_pre_enable_dp;
6158 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006159 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006160 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006161 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006162 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006163 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006164 intel_encoder->pre_enable = vlv_pre_enable_dp;
6165 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006166 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006167 intel_encoder->post_disable = vlv_post_disable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006168 } else if (INTEL_GEN(dev_priv) >= 5) {
6169 intel_encoder->pre_enable = g4x_pre_enable_dp;
6170 intel_encoder->enable = g4x_enable_dp;
6171 intel_encoder->disable = ilk_disable_dp;
6172 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006173 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006174 intel_encoder->pre_enable = g4x_pre_enable_dp;
6175 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006176 intel_encoder->disable = g4x_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006177 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006178
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006179 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006180 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006181
Ville Syrjäläcca05022016-06-22 21:57:06 +03006182 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006183 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006184 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006185 if (port == PORT_D)
6186 intel_encoder->crtc_mask = 1 << 2;
6187 else
6188 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6189 } else {
6190 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6191 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006192 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006193 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006194
Dave Airlie13cf5502014-06-18 11:29:35 +10006195 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006196 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006197
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006198 if (port != PORT_A)
6199 intel_infoframe_init(intel_dig_port);
6200
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306201 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6202 goto err_init_connector;
6203
Chris Wilson457c52d2016-06-01 08:27:50 +01006204 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306205
6206err_init_connector:
6207 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306208err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306209 kfree(intel_connector);
6210err_connector_alloc:
6211 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006212 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006213}
Dave Airlie0e32b392014-05-02 14:02:48 +10006214
6215void intel_dp_mst_suspend(struct drm_device *dev)
6216{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006217 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006218 int i;
6219
6220 /* disable MST */
6221 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006222 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006223
6224 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006225 continue;
6226
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006227 if (intel_dig_port->dp.is_mst)
6228 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006229 }
6230}
6231
6232void intel_dp_mst_resume(struct drm_device *dev)
6233{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006234 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006235 int i;
6236
6237 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006238 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006239 int ret;
6240
6241 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006242 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006243
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006244 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6245 if (ret)
6246 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006247 }
6248}