blob: ff04b3616f957f0782102a405feaba58e2f441d0 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Manasi Navare611032b2017-01-24 08:21:49 -080031#include <linux/types.h>
Clint Taylor01527b32014-07-07 13:01:46 -070032#include <linux/notifier.h>
33#include <linux/reboot.h>
Manasi Navare611032b2017-01-24 08:21:49 -080034#include <asm/byteorder.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_crtc.h>
38#include <drm/drm_crtc_helper.h>
39#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070043
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -070045#define DP_DPRX_ESI_LEN 14
Keith Packarda4fc5ed2009-04-07 16:16:42 -070046
Todd Previte559be302015-05-04 07:48:20 -070047/* Compliance test status bits */
48#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
49#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
52
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080053struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030054 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080055 struct dpll dpll;
56};
57
58static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030059 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080060 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030061 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080062 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
63};
64
65static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030066 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080067 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030068 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080069 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
70};
71
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080072static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030073 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080074 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030075 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080076 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
77};
78
Chon Ming Leeef9348c2014-04-09 13:28:18 +030079/*
80 * CHV supports eDP 1.4 that have more link rates.
81 * Below only provides the fixed rate but exclude variable rate.
82 */
83static const struct dp_link_dpll chv_dpll[] = {
84 /*
85 * CHV requires to program fractional division for m2.
86 * m2 is stored in fixed point format using formula below
87 * (m2_int << 22) | m2_fraction
88 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030089 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030090 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030091 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030092 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030093 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030094 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
95};
Sonika Jindal637a9c62015-05-07 09:52:08 +053096
Sonika Jindal64987fc2015-05-26 17:50:13 +053097static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
98 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053099static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +0200100 324000, 432000, 540000 };
Rodrigo Vivid907b662017-08-10 15:40:08 -0700101static const int cnl_rates[] = { 162000, 216000, 270000,
102 324000, 432000, 540000,
103 648000, 810000 };
Ville Syrjäläf4896f12015-03-12 17:10:27 +0200104static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300105
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700106/**
Jani Nikula1853a9d2017-08-18 12:30:20 +0300107 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700108 * @intel_dp: DP struct
109 *
110 * If a CPU or PCH DP output is attached to an eDP panel, this function
111 * will return true, and false otherwise.
112 */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300113bool intel_dp_is_edp(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200115 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
116
117 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700118}
119
Imre Deak68b4d822013-05-08 13:14:06 +0300120static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121{
Imre Deak68b4d822013-05-08 13:14:06 +0300122 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
123
124 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700125}
126
Chris Wilsondf0e9242010-09-09 16:20:55 +0100127static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
128{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200129 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100130}
131
Chris Wilsonea5b2132010-08-04 13:50:23 +0100132static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300133static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100134static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300135static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300136static void vlv_steal_power_sequencer(struct drm_device *dev,
137 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530138static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700139
Jani Nikula68f357c2017-03-28 17:59:05 +0300140static int intel_dp_num_rates(u8 link_bw_code)
141{
142 switch (link_bw_code) {
143 default:
144 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
145 link_bw_code);
146 case DP_LINK_BW_1_62:
147 return 1;
148 case DP_LINK_BW_2_7:
149 return 2;
150 case DP_LINK_BW_5_4:
151 return 3;
152 }
153}
154
155/* update sink rates from dpcd */
156static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
157{
158 int i, num_rates;
159
160 num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]);
161
162 for (i = 0; i < num_rates; i++)
163 intel_dp->sink_rates[i] = default_rates[i];
164
165 intel_dp->num_sink_rates = num_rates;
166}
167
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300168/* Theoretical max between source and sink */
169static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700170{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300171 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700172}
173
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300174/* Theoretical max between source and sink */
175static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300176{
177 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300178 int source_max = intel_dig_port->max_lanes;
179 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300180
181 return min(source_max, sink_max);
182}
183
Jani Nikula3d65a732017-04-06 16:44:14 +0300184int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300185{
186 return intel_dp->max_link_lane_count;
187}
188
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800189int
Keith Packardc8982612012-01-25 08:16:25 -0800190intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700191{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800192 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
193 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700194}
195
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800196int
Dave Airliefe27d532010-06-30 11:46:17 +1000197intel_dp_max_data_rate(int max_link_clock, int max_lanes)
198{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800199 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
200 * link rate that is generally expressed in Gbps. Since, 8 bits of data
201 * is transmitted every LS_Clk per lane, there is no need to account for
202 * the channel encoding that is done in the PHY layer here.
203 */
204
205 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000206}
207
Mika Kahola70ec0642016-09-09 14:10:55 +0300208static int
209intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
210{
211 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
212 struct intel_encoder *encoder = &intel_dig_port->base;
213 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
214 int max_dotclk = dev_priv->max_dotclk_freq;
215 int ds_max_dotclk;
216
217 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
218
219 if (type != DP_DS_PORT_TYPE_VGA)
220 return max_dotclk;
221
222 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
223 intel_dp->downstream_ports);
224
225 if (ds_max_dotclk != 0)
226 max_dotclk = min(max_dotclk, ds_max_dotclk);
227
228 return max_dotclk;
229}
230
Jani Nikula55cfc582017-03-28 17:59:04 +0300231static void
232intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700233{
234 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
235 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700236 enum port port = dig_port->port;
Jani Nikula55cfc582017-03-28 17:59:04 +0300237 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700238 int size;
Rodrigo Vivid907b662017-08-10 15:40:08 -0700239 u32 voltage;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700240
Jani Nikula55cfc582017-03-28 17:59:04 +0300241 /* This should only be done once */
242 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
243
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200244 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300245 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700246 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700247 } else if (IS_CANNONLAKE(dev_priv)) {
248 source_rates = cnl_rates;
249 size = ARRAY_SIZE(cnl_rates);
250 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
251 if (port == PORT_A || port == PORT_D ||
252 voltage == VOLTAGE_INFO_0_85V)
253 size -= 2;
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800254 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300255 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700256 size = ARRAY_SIZE(skl_rates);
257 } else {
Jani Nikula55cfc582017-03-28 17:59:04 +0300258 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700259 size = ARRAY_SIZE(default_rates);
260 }
261
262 /* This depends on the fact that 5.4 is last value in the array */
263 if (!intel_dp_source_supports_hbr2(intel_dp))
264 size--;
265
Jani Nikula55cfc582017-03-28 17:59:04 +0300266 intel_dp->source_rates = source_rates;
267 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700268}
269
270static int intersect_rates(const int *source_rates, int source_len,
271 const int *sink_rates, int sink_len,
272 int *common_rates)
273{
274 int i = 0, j = 0, k = 0;
275
276 while (i < source_len && j < sink_len) {
277 if (source_rates[i] == sink_rates[j]) {
278 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
279 return k;
280 common_rates[k] = source_rates[i];
281 ++k;
282 ++i;
283 ++j;
284 } else if (source_rates[i] < sink_rates[j]) {
285 ++i;
286 } else {
287 ++j;
288 }
289 }
290 return k;
291}
292
Jani Nikula8001b752017-03-28 17:59:03 +0300293/* return index of rate in rates array, or -1 if not found */
294static int intel_dp_rate_index(const int *rates, int len, int rate)
295{
296 int i;
297
298 for (i = 0; i < len; i++)
299 if (rate == rates[i])
300 return i;
301
302 return -1;
303}
304
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300305static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700306{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300307 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700308
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300309 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
310 intel_dp->num_source_rates,
311 intel_dp->sink_rates,
312 intel_dp->num_sink_rates,
313 intel_dp->common_rates);
314
315 /* Paranoia, there should always be something in common. */
316 if (WARN_ON(intel_dp->num_common_rates == 0)) {
317 intel_dp->common_rates[0] = default_rates[0];
318 intel_dp->num_common_rates = 1;
319 }
320}
321
322/* get length of common rates potentially limited by max_rate */
323static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
324 int max_rate)
325{
326 const int *common_rates = intel_dp->common_rates;
327 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700328
Jani Nikula68f357c2017-03-28 17:59:05 +0300329 /* Limit results by potentially reduced max rate */
330 for (i = 0; i < common_len; i++) {
331 if (common_rates[common_len - i - 1] <= max_rate)
332 return common_len - i;
333 }
334
335 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700336}
337
Manasi Navare1a92c702017-06-08 13:41:02 -0700338static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
339 uint8_t lane_count)
Manasi Navare14c562c2017-04-06 14:00:12 -0700340{
341 /*
342 * FIXME: we need to synchronize the current link parameters with
343 * hardware readout. Currently fast link training doesn't work on
344 * boot-up.
345 */
Manasi Navare1a92c702017-06-08 13:41:02 -0700346 if (link_rate == 0 ||
347 link_rate > intel_dp->max_link_rate)
Manasi Navare14c562c2017-04-06 14:00:12 -0700348 return false;
349
Manasi Navare1a92c702017-06-08 13:41:02 -0700350 if (lane_count == 0 ||
351 lane_count > intel_dp_max_lane_count(intel_dp))
Manasi Navare14c562c2017-04-06 14:00:12 -0700352 return false;
353
354 return true;
355}
356
Manasi Navarefdb14d32016-12-08 19:05:12 -0800357int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
358 int link_rate, uint8_t lane_count)
359{
Jani Nikulab1810a72017-04-06 16:44:11 +0300360 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800361
Jani Nikulab1810a72017-04-06 16:44:11 +0300362 index = intel_dp_rate_index(intel_dp->common_rates,
363 intel_dp->num_common_rates,
364 link_rate);
365 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300366 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
367 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800368 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300369 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300370 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800371 } else {
372 DRM_ERROR("Link Training Unsuccessful\n");
373 return -1;
374 }
375
376 return 0;
377}
378
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000379static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700380intel_dp_mode_valid(struct drm_connector *connector,
381 struct drm_display_mode *mode)
382{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100383 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300384 struct intel_connector *intel_connector = to_intel_connector(connector);
385 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100386 int target_clock = mode->clock;
387 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300388 int max_dotclk;
389
390 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700391
Jani Nikula1853a9d2017-08-18 12:30:20 +0300392 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
Jani Nikuladd06f902012-10-19 14:51:50 +0300393 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100394 return MODE_PANEL;
395
Jani Nikuladd06f902012-10-19 14:51:50 +0300396 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100397 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200398
399 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100400 }
401
Ville Syrjälä50fec212015-03-12 17:10:34 +0200402 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300403 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100404
405 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
406 mode_rate = intel_dp_link_required(target_clock, 18);
407
Mika Kahola799487f2016-02-02 15:16:38 +0200408 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200409 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700410
411 if (mode->clock < 10000)
412 return MODE_CLOCK_LOW;
413
Daniel Vetter0af78a22012-05-23 11:30:55 +0200414 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
415 return MODE_H_ILLEGAL;
416
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700417 return MODE_OK;
418}
419
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800420uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700421{
422 int i;
423 uint32_t v = 0;
424
425 if (src_bytes > 4)
426 src_bytes = 4;
427 for (i = 0; i < src_bytes; i++)
428 v |= ((uint32_t) src[i]) << ((3-i) * 8);
429 return v;
430}
431
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000432static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700433{
434 int i;
435 if (dst_bytes > 4)
436 dst_bytes = 4;
437 for (i = 0; i < dst_bytes; i++)
438 dst[i] = src >> ((3-i) * 8);
439}
440
Jani Nikulabf13e812013-09-06 07:40:05 +0300441static void
442intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300443 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300444static void
445intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200446 struct intel_dp *intel_dp,
447 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300448static void
449intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300450
Ville Syrjälä773538e82014-09-04 14:54:56 +0300451static void pps_lock(struct intel_dp *intel_dp)
452{
453 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
454 struct intel_encoder *encoder = &intel_dig_port->base;
455 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100456 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300457
458 /*
459 * See vlv_power_sequencer_reset() why we need
460 * a power domain reference here.
461 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200462 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300463
464 mutex_lock(&dev_priv->pps_mutex);
465}
466
467static void pps_unlock(struct intel_dp *intel_dp)
468{
469 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
470 struct intel_encoder *encoder = &intel_dig_port->base;
471 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100472 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300473
474 mutex_unlock(&dev_priv->pps_mutex);
475
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200476 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300477}
478
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300479static void
480vlv_power_sequencer_kick(struct intel_dp *intel_dp)
481{
482 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200483 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300484 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300485 bool pll_enabled, release_cl_override = false;
486 enum dpio_phy phy = DPIO_PHY(pipe);
487 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300488 uint32_t DP;
489
490 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
491 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
492 pipe_name(pipe), port_name(intel_dig_port->port)))
493 return;
494
495 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
496 pipe_name(pipe), port_name(intel_dig_port->port));
497
498 /* Preserve the BIOS-computed detected bit. This is
499 * supposed to be read-only.
500 */
501 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
502 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
503 DP |= DP_PORT_WIDTH(1);
504 DP |= DP_LINK_TRAIN_PAT_1;
505
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100506 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300507 DP |= DP_PIPE_SELECT_CHV(pipe);
508 else if (pipe == PIPE_B)
509 DP |= DP_PIPEB_SELECT;
510
Ville Syrjäläd288f652014-10-28 13:20:22 +0200511 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
512
513 /*
514 * The DPLL for the pipe must be enabled for this to work.
515 * So enable temporarily it if it's not already enabled.
516 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300517 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100518 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300519 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
520
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200521 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000522 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
523 DRM_ERROR("Failed to force on pll for pipe %c!\n",
524 pipe_name(pipe));
525 return;
526 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300527 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200528
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300529 /*
530 * Similar magic as in intel_dp_enable_port().
531 * We _must_ do this port enable + disable trick
532 * to make this power seqeuencer lock onto the port.
533 * Otherwise even VDD force bit won't work.
534 */
535 I915_WRITE(intel_dp->output_reg, DP);
536 POSTING_READ(intel_dp->output_reg);
537
538 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
539 POSTING_READ(intel_dp->output_reg);
540
541 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
542 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200543
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300544 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200545 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300546
547 if (release_cl_override)
548 chv_phy_powergate_ch(dev_priv, phy, ch, false);
549 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300550}
551
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200552static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
553{
554 struct intel_encoder *encoder;
555 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
556
557 /*
558 * We don't have power sequencer currently.
559 * Pick one that's not used by other ports.
560 */
561 for_each_intel_encoder(&dev_priv->drm, encoder) {
562 struct intel_dp *intel_dp;
563
564 if (encoder->type != INTEL_OUTPUT_DP &&
565 encoder->type != INTEL_OUTPUT_EDP)
566 continue;
567
568 intel_dp = enc_to_intel_dp(&encoder->base);
569
570 if (encoder->type == INTEL_OUTPUT_EDP) {
571 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
572 intel_dp->active_pipe != intel_dp->pps_pipe);
573
574 if (intel_dp->pps_pipe != INVALID_PIPE)
575 pipes &= ~(1 << intel_dp->pps_pipe);
576 } else {
577 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
578
579 if (intel_dp->active_pipe != INVALID_PIPE)
580 pipes &= ~(1 << intel_dp->active_pipe);
581 }
582 }
583
584 if (pipes == 0)
585 return INVALID_PIPE;
586
587 return ffs(pipes) - 1;
588}
589
Jani Nikulabf13e812013-09-06 07:40:05 +0300590static enum pipe
591vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
592{
593 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300594 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100595 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300596 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300597
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300598 lockdep_assert_held(&dev_priv->pps_mutex);
599
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300600 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300601 WARN_ON(!intel_dp_is_edp(intel_dp));
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300602
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200603 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
604 intel_dp->active_pipe != intel_dp->pps_pipe);
605
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300606 if (intel_dp->pps_pipe != INVALID_PIPE)
607 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300608
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200609 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300610
611 /*
612 * Didn't find one. This should not happen since there
613 * are two power sequencers and up to two eDP ports.
614 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200615 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300616 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300617
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300618 vlv_steal_power_sequencer(dev, pipe);
619 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300620
621 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
622 pipe_name(intel_dp->pps_pipe),
623 port_name(intel_dig_port->port));
624
625 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300626 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200627 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300628
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300629 /*
630 * Even vdd force doesn't work until we've made
631 * the power sequencer lock in on the port.
632 */
633 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300634
635 return intel_dp->pps_pipe;
636}
637
Imre Deak78597992016-06-16 16:37:20 +0300638static int
639bxt_power_sequencer_idx(struct intel_dp *intel_dp)
640{
641 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
642 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100643 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300644
645 lockdep_assert_held(&dev_priv->pps_mutex);
646
647 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300648 WARN_ON(!intel_dp_is_edp(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300649
650 /*
651 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
652 * mapping needs to be retrieved from VBT, for now just hard-code to
653 * use instance #0 always.
654 */
655 if (!intel_dp->pps_reset)
656 return 0;
657
658 intel_dp->pps_reset = false;
659
660 /*
661 * Only the HW needs to be reprogrammed, the SW state is fixed and
662 * has been setup during connector init.
663 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200664 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300665
666 return 0;
667}
668
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300669typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
670 enum pipe pipe);
671
672static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
673 enum pipe pipe)
674{
Imre Deak44cb7342016-08-10 14:07:29 +0300675 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300676}
677
678static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
679 enum pipe pipe)
680{
Imre Deak44cb7342016-08-10 14:07:29 +0300681 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300682}
683
684static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
685 enum pipe pipe)
686{
687 return true;
688}
689
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300690static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300691vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
692 enum port port,
693 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300694{
Jani Nikulabf13e812013-09-06 07:40:05 +0300695 enum pipe pipe;
696
Jani Nikulabf13e812013-09-06 07:40:05 +0300697 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300698 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300699 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300700
701 if (port_sel != PANEL_PORT_SELECT_VLV(port))
702 continue;
703
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300704 if (!pipe_check(dev_priv, pipe))
705 continue;
706
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300707 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300708 }
709
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300710 return INVALID_PIPE;
711}
712
713static void
714vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
715{
716 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
717 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100718 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300719 enum port port = intel_dig_port->port;
720
721 lockdep_assert_held(&dev_priv->pps_mutex);
722
723 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300724 /* first pick one where the panel is on */
725 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
726 vlv_pipe_has_pp_on);
727 /* didn't find one? pick one where vdd is on */
728 if (intel_dp->pps_pipe == INVALID_PIPE)
729 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
730 vlv_pipe_has_vdd_on);
731 /* didn't find one? pick one with just the correct port */
732 if (intel_dp->pps_pipe == INVALID_PIPE)
733 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
734 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300735
736 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
737 if (intel_dp->pps_pipe == INVALID_PIPE) {
738 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
739 port_name(port));
740 return;
741 }
742
743 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
744 port_name(port), pipe_name(intel_dp->pps_pipe));
745
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300746 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200747 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300748}
749
Imre Deak78597992016-06-16 16:37:20 +0300750void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300751{
Chris Wilson91c8a322016-07-05 10:40:23 +0100752 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300753 struct intel_encoder *encoder;
754
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100755 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200756 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300757 return;
758
759 /*
760 * We can't grab pps_mutex here due to deadlock with power_domain
761 * mutex when power_domain functions are called while holding pps_mutex.
762 * That also means that in order to use pps_pipe the code needs to
763 * hold both a power domain reference and pps_mutex, and the power domain
764 * reference get/put must be done while _not_ holding pps_mutex.
765 * pps_{lock,unlock}() do these steps in the correct order, so one
766 * should use them always.
767 */
768
Jani Nikula19c80542015-12-16 12:48:16 +0200769 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300770 struct intel_dp *intel_dp;
771
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200772 if (encoder->type != INTEL_OUTPUT_DP &&
773 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300774 continue;
775
776 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200777
778 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
779
780 if (encoder->type != INTEL_OUTPUT_EDP)
781 continue;
782
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200783 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300784 intel_dp->pps_reset = true;
785 else
786 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300787 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300788}
789
Imre Deak8e8232d2016-06-16 16:37:21 +0300790struct pps_registers {
791 i915_reg_t pp_ctrl;
792 i915_reg_t pp_stat;
793 i915_reg_t pp_on;
794 i915_reg_t pp_off;
795 i915_reg_t pp_div;
796};
797
798static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
799 struct intel_dp *intel_dp,
800 struct pps_registers *regs)
801{
Imre Deak44cb7342016-08-10 14:07:29 +0300802 int pps_idx = 0;
803
Imre Deak8e8232d2016-06-16 16:37:21 +0300804 memset(regs, 0, sizeof(*regs));
805
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200806 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300807 pps_idx = bxt_power_sequencer_idx(intel_dp);
808 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
809 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300810
Imre Deak44cb7342016-08-10 14:07:29 +0300811 regs->pp_ctrl = PP_CONTROL(pps_idx);
812 regs->pp_stat = PP_STATUS(pps_idx);
813 regs->pp_on = PP_ON_DELAYS(pps_idx);
814 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700815 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300816 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300817}
818
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200819static i915_reg_t
820_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300821{
Imre Deak8e8232d2016-06-16 16:37:21 +0300822 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300823
Imre Deak8e8232d2016-06-16 16:37:21 +0300824 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
825 &regs);
826
827 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300828}
829
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200830static i915_reg_t
831_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300832{
Imre Deak8e8232d2016-06-16 16:37:21 +0300833 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300834
Imre Deak8e8232d2016-06-16 16:37:21 +0300835 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
836 &regs);
837
838 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300839}
840
Clint Taylor01527b32014-07-07 13:01:46 -0700841/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
842 This function only applicable when panel PM state is not to be tracked */
843static int edp_notify_handler(struct notifier_block *this, unsigned long code,
844 void *unused)
845{
846 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
847 edp_notifier);
848 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100849 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700850
Jani Nikula1853a9d2017-08-18 12:30:20 +0300851 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
Clint Taylor01527b32014-07-07 13:01:46 -0700852 return 0;
853
Ville Syrjälä773538e82014-09-04 14:54:56 +0300854 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300855
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100856 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300857 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200858 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300859 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300860
Imre Deak44cb7342016-08-10 14:07:29 +0300861 pp_ctrl_reg = PP_CONTROL(pipe);
862 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700863 pp_div = I915_READ(pp_div_reg);
864 pp_div &= PP_REFERENCE_DIVIDER_MASK;
865
866 /* 0x1F write to PP_DIV_REG sets max cycle delay */
867 I915_WRITE(pp_div_reg, pp_div | 0x1F);
868 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
869 msleep(intel_dp->panel_power_cycle_delay);
870 }
871
Ville Syrjälä773538e82014-09-04 14:54:56 +0300872 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300873
Clint Taylor01527b32014-07-07 13:01:46 -0700874 return 0;
875}
876
Daniel Vetter4be73782014-01-17 14:39:48 +0100877static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700878{
Paulo Zanoni30add222012-10-26 19:05:45 -0200879 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100880 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700881
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300882 lockdep_assert_held(&dev_priv->pps_mutex);
883
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100884 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300885 intel_dp->pps_pipe == INVALID_PIPE)
886 return false;
887
Jani Nikulabf13e812013-09-06 07:40:05 +0300888 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700889}
890
Daniel Vetter4be73782014-01-17 14:39:48 +0100891static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700892{
Paulo Zanoni30add222012-10-26 19:05:45 -0200893 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100894 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700895
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300896 lockdep_assert_held(&dev_priv->pps_mutex);
897
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100898 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300899 intel_dp->pps_pipe == INVALID_PIPE)
900 return false;
901
Ville Syrjälä773538e82014-09-04 14:54:56 +0300902 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700903}
904
Keith Packard9b984da2011-09-19 13:54:47 -0700905static void
906intel_dp_check_edp(struct intel_dp *intel_dp)
907{
Paulo Zanoni30add222012-10-26 19:05:45 -0200908 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100909 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700910
Jani Nikula1853a9d2017-08-18 12:30:20 +0300911 if (!intel_dp_is_edp(intel_dp))
Keith Packard9b984da2011-09-19 13:54:47 -0700912 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700913
Daniel Vetter4be73782014-01-17 14:39:48 +0100914 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700915 WARN(1, "eDP powered off while attempting aux channel communication.\n");
916 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300917 I915_READ(_pp_stat_reg(intel_dp)),
918 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700919 }
920}
921
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100922static uint32_t
923intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
924{
925 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
926 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100927 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200928 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100929 uint32_t status;
930 bool done;
931
Daniel Vetteref04f002012-12-01 21:03:59 +0100932#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100933 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300934 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300935 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100936 else
Imre Deak713a6b662016-06-28 13:37:33 +0300937 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100938 if (!done)
939 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
940 has_aux_irq);
941#undef C
942
943 return status;
944}
945
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200946static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000947{
948 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200949 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000950
Ville Syrjäläa457f542016-03-02 17:22:17 +0200951 if (index)
952 return 0;
953
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000954 /*
955 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200956 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000957 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200958 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000959}
960
961static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
962{
963 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200964 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000965
966 if (index)
967 return 0;
968
Ville Syrjäläa457f542016-03-02 17:22:17 +0200969 /*
970 * The clock divider is based off the cdclk or PCH rawclk, and would
971 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
972 * divide by 2000 and use that
973 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200974 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200975 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200976 else
977 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000978}
979
980static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300981{
982 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200983 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300984
Ville Syrjäläa457f542016-03-02 17:22:17 +0200985 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300986 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100987 switch (index) {
988 case 0: return 63;
989 case 1: return 72;
990 default: return 0;
991 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300992 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200993
994 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300995}
996
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000997static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
998{
999 /*
1000 * SKL doesn't need us to program the AUX clock divider (Hardware will
1001 * derive the clock from CDCLK automatically). We still implement the
1002 * get_aux_clock_divider vfunc to plug-in into the existing code.
1003 */
1004 return index ? 0 : 1;
1005}
1006
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02001007static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1008 bool has_aux_irq,
1009 int send_bytes,
1010 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001011{
1012 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001013 struct drm_i915_private *dev_priv =
1014 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001015 uint32_t precharge, timeout;
1016
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001017 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001018 precharge = 3;
1019 else
1020 precharge = 5;
1021
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001022 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001023 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1024 else
1025 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1026
1027 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001028 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001029 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001030 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001031 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001032 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001033 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1034 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001035 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001036}
1037
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001038static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1039 bool has_aux_irq,
1040 int send_bytes,
1041 uint32_t unused)
1042{
1043 return DP_AUX_CH_CTL_SEND_BUSY |
1044 DP_AUX_CH_CTL_DONE |
1045 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1046 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1047 DP_AUX_CH_CTL_TIME_OUT_1600us |
1048 DP_AUX_CH_CTL_RECEIVE_ERROR |
1049 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001050 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001051 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1052}
1053
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001054static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001055intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001056 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001057 uint8_t *recv, int recv_size)
1058{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001059 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001060 struct drm_i915_private *dev_priv =
1061 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001062 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001063 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001064 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001065 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001066 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001067 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001068 bool vdd;
1069
Ville Syrjälä773538e82014-09-04 14:54:56 +03001070 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001071
Ville Syrjälä72c35002014-08-18 22:16:00 +03001072 /*
1073 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1074 * In such cases we want to leave VDD enabled and it's up to upper layers
1075 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1076 * ourselves.
1077 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001078 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001079
1080 /* dp aux is extremely sensitive to irq latency, hence request the
1081 * lowest possible wakeup latency and so prevent the cpu from going into
1082 * deep sleep states.
1083 */
1084 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001085
Keith Packard9b984da2011-09-19 13:54:47 -07001086 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001087
Jesse Barnes11bee432011-08-01 15:02:20 -07001088 /* Try to wait for any previous AUX channel activity */
1089 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001090 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001091 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1092 break;
1093 msleep(1);
1094 }
1095
1096 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001097 static u32 last_status = -1;
1098 const u32 status = I915_READ(ch_ctl);
1099
1100 if (status != last_status) {
1101 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1102 status);
1103 last_status = status;
1104 }
1105
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001106 ret = -EBUSY;
1107 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001108 }
1109
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001110 /* Only 5 data registers! */
1111 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1112 ret = -E2BIG;
1113 goto out;
1114 }
1115
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001116 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001117 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1118 has_aux_irq,
1119 send_bytes,
1120 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001121
Chris Wilsonbc866252013-07-21 16:00:03 +01001122 /* Must try at least 3 times according to DP spec */
1123 for (try = 0; try < 5; try++) {
1124 /* Load the send data into the aux channel data registers */
1125 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001126 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001127 intel_dp_pack_aux(send + i,
1128 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001129
Chris Wilsonbc866252013-07-21 16:00:03 +01001130 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001131 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001132
Chris Wilsonbc866252013-07-21 16:00:03 +01001133 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001134
Chris Wilsonbc866252013-07-21 16:00:03 +01001135 /* Clear done status and any errors */
1136 I915_WRITE(ch_ctl,
1137 status |
1138 DP_AUX_CH_CTL_DONE |
1139 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1140 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001141
Todd Previte74ebf292015-04-15 08:38:41 -07001142 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001143 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001144
1145 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1146 * 400us delay required for errors and timeouts
1147 * Timeout errors from the HW already meet this
1148 * requirement so skip to next iteration
1149 */
1150 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1151 usleep_range(400, 500);
1152 continue;
1153 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001154 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001155 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001156 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001157 }
1158
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001159 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001160 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001161 ret = -EBUSY;
1162 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001163 }
1164
Jim Bridee058c942015-05-27 10:21:48 -07001165done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001166 /* Check for timeout or receive error.
1167 * Timeouts occur when the sink is not connected
1168 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001169 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001170 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001171 ret = -EIO;
1172 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001173 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001174
1175 /* Timeouts occur when the device isn't connected, so they're
1176 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001177 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001178 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001179 ret = -ETIMEDOUT;
1180 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181 }
1182
1183 /* Unload any bytes sent back from the other side */
1184 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1185 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001186
1187 /*
1188 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1189 * We have no idea of what happened so we return -EBUSY so
1190 * drm layer takes care for the necessary retries.
1191 */
1192 if (recv_bytes == 0 || recv_bytes > 20) {
1193 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1194 recv_bytes);
1195 /*
1196 * FIXME: This patch was created on top of a series that
1197 * organize the retries at drm level. There EBUSY should
1198 * also take care for 1ms wait before retrying.
1199 * That aux retries re-org is still needed and after that is
1200 * merged we remove this sleep from here.
1201 */
1202 usleep_range(1000, 1500);
1203 ret = -EBUSY;
1204 goto out;
1205 }
1206
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001207 if (recv_bytes > recv_size)
1208 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001209
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001210 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001211 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001212 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001213
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001214 ret = recv_bytes;
1215out:
1216 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1217
Jani Nikula884f19e2014-03-14 16:51:14 +02001218 if (vdd)
1219 edp_panel_vdd_off(intel_dp, false);
1220
Ville Syrjälä773538e82014-09-04 14:54:56 +03001221 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001222
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001223 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001224}
1225
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001226#define BARE_ADDRESS_SIZE 3
1227#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001228static ssize_t
1229intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001230{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001231 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1232 uint8_t txbuf[20], rxbuf[20];
1233 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001234 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001235
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001236 txbuf[0] = (msg->request << 4) |
1237 ((msg->address >> 16) & 0xf);
1238 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001239 txbuf[2] = msg->address & 0xff;
1240 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001241
Jani Nikula9d1a1032014-03-14 16:51:15 +02001242 switch (msg->request & ~DP_AUX_I2C_MOT) {
1243 case DP_AUX_NATIVE_WRITE:
1244 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001245 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001246 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001247 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001248
Jani Nikula9d1a1032014-03-14 16:51:15 +02001249 if (WARN_ON(txsize > 20))
1250 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001251
Ville Syrjälädd788092016-07-28 17:55:04 +03001252 WARN_ON(!msg->buffer != !msg->size);
1253
Imre Deakd81a67c2016-01-29 14:52:26 +02001254 if (msg->buffer)
1255 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001256
Jani Nikula9d1a1032014-03-14 16:51:15 +02001257 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1258 if (ret > 0) {
1259 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001260
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001261 if (ret > 1) {
1262 /* Number of bytes written in a short write. */
1263 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1264 } else {
1265 /* Return payload size. */
1266 ret = msg->size;
1267 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001268 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001269 break;
1270
1271 case DP_AUX_NATIVE_READ:
1272 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001273 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001274 rxsize = msg->size + 1;
1275
1276 if (WARN_ON(rxsize > 20))
1277 return -E2BIG;
1278
1279 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1280 if (ret > 0) {
1281 msg->reply = rxbuf[0] >> 4;
1282 /*
1283 * Assume happy day, and copy the data. The caller is
1284 * expected to check msg->reply before touching it.
1285 *
1286 * Return payload size.
1287 */
1288 ret--;
1289 memcpy(msg->buffer, rxbuf + 1, ret);
1290 }
1291 break;
1292
1293 default:
1294 ret = -EINVAL;
1295 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001296 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001297
Jani Nikula9d1a1032014-03-14 16:51:15 +02001298 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001299}
1300
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001301static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1302 enum port port)
1303{
1304 const struct ddi_vbt_port_info *info =
1305 &dev_priv->vbt.ddi_port_info[port];
1306 enum port aux_port;
1307
1308 if (!info->alternate_aux_channel) {
1309 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1310 port_name(port), port_name(port));
1311 return port;
1312 }
1313
1314 switch (info->alternate_aux_channel) {
1315 case DP_AUX_A:
1316 aux_port = PORT_A;
1317 break;
1318 case DP_AUX_B:
1319 aux_port = PORT_B;
1320 break;
1321 case DP_AUX_C:
1322 aux_port = PORT_C;
1323 break;
1324 case DP_AUX_D:
1325 aux_port = PORT_D;
1326 break;
1327 default:
1328 MISSING_CASE(info->alternate_aux_channel);
1329 aux_port = PORT_A;
1330 break;
1331 }
1332
1333 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1334 port_name(aux_port), port_name(port));
1335
1336 return aux_port;
1337}
1338
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001339static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001340 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001341{
1342 switch (port) {
1343 case PORT_B:
1344 case PORT_C:
1345 case PORT_D:
1346 return DP_AUX_CH_CTL(port);
1347 default:
1348 MISSING_CASE(port);
1349 return DP_AUX_CH_CTL(PORT_B);
1350 }
1351}
1352
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001353static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001354 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001355{
1356 switch (port) {
1357 case PORT_B:
1358 case PORT_C:
1359 case PORT_D:
1360 return DP_AUX_CH_DATA(port, index);
1361 default:
1362 MISSING_CASE(port);
1363 return DP_AUX_CH_DATA(PORT_B, index);
1364 }
1365}
1366
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001367static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001368 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001369{
1370 switch (port) {
1371 case PORT_A:
1372 return DP_AUX_CH_CTL(port);
1373 case PORT_B:
1374 case PORT_C:
1375 case PORT_D:
1376 return PCH_DP_AUX_CH_CTL(port);
1377 default:
1378 MISSING_CASE(port);
1379 return DP_AUX_CH_CTL(PORT_A);
1380 }
1381}
1382
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001383static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001384 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001385{
1386 switch (port) {
1387 case PORT_A:
1388 return DP_AUX_CH_DATA(port, index);
1389 case PORT_B:
1390 case PORT_C:
1391 case PORT_D:
1392 return PCH_DP_AUX_CH_DATA(port, index);
1393 default:
1394 MISSING_CASE(port);
1395 return DP_AUX_CH_DATA(PORT_A, index);
1396 }
1397}
1398
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001399static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001400 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001401{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001402 switch (port) {
1403 case PORT_A:
1404 case PORT_B:
1405 case PORT_C:
1406 case PORT_D:
1407 return DP_AUX_CH_CTL(port);
1408 default:
1409 MISSING_CASE(port);
1410 return DP_AUX_CH_CTL(PORT_A);
1411 }
1412}
1413
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001414static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001415 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001416{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001417 switch (port) {
1418 case PORT_A:
1419 case PORT_B:
1420 case PORT_C:
1421 case PORT_D:
1422 return DP_AUX_CH_DATA(port, index);
1423 default:
1424 MISSING_CASE(port);
1425 return DP_AUX_CH_DATA(PORT_A, index);
1426 }
1427}
1428
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001429static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001430 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001431{
1432 if (INTEL_INFO(dev_priv)->gen >= 9)
1433 return skl_aux_ctl_reg(dev_priv, port);
1434 else if (HAS_PCH_SPLIT(dev_priv))
1435 return ilk_aux_ctl_reg(dev_priv, port);
1436 else
1437 return g4x_aux_ctl_reg(dev_priv, port);
1438}
1439
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001440static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001441 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001442{
1443 if (INTEL_INFO(dev_priv)->gen >= 9)
1444 return skl_aux_data_reg(dev_priv, port, index);
1445 else if (HAS_PCH_SPLIT(dev_priv))
1446 return ilk_aux_data_reg(dev_priv, port, index);
1447 else
1448 return g4x_aux_data_reg(dev_priv, port, index);
1449}
1450
1451static void intel_aux_reg_init(struct intel_dp *intel_dp)
1452{
1453 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001454 enum port port = intel_aux_port(dev_priv,
1455 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001456 int i;
1457
1458 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1459 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1460 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1461}
1462
Jani Nikula9d1a1032014-03-14 16:51:15 +02001463static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001464intel_dp_aux_fini(struct intel_dp *intel_dp)
1465{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001466 kfree(intel_dp->aux.name);
1467}
1468
Chris Wilson7a418e32016-06-24 14:00:14 +01001469static void
Mika Kaholab6339582016-09-09 14:10:52 +03001470intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001471{
Jani Nikula33ad6622014-03-14 16:51:16 +02001472 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1473 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001474
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001475 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001476 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001477
Chris Wilson7a418e32016-06-24 14:00:14 +01001478 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001479 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001480 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001481}
1482
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001483bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301484{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001485 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001486 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001487
Navare, Manasi D577c5432016-09-27 16:36:53 -07001488 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1489 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301490 return true;
1491 else
1492 return false;
1493}
1494
Daniel Vetter0e503382014-07-04 11:26:04 -03001495static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001496intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001497 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001498{
1499 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001500 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001501 const struct dp_link_dpll *divisor = NULL;
1502 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001503
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001504 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001505 divisor = gen4_dpll;
1506 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001507 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001508 divisor = pch_dpll;
1509 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001510 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001511 divisor = chv_dpll;
1512 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001513 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001514 divisor = vlv_dpll;
1515 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001516 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001517
1518 if (divisor && count) {
1519 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001520 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001521 pipe_config->dpll = divisor[i].dpll;
1522 pipe_config->clock_set = true;
1523 break;
1524 }
1525 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001526 }
1527}
1528
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001529static void snprintf_int_array(char *str, size_t len,
1530 const int *array, int nelem)
1531{
1532 int i;
1533
1534 str[0] = '\0';
1535
1536 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001537 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001538 if (r >= len)
1539 return;
1540 str += r;
1541 len -= r;
1542 }
1543}
1544
1545static void intel_dp_print_rates(struct intel_dp *intel_dp)
1546{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001547 char str[128]; /* FIXME: too big for stack? */
1548
1549 if ((drm_debug & DRM_UT_KMS) == 0)
1550 return;
1551
Jani Nikula55cfc582017-03-28 17:59:04 +03001552 snprintf_int_array(str, sizeof(str),
1553 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001554 DRM_DEBUG_KMS("source rates: %s\n", str);
1555
Jani Nikula68f357c2017-03-28 17:59:05 +03001556 snprintf_int_array(str, sizeof(str),
1557 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001558 DRM_DEBUG_KMS("sink rates: %s\n", str);
1559
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001560 snprintf_int_array(str, sizeof(str),
1561 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001562 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001563}
1564
Ville Syrjälä50fec212015-03-12 17:10:34 +02001565int
1566intel_dp_max_link_rate(struct intel_dp *intel_dp)
1567{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001568 int len;
1569
Jani Nikulae6c0c642017-04-06 16:44:12 +03001570 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001571 if (WARN_ON(len <= 0))
1572 return 162000;
1573
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001574 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001575}
1576
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001577int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1578{
Jani Nikula8001b752017-03-28 17:59:03 +03001579 int i = intel_dp_rate_index(intel_dp->sink_rates,
1580 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001581
1582 if (WARN_ON(i < 0))
1583 i = 0;
1584
1585 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001586}
1587
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001588void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1589 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001590{
Jani Nikula68f357c2017-03-28 17:59:05 +03001591 /* eDP 1.4 rate select method. */
1592 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001593 *link_bw = 0;
1594 *rate_select =
1595 intel_dp_rate_select(intel_dp, port_clock);
1596 } else {
1597 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1598 *rate_select = 0;
1599 }
1600}
1601
Jani Nikulaf580bea2016-09-15 16:28:52 +03001602static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1603 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001604{
1605 int bpp, bpc;
1606
1607 bpp = pipe_config->pipe_bpp;
1608 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1609
1610 if (bpc > 0)
1611 bpp = min(bpp, 3*bpc);
1612
Manasi Navare611032b2017-01-24 08:21:49 -08001613 /* For DP Compliance we override the computed bpp for the pipe */
1614 if (intel_dp->compliance.test_data.bpc != 0) {
1615 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1616 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1617 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1618 pipe_config->pipe_bpp);
1619 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001620 return bpp;
1621}
1622
Jim Bridedc911f52017-08-09 12:48:53 -07001623static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1624 struct drm_display_mode *m2)
1625{
1626 bool bres = false;
1627
1628 if (m1 && m2)
1629 bres = (m1->hdisplay == m2->hdisplay &&
1630 m1->hsync_start == m2->hsync_start &&
1631 m1->hsync_end == m2->hsync_end &&
1632 m1->htotal == m2->htotal &&
1633 m1->vdisplay == m2->vdisplay &&
1634 m1->vsync_start == m2->vsync_start &&
1635 m1->vsync_end == m2->vsync_end &&
1636 m1->vtotal == m2->vtotal);
1637 return bres;
1638}
1639
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001640bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001641intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001642 struct intel_crtc_state *pipe_config,
1643 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001644{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001645 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001646 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001647 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001648 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001649 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001650 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001651 struct intel_digital_connector_state *intel_conn_state =
1652 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001653 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001654 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001655 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001656 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001657 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301658 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001659 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001660 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001661 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001662 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001663 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1664 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301665
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001666 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001667 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301668
1669 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001670 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301671
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001672 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001673
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001674 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001675 pipe_config->has_pch_encoder = true;
1676
Vandana Kannanf769cd22014-08-05 07:51:22 -07001677 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001678 if (port == PORT_A)
1679 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001680 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001681 pipe_config->has_audio = intel_dp->has_audio;
1682 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001683 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001684
Jani Nikula1853a9d2017-08-18 12:30:20 +03001685 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jim Bridedc911f52017-08-09 12:48:53 -07001686 struct drm_display_mode *panel_mode =
1687 intel_connector->panel.alt_fixed_mode;
1688 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1689
1690 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1691 panel_mode = intel_connector->panel.fixed_mode;
1692
1693 drm_mode_debug_printmodeline(panel_mode);
1694
1695 intel_fixed_panel_mode(panel_mode, adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001696
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001697 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001698 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001699 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001700 if (ret)
1701 return ret;
1702 }
1703
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001704 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001705 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001706 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001707 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001708 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001709 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001710 }
1711
Daniel Vettercb1793c2012-06-04 18:39:21 +02001712 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001713 return false;
1714
Manasi Navareda15f7c2017-01-24 08:16:34 -08001715 /* Use values requested by Compliance Test Request */
1716 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001717 int index;
1718
Manasi Navare140ef132017-06-08 13:41:03 -07001719 /* Validate the compliance test data since max values
1720 * might have changed due to link train fallback.
1721 */
1722 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1723 intel_dp->compliance.test_lane_count)) {
1724 index = intel_dp_rate_index(intel_dp->common_rates,
1725 intel_dp->num_common_rates,
1726 intel_dp->compliance.test_link_rate);
1727 if (index >= 0)
1728 min_clock = max_clock = index;
1729 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1730 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08001731 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001732 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301733 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001734 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001735 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001736
Daniel Vetter36008362013-03-27 00:44:59 +01001737 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1738 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001739 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula1853a9d2017-08-18 12:30:20 +03001740 if (intel_dp_is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301741
1742 /* Get bpp from vbt only for panels that dont have bpp in edid */
1743 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001744 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001745 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001746 dev_priv->vbt.edp.bpp);
1747 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001748 }
1749
Jani Nikula344c5bb2014-09-09 11:25:13 +03001750 /*
1751 * Use the maximum clock and number of lanes the eDP panel
1752 * advertizes being capable of. The panels are generally
1753 * designed to support only a single clock and lane
1754 * configuration, and typically these values correspond to the
1755 * native resolution of the panel.
1756 */
1757 min_lane_count = max_lane_count;
1758 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001759 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001760
Daniel Vetter36008362013-03-27 00:44:59 +01001761 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001762 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1763 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001764
Dave Airliec6930992014-07-14 11:04:39 +10001765 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301766 for (lane_count = min_lane_count;
1767 lane_count <= max_lane_count;
1768 lane_count <<= 1) {
1769
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001770 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001771 link_avail = intel_dp_max_data_rate(link_clock,
1772 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001773
Daniel Vetter36008362013-03-27 00:44:59 +01001774 if (mode_rate <= link_avail) {
1775 goto found;
1776 }
1777 }
1778 }
1779 }
1780
1781 return false;
1782
1783found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001784 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001785 /*
1786 * See:
1787 * CEA-861-E - 5.1 Default Encoding Parameters
1788 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1789 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001790 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001791 bpp != 18 &&
1792 drm_default_rgb_quant_range(adjusted_mode) ==
1793 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001794 } else {
1795 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001796 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001797 }
1798
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001799 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301800
Daniel Vetter657445f2013-05-04 10:09:18 +02001801 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001802 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001803
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001804 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1805 &link_bw, &rate_select);
1806
1807 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1808 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001809 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001810 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1811 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001812
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001813 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001814 adjusted_mode->crtc_clock,
1815 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001816 &pipe_config->dp_m_n,
1817 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001818
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301819 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301820 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001821 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301822 intel_link_compute_m_n(bpp, lane_count,
1823 intel_connector->panel.downclock_mode->clock,
1824 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001825 &pipe_config->dp_m2_n2,
1826 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301827 }
1828
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001829 /*
1830 * DPLL0 VCO may need to be adjusted to get the correct
1831 * clock for eDP. This will affect cdclk as well.
1832 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03001833 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001834 int vco;
1835
1836 switch (pipe_config->port_clock / 2) {
1837 case 108000:
1838 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001839 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001840 break;
1841 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001842 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001843 break;
1844 }
1845
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001846 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001847 }
1848
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001849 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001850 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001851
Daniel Vetter36008362013-03-27 00:44:59 +01001852 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001853}
1854
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001855void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001856 int link_rate, uint8_t lane_count,
1857 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001858{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001859 intel_dp->link_rate = link_rate;
1860 intel_dp->lane_count = lane_count;
1861 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001862}
1863
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001864static void intel_dp_prepare(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03001865 const struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001866{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001867 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001868 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001869 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001870 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001871 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001872 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001873
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001874 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1875 pipe_config->lane_count,
1876 intel_crtc_has_type(pipe_config,
1877 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001878
Keith Packard417e8222011-11-01 19:54:11 -07001879 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001880 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001881 *
1882 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001883 * SNB CPU
1884 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001885 * CPT PCH
1886 *
1887 * IBX PCH and CPU are the same for almost everything,
1888 * except that the CPU DP PLL is configured in this
1889 * register
1890 *
1891 * CPT PCH is quite different, having many bits moved
1892 * to the TRANS_DP_CTL register instead. That
1893 * configuration happens (oddly) in ironlake_pch_enable
1894 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001895
Keith Packard417e8222011-11-01 19:54:11 -07001896 /* Preserve the BIOS-computed detected bit. This is
1897 * supposed to be read-only.
1898 */
1899 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001900
Keith Packard417e8222011-11-01 19:54:11 -07001901 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001902 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001903 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001904
Keith Packard417e8222011-11-01 19:54:11 -07001905 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001906
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001907 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001908 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1909 intel_dp->DP |= DP_SYNC_HS_HIGH;
1910 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1911 intel_dp->DP |= DP_SYNC_VS_HIGH;
1912 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1913
Jani Nikula6aba5b62013-10-04 15:08:10 +03001914 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001915 intel_dp->DP |= DP_ENHANCED_FRAMING;
1916
Daniel Vetter7c62a162013-06-01 17:16:20 +02001917 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001918 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001919 u32 trans_dp;
1920
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001921 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001922
1923 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1924 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1925 trans_dp |= TRANS_DP_ENH_FRAMING;
1926 else
1927 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1928 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001929 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001930 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001931 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001932
1933 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1934 intel_dp->DP |= DP_SYNC_HS_HIGH;
1935 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1936 intel_dp->DP |= DP_SYNC_VS_HIGH;
1937 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1938
Jani Nikula6aba5b62013-10-04 15:08:10 +03001939 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001940 intel_dp->DP |= DP_ENHANCED_FRAMING;
1941
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001942 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001943 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001944 else if (crtc->pipe == PIPE_B)
1945 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001946 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001947}
1948
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001949#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1950#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001951
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001952#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1953#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001954
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001955#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1956#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001957
Imre Deakde9c1b62016-06-16 20:01:46 +03001958static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1959 struct intel_dp *intel_dp);
1960
Daniel Vetter4be73782014-01-17 14:39:48 +01001961static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001962 u32 mask,
1963 u32 value)
1964{
Paulo Zanoni30add222012-10-26 19:05:45 -02001965 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001966 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001967 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001968
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001969 lockdep_assert_held(&dev_priv->pps_mutex);
1970
Imre Deakde9c1b62016-06-16 20:01:46 +03001971 intel_pps_verify_state(dev_priv, intel_dp);
1972
Jani Nikulabf13e812013-09-06 07:40:05 +03001973 pp_stat_reg = _pp_stat_reg(intel_dp);
1974 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001975
1976 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001977 mask, value,
1978 I915_READ(pp_stat_reg),
1979 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001980
Chris Wilson9036ff02016-06-30 15:33:09 +01001981 if (intel_wait_for_register(dev_priv,
1982 pp_stat_reg, mask, value,
1983 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001984 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001985 I915_READ(pp_stat_reg),
1986 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001987
1988 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001989}
1990
Daniel Vetter4be73782014-01-17 14:39:48 +01001991static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001992{
1993 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001994 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001995}
1996
Daniel Vetter4be73782014-01-17 14:39:48 +01001997static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001998{
Keith Packardbd943152011-09-18 23:09:52 -07001999 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01002000 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07002001}
Keith Packardbd943152011-09-18 23:09:52 -07002002
Daniel Vetter4be73782014-01-17 14:39:48 +01002003static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07002004{
Abhay Kumard28d4732016-01-22 17:39:04 -08002005 ktime_t panel_power_on_time;
2006 s64 panel_power_off_duration;
2007
Keith Packard99ea7122011-11-01 19:57:50 -07002008 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02002009
Abhay Kumard28d4732016-01-22 17:39:04 -08002010 /* take the difference of currrent time and panel power off time
2011 * and then make panel wait for t11_t12 if needed. */
2012 panel_power_on_time = ktime_get_boottime();
2013 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2014
Paulo Zanonidce56b32013-12-19 14:29:40 -02002015 /* When we disable the VDD override bit last we have to do the manual
2016 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08002017 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2018 wait_remaining_ms_from_jiffies(jiffies,
2019 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002020
Daniel Vetter4be73782014-01-17 14:39:48 +01002021 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002022}
Keith Packardbd943152011-09-18 23:09:52 -07002023
Daniel Vetter4be73782014-01-17 14:39:48 +01002024static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002025{
2026 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2027 intel_dp->backlight_on_delay);
2028}
2029
Daniel Vetter4be73782014-01-17 14:39:48 +01002030static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002031{
2032 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2033 intel_dp->backlight_off_delay);
2034}
Keith Packard99ea7122011-11-01 19:57:50 -07002035
Keith Packard832dd3c2011-11-01 19:34:06 -07002036/* Read the current pp_control value, unlocking the register if it
2037 * is locked
2038 */
2039
Jesse Barnes453c5422013-03-28 09:55:41 -07002040static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002041{
Jesse Barnes453c5422013-03-28 09:55:41 -07002042 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002043 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002044 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002045
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002046 lockdep_assert_held(&dev_priv->pps_mutex);
2047
Jani Nikulabf13e812013-09-06 07:40:05 +03002048 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002049 if (WARN_ON(!HAS_DDI(dev_priv) &&
2050 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302051 control &= ~PANEL_UNLOCK_MASK;
2052 control |= PANEL_UNLOCK_REGS;
2053 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002054 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002055}
2056
Ville Syrjälä951468f2014-09-04 14:55:31 +03002057/*
2058 * Must be paired with edp_panel_vdd_off().
2059 * Must hold pps_mutex around the whole on/off sequence.
2060 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2061 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002062static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002063{
Paulo Zanoni30add222012-10-26 19:05:45 -02002064 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002065 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002066 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002067 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002068 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002069 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002070
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002071 lockdep_assert_held(&dev_priv->pps_mutex);
2072
Jani Nikula1853a9d2017-08-18 12:30:20 +03002073 if (!intel_dp_is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002074 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002075
Egbert Eich2c623c12014-11-25 12:54:57 +01002076 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002077 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002078
Daniel Vetter4be73782014-01-17 14:39:48 +01002079 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002080 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002081
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002082 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002083
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002084 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2085 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002086
Daniel Vetter4be73782014-01-17 14:39:48 +01002087 if (!edp_have_panel_power(intel_dp))
2088 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002089
Jesse Barnes453c5422013-03-28 09:55:41 -07002090 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002091 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002092
Jani Nikulabf13e812013-09-06 07:40:05 +03002093 pp_stat_reg = _pp_stat_reg(intel_dp);
2094 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002095
2096 I915_WRITE(pp_ctrl_reg, pp);
2097 POSTING_READ(pp_ctrl_reg);
2098 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2099 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002100 /*
2101 * If the panel wasn't on, delay before accessing aux channel
2102 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002103 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002104 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2105 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002106 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002107 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002108
2109 return need_to_disable;
2110}
2111
Ville Syrjälä951468f2014-09-04 14:55:31 +03002112/*
2113 * Must be paired with intel_edp_panel_vdd_off() or
2114 * intel_edp_panel_off().
2115 * Nested calls to these functions are not allowed since
2116 * we drop the lock. Caller must use some higher level
2117 * locking to prevent nested calls from other threads.
2118 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002119void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002120{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002121 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002122
Jani Nikula1853a9d2017-08-18 12:30:20 +03002123 if (!intel_dp_is_edp(intel_dp))
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002124 return;
2125
Ville Syrjälä773538e82014-09-04 14:54:56 +03002126 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002127 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002128 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002129
Rob Clarke2c719b2014-12-15 13:56:32 -05002130 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002131 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002132}
2133
Daniel Vetter4be73782014-01-17 14:39:48 +01002134static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002135{
Paulo Zanoni30add222012-10-26 19:05:45 -02002136 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002137 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002138 struct intel_digital_port *intel_dig_port =
2139 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002140 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002141 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002142
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002143 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002144
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002145 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002146
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002147 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002148 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002149
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002150 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2151 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002152
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002153 pp = ironlake_get_pp_control(intel_dp);
2154 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002155
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002156 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2157 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002158
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002159 I915_WRITE(pp_ctrl_reg, pp);
2160 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002161
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002162 /* Make sure sequencer is idle before allowing subsequent activity */
2163 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2164 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002165
Imre Deak5a162e22016-08-10 14:07:30 +03002166 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002167 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002168
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002169 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002170}
2171
Daniel Vetter4be73782014-01-17 14:39:48 +01002172static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002173{
2174 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2175 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002176
Ville Syrjälä773538e82014-09-04 14:54:56 +03002177 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002178 if (!intel_dp->want_panel_vdd)
2179 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002180 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002181}
2182
Imre Deakaba86892014-07-30 15:57:31 +03002183static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2184{
2185 unsigned long delay;
2186
2187 /*
2188 * Queue the timer to fire a long time from now (relative to the power
2189 * down delay) to keep the panel power up across a sequence of
2190 * operations.
2191 */
2192 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2193 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2194}
2195
Ville Syrjälä951468f2014-09-04 14:55:31 +03002196/*
2197 * Must be paired with edp_panel_vdd_on().
2198 * Must hold pps_mutex around the whole on/off sequence.
2199 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2200 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002201static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002202{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002203 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002204
2205 lockdep_assert_held(&dev_priv->pps_mutex);
2206
Jani Nikula1853a9d2017-08-18 12:30:20 +03002207 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002208 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002209
Rob Clarke2c719b2014-12-15 13:56:32 -05002210 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002211 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002212
Keith Packardbd943152011-09-18 23:09:52 -07002213 intel_dp->want_panel_vdd = false;
2214
Imre Deakaba86892014-07-30 15:57:31 +03002215 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002216 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002217 else
2218 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002219}
2220
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002221static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002222{
Paulo Zanoni30add222012-10-26 19:05:45 -02002223 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002224 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002225 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002226 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002227
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002228 lockdep_assert_held(&dev_priv->pps_mutex);
2229
Jani Nikula1853a9d2017-08-18 12:30:20 +03002230 if (!intel_dp_is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002231 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002232
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002233 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2234 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002235
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002236 if (WARN(edp_have_panel_power(intel_dp),
2237 "eDP port %c panel power already on\n",
2238 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002239 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002240
Daniel Vetter4be73782014-01-17 14:39:48 +01002241 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002242
Jani Nikulabf13e812013-09-06 07:40:05 +03002243 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002244 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002245 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002246 /* ILK workaround: disable reset around power sequence */
2247 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002248 I915_WRITE(pp_ctrl_reg, pp);
2249 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002250 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002251
Imre Deak5a162e22016-08-10 14:07:30 +03002252 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002253 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002254 pp |= PANEL_POWER_RESET;
2255
Jesse Barnes453c5422013-03-28 09:55:41 -07002256 I915_WRITE(pp_ctrl_reg, pp);
2257 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002258
Daniel Vetter4be73782014-01-17 14:39:48 +01002259 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002260 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002261
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002262 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002263 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002264 I915_WRITE(pp_ctrl_reg, pp);
2265 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002266 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002267}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002268
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002269void intel_edp_panel_on(struct intel_dp *intel_dp)
2270{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002271 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002272 return;
2273
2274 pps_lock(intel_dp);
2275 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002276 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002277}
2278
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002279
2280static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002281{
Paulo Zanoni30add222012-10-26 19:05:45 -02002282 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002283 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002284 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002285 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002286
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002287 lockdep_assert_held(&dev_priv->pps_mutex);
2288
Jani Nikula1853a9d2017-08-18 12:30:20 +03002289 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002290 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002291
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002292 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2293 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002294
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002295 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2296 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002297
Jesse Barnes453c5422013-03-28 09:55:41 -07002298 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002299 /* We need to switch off panel power _and_ force vdd, for otherwise some
2300 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002301 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002302 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002303
Jani Nikulabf13e812013-09-06 07:40:05 +03002304 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002305
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002306 intel_dp->want_panel_vdd = false;
2307
Jesse Barnes453c5422013-03-28 09:55:41 -07002308 I915_WRITE(pp_ctrl_reg, pp);
2309 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002310
Abhay Kumard28d4732016-01-22 17:39:04 -08002311 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002312 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002313
2314 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002315 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002316}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002317
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002318void intel_edp_panel_off(struct intel_dp *intel_dp)
2319{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002320 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002321 return;
2322
2323 pps_lock(intel_dp);
2324 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002325 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002326}
2327
Jani Nikula1250d102014-08-12 17:11:39 +03002328/* Enable backlight in the panel power control. */
2329static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002330{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002331 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2332 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002333 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002334 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002335 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002336
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002337 /*
2338 * If we enable the backlight right away following a panel power
2339 * on, we may see slight flicker as the panel syncs with the eDP
2340 * link. So delay a bit to make sure the image is solid before
2341 * allowing it to appear.
2342 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002343 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002344
Ville Syrjälä773538e82014-09-04 14:54:56 +03002345 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002346
Jesse Barnes453c5422013-03-28 09:55:41 -07002347 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002348 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002349
Jani Nikulabf13e812013-09-06 07:40:05 +03002350 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002351
2352 I915_WRITE(pp_ctrl_reg, pp);
2353 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002354
Ville Syrjälä773538e82014-09-04 14:54:56 +03002355 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002356}
2357
Jani Nikula1250d102014-08-12 17:11:39 +03002358/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002359void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2360 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002361{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002362 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2363
Jani Nikula1853a9d2017-08-18 12:30:20 +03002364 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002365 return;
2366
2367 DRM_DEBUG_KMS("\n");
2368
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002369 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002370 _intel_edp_backlight_on(intel_dp);
2371}
2372
2373/* Disable backlight in the panel power control. */
2374static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002375{
Paulo Zanoni30add222012-10-26 19:05:45 -02002376 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002377 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002378 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002379 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002380
Jani Nikula1853a9d2017-08-18 12:30:20 +03002381 if (!intel_dp_is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07002382 return;
2383
Ville Syrjälä773538e82014-09-04 14:54:56 +03002384 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002385
Jesse Barnes453c5422013-03-28 09:55:41 -07002386 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002387 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002388
Jani Nikulabf13e812013-09-06 07:40:05 +03002389 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002390
2391 I915_WRITE(pp_ctrl_reg, pp);
2392 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002393
Ville Syrjälä773538e82014-09-04 14:54:56 +03002394 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002395
Paulo Zanonidce56b32013-12-19 14:29:40 -02002396 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002397 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002398}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002399
Jani Nikula1250d102014-08-12 17:11:39 +03002400/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002401void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002402{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002403 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2404
Jani Nikula1853a9d2017-08-18 12:30:20 +03002405 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002406 return;
2407
2408 DRM_DEBUG_KMS("\n");
2409
2410 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002411 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002412}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002413
Jani Nikula73580fb72014-08-12 17:11:41 +03002414/*
2415 * Hook for controlling the panel power control backlight through the bl_power
2416 * sysfs attribute. Take care to handle multiple calls.
2417 */
2418static void intel_edp_backlight_power(struct intel_connector *connector,
2419 bool enable)
2420{
2421 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002422 bool is_enabled;
2423
Ville Syrjälä773538e82014-09-04 14:54:56 +03002424 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002425 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002426 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002427
2428 if (is_enabled == enable)
2429 return;
2430
Jani Nikula23ba9372014-08-27 14:08:43 +03002431 DRM_DEBUG_KMS("panel power control backlight %s\n",
2432 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002433
2434 if (enable)
2435 _intel_edp_backlight_on(intel_dp);
2436 else
2437 _intel_edp_backlight_off(intel_dp);
2438}
2439
Ville Syrjälä64e10772015-10-29 21:26:01 +02002440static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2441{
2442 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2443 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2444 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2445
2446 I915_STATE_WARN(cur_state != state,
2447 "DP port %c state assertion failure (expected %s, current %s)\n",
2448 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002449 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002450}
2451#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2452
2453static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2454{
2455 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2456
2457 I915_STATE_WARN(cur_state != state,
2458 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002459 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002460}
2461#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2462#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2463
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002464static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002465 const struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002466{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002467 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002468 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002469
Ville Syrjälä64e10772015-10-29 21:26:01 +02002470 assert_pipe_disabled(dev_priv, crtc->pipe);
2471 assert_dp_port_disabled(intel_dp);
2472 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002473
Ville Syrjäläabfce942015-10-29 21:26:03 +02002474 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002475 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002476
2477 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2478
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002479 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002480 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2481 else
2482 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2483
2484 I915_WRITE(DP_A, intel_dp->DP);
2485 POSTING_READ(DP_A);
2486 udelay(500);
2487
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002488 /*
2489 * [DevILK] Work around required when enabling DP PLL
2490 * while a pipe is enabled going to FDI:
2491 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2492 * 2. Program DP PLL enable
2493 */
2494 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002495 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002496
Daniel Vetter07679352012-09-06 22:15:42 +02002497 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002498
Daniel Vetter07679352012-09-06 22:15:42 +02002499 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002500 POSTING_READ(DP_A);
2501 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002502}
2503
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002504static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002505{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002506 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002507 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2508 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002509
Ville Syrjälä64e10772015-10-29 21:26:01 +02002510 assert_pipe_disabled(dev_priv, crtc->pipe);
2511 assert_dp_port_disabled(intel_dp);
2512 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002513
Ville Syrjäläabfce942015-10-29 21:26:03 +02002514 DRM_DEBUG_KMS("disabling eDP PLL\n");
2515
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002516 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002517
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002518 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002519 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002520 udelay(200);
2521}
2522
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002523/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002524void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002525{
2526 int ret, i;
2527
2528 /* Should have a valid DPCD by this point */
2529 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2530 return;
2531
2532 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002533 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2534 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002535 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002536 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2537
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002538 /*
2539 * When turning on, we need to retry for 1ms to give the sink
2540 * time to wake up.
2541 */
2542 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002543 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2544 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002545 if (ret == 1)
2546 break;
2547 msleep(1);
2548 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002549
2550 if (ret == 1 && lspcon->active)
2551 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002552 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002553
2554 if (ret != 1)
2555 DRM_DEBUG_KMS("failed to %s sink power state\n",
2556 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002557}
2558
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002559static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2560 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002561{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002562 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002563 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002564 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002565 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002566 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002567 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002568
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002569 if (!intel_display_power_get_if_enabled(dev_priv,
2570 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002571 return false;
2572
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002573 ret = false;
2574
Imre Deak6d129be2014-03-05 16:20:54 +02002575 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002576
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002577 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002578 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002579
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002580 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002581 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002582 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002583 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002584
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002585 for_each_pipe(dev_priv, p) {
2586 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2587 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2588 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002589 ret = true;
2590
2591 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002592 }
2593 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002594
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002595 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002596 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002597 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002598 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2599 } else {
2600 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002601 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002602
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002603 ret = true;
2604
2605out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002606 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002607
2608 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002609}
2610
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002611static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002612 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002613{
2614 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002615 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002616 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002617 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002618 enum port port = dp_to_dig_port(intel_dp)->port;
2619 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002620
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002621 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002622
2623 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002624
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002625 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002626 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2627
2628 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002629 flags |= DRM_MODE_FLAG_PHSYNC;
2630 else
2631 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002632
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002633 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002634 flags |= DRM_MODE_FLAG_PVSYNC;
2635 else
2636 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002637 } else {
2638 if (tmp & DP_SYNC_HS_HIGH)
2639 flags |= DRM_MODE_FLAG_PHSYNC;
2640 else
2641 flags |= DRM_MODE_FLAG_NHSYNC;
2642
2643 if (tmp & DP_SYNC_VS_HIGH)
2644 flags |= DRM_MODE_FLAG_PVSYNC;
2645 else
2646 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002647 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002648
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002649 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002650
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002651 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002652 pipe_config->limited_color_range = true;
2653
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002654 pipe_config->lane_count =
2655 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2656
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002657 intel_dp_get_m_n(crtc, pipe_config);
2658
Ville Syrjälä18442d02013-09-13 16:00:08 +03002659 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002660 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002661 pipe_config->port_clock = 162000;
2662 else
2663 pipe_config->port_clock = 270000;
2664 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002665
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002666 pipe_config->base.adjusted_mode.crtc_clock =
2667 intel_dotclock_calculate(pipe_config->port_clock,
2668 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002669
Jani Nikula1853a9d2017-08-18 12:30:20 +03002670 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02002671 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002672 /*
2673 * This is a big fat ugly hack.
2674 *
2675 * Some machines in UEFI boot mode provide us a VBT that has 18
2676 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2677 * unknown we fail to light up. Yet the same BIOS boots up with
2678 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2679 * max, not what it tells us to use.
2680 *
2681 * Note: This will still be broken if the eDP panel is not lit
2682 * up by the BIOS, and thus we can't get the mode at module
2683 * load.
2684 */
2685 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002686 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2687 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002688 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002689}
2690
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002691static void intel_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002692 const struct intel_crtc_state *old_crtc_state,
2693 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002694{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002695 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002696
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002697 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002698 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002699
2700 /* Make sure the panel is off before trying to change the mode. But also
2701 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002702 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002703 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002704 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002705 intel_edp_panel_off(intel_dp);
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002706}
2707
2708static void g4x_disable_dp(struct intel_encoder *encoder,
2709 const struct intel_crtc_state *old_crtc_state,
2710 const struct drm_connector_state *old_conn_state)
2711{
2712 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2713
2714 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Daniel Vetter37398502012-09-06 22:15:44 +02002715
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002716 /* disable the port before the pipe on g4x */
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03002717 intel_dp_link_down(intel_dp);
2718}
2719
2720static void ilk_disable_dp(struct intel_encoder *encoder,
2721 const struct intel_crtc_state *old_crtc_state,
2722 const struct drm_connector_state *old_conn_state)
2723{
2724 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2725}
2726
2727static void vlv_disable_dp(struct intel_encoder *encoder,
2728 const struct intel_crtc_state *old_crtc_state,
2729 const struct drm_connector_state *old_conn_state)
2730{
2731 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2732
2733 intel_psr_disable(intel_dp, old_crtc_state);
2734
2735 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
Jesse Barnesd240f202010-08-13 15:43:26 -07002736}
2737
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002738static void ilk_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002739 const struct intel_crtc_state *old_crtc_state,
2740 const struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002741{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002742 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002743 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002744
Ville Syrjälä49277c32014-03-31 18:21:26 +03002745 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002746
2747 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002748 if (port == PORT_A)
2749 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002750}
2751
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002752static void vlv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002753 const struct intel_crtc_state *old_crtc_state,
2754 const struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002755{
2756 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2757
2758 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002759}
2760
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002761static void chv_post_disable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002762 const struct intel_crtc_state *old_crtc_state,
2763 const struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002764{
2765 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002766 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002767 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002768
2769 intel_dp_link_down(intel_dp);
2770
Ville Syrjäläa5805162015-05-26 20:42:30 +03002771 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002772
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002773 /* Assert data lane reset */
2774 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002775
Ville Syrjäläa5805162015-05-26 20:42:30 +03002776 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002777}
2778
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002779static void
2780_intel_dp_set_link_train(struct intel_dp *intel_dp,
2781 uint32_t *DP,
2782 uint8_t dp_train_pat)
2783{
2784 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2785 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002786 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002787 enum port port = intel_dig_port->port;
2788
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002789 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2790 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2791 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2792
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002793 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002794 uint32_t temp = I915_READ(DP_TP_CTL(port));
2795
2796 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2797 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2798 else
2799 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2800
2801 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2802 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2803 case DP_TRAINING_PATTERN_DISABLE:
2804 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2805
2806 break;
2807 case DP_TRAINING_PATTERN_1:
2808 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2809 break;
2810 case DP_TRAINING_PATTERN_2:
2811 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2812 break;
2813 case DP_TRAINING_PATTERN_3:
2814 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2815 break;
2816 }
2817 I915_WRITE(DP_TP_CTL(port), temp);
2818
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002819 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002820 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002821 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2822
2823 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2824 case DP_TRAINING_PATTERN_DISABLE:
2825 *DP |= DP_LINK_TRAIN_OFF_CPT;
2826 break;
2827 case DP_TRAINING_PATTERN_1:
2828 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2829 break;
2830 case DP_TRAINING_PATTERN_2:
2831 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2832 break;
2833 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002834 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002835 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2836 break;
2837 }
2838
2839 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002840 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002841 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2842 else
2843 *DP &= ~DP_LINK_TRAIN_MASK;
2844
2845 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2846 case DP_TRAINING_PATTERN_DISABLE:
2847 *DP |= DP_LINK_TRAIN_OFF;
2848 break;
2849 case DP_TRAINING_PATTERN_1:
2850 *DP |= DP_LINK_TRAIN_PAT_1;
2851 break;
2852 case DP_TRAINING_PATTERN_2:
2853 *DP |= DP_LINK_TRAIN_PAT_2;
2854 break;
2855 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002856 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002857 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2858 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002859 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002860 *DP |= DP_LINK_TRAIN_PAT_2;
2861 }
2862 break;
2863 }
2864 }
2865}
2866
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002867static void intel_dp_enable_port(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002868 const struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002869{
2870 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002871 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002872
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002873 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002874
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002875 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002876
2877 /*
2878 * Magic for VLV/CHV. We _must_ first set up the register
2879 * without actually enabling the port, and then do another
2880 * write to enable the port. Otherwise link training will
2881 * fail when the power sequencer is freshly used for this port.
2882 */
2883 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002884 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002885 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002886
2887 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2888 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002889}
2890
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002891static void intel_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002892 const struct intel_crtc_state *pipe_config,
2893 const struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002894{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002895 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2896 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002897 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002898 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002899 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002900 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002901
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002902 if (WARN_ON(dp_reg & DP_PORT_EN))
2903 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002904
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002905 pps_lock(intel_dp);
2906
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002907 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002908 vlv_init_panel_power_sequencer(intel_dp);
2909
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002910 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002911
2912 edp_panel_vdd_on(intel_dp);
2913 edp_panel_on(intel_dp);
2914 edp_panel_vdd_off(intel_dp, true);
2915
2916 pps_unlock(intel_dp);
2917
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002918 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002919 unsigned int lane_mask = 0x0;
2920
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002921 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002922 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002923
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002924 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2925 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002926 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002927
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002928 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2929 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002930 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002931
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002932 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002933 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002934 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002935 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002936 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002937}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002938
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002939static void g4x_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002940 const struct intel_crtc_state *pipe_config,
2941 const struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002942{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002943 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002944 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002945}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002946
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002947static void vlv_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002948 const struct intel_crtc_state *pipe_config,
2949 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002950{
Jani Nikula828f5c62013-09-05 16:44:45 +03002951 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2952
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002953 intel_edp_backlight_on(pipe_config, conn_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002954 intel_psr_enable(intel_dp, pipe_config);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002955}
2956
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002957static void g4x_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002958 const struct intel_crtc_state *pipe_config,
2959 const struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002960{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002961 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002962 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002963
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002964 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002965
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002966 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002967 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002968 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002969}
2970
Ville Syrjälä83b84592014-10-16 21:29:51 +03002971static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2972{
2973 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002974 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002975 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002976 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002977
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002978 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2979
Ville Syrjäläd1586942017-02-08 19:52:54 +02002980 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2981 return;
2982
Ville Syrjälä83b84592014-10-16 21:29:51 +03002983 edp_panel_vdd_off_sync(intel_dp);
2984
2985 /*
2986 * VLV seems to get confused when multiple power seqeuencers
2987 * have the same port selected (even if only one has power/vdd
2988 * enabled). The failure manifests as vlv_wait_port_ready() failing
2989 * CHV on the other hand doesn't seem to mind having the same port
2990 * selected in multiple power seqeuencers, but let's clear the
2991 * port select always when logically disconnecting a power sequencer
2992 * from a port.
2993 */
2994 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2995 pipe_name(pipe), port_name(intel_dig_port->port));
2996 I915_WRITE(pp_on_reg, 0);
2997 POSTING_READ(pp_on_reg);
2998
2999 intel_dp->pps_pipe = INVALID_PIPE;
3000}
3001
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003002static void vlv_steal_power_sequencer(struct drm_device *dev,
3003 enum pipe pipe)
3004{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003005 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003006 struct intel_encoder *encoder;
3007
3008 lockdep_assert_held(&dev_priv->pps_mutex);
3009
Jani Nikula19c80542015-12-16 12:48:16 +02003010 for_each_intel_encoder(dev, 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ä773538e82014-09-04 14:54:56 +03003019 port = dp_to_dig_port(intel_dp)->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
3036static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
3037{
3038 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3039 struct intel_encoder *encoder = &intel_dig_port->base;
3040 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003041 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003042 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003043
3044 lockdep_assert_held(&dev_priv->pps_mutex);
3045
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003046 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003047
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003048 if (intel_dp->pps_pipe != INVALID_PIPE &&
3049 intel_dp->pps_pipe != crtc->pipe) {
3050 /*
3051 * If another power sequencer was being used on this
3052 * port previously make sure to turn off vdd there while
3053 * we still have control of it.
3054 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003055 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003056 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003057
3058 /*
3059 * We may be stealing the power
3060 * sequencer from another port.
3061 */
3062 vlv_steal_power_sequencer(dev, crtc->pipe);
3063
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003064 intel_dp->active_pipe = crtc->pipe;
3065
Jani Nikula1853a9d2017-08-18 12:30:20 +03003066 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003067 return;
3068
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003069 /* now it's all ours */
3070 intel_dp->pps_pipe = crtc->pipe;
3071
3072 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3073 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3074
3075 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003076 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003077 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003078}
3079
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003080static void vlv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003081 const struct intel_crtc_state *pipe_config,
3082 const struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003083{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003084 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003085
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003086 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003087}
3088
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003089static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003090 const struct intel_crtc_state *pipe_config,
3091 const struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003092{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003093 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003094
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003095 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003096}
3097
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003098static void chv_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003099 const struct intel_crtc_state *pipe_config,
3100 const struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003101{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003102 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003103
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003104 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003105
3106 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003107 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003108}
3109
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003110static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003111 const struct intel_crtc_state *pipe_config,
3112 const struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003113{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003114 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003115
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003116 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003117}
3118
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003119static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003120 const struct intel_crtc_state *pipe_config,
3121 const struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003122{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003123 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003124}
3125
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003126/*
3127 * Fetch AUX CH registers 0x202 - 0x207 which contain
3128 * link status information
3129 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003130bool
Keith Packard93f62da2011-11-01 19:45:03 -07003131intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003132{
Lyude9f085eb2016-04-13 10:58:33 -04003133 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3134 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003135}
3136
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303137static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3138{
3139 uint8_t psr_caps = 0;
3140
Imre Deak9bacd4b2017-05-10 12:21:48 +03003141 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3142 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303143 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3144}
3145
3146static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3147{
3148 uint8_t dprx = 0;
3149
Imre Deak9bacd4b2017-05-10 12:21:48 +03003150 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3151 &dprx) != 1)
3152 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303153 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3154}
3155
Chris Wilsona76f73d2017-01-14 10:51:13 +00003156static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303157{
3158 uint8_t alpm_caps = 0;
3159
Imre Deak9bacd4b2017-05-10 12:21:48 +03003160 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3161 &alpm_caps) != 1)
3162 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303163 return alpm_caps & DP_ALPM_CAP;
3164}
3165
Paulo Zanoni11002442014-06-13 18:45:41 -03003166/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003167uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003168intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003169{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003170 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003171 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003172
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003173 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303174 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003175 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003176 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3177 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003178 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303179 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003180 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303181 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003182 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303183 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003184 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003186}
3187
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003188uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003189intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3190{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003191 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003192 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003193
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003194 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003195 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3197 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3198 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3199 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3200 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3201 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303202 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3203 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003204 default:
3205 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3206 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003207 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003208 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303209 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3210 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3211 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3212 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3213 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3214 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003216 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303217 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003218 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003219 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003220 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303221 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3222 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3223 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3224 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3225 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3226 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3227 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003228 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003230 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003231 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003232 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303233 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3234 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3236 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3237 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003238 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303239 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003240 }
3241 } else {
3242 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303243 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3244 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3245 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3246 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3247 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3248 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3249 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003250 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303251 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003252 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003253 }
3254}
3255
Daniel Vetter5829975c2015-04-16 11:36:52 +02003256static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003257{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003258 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003259 unsigned long demph_reg_value, preemph_reg_value,
3260 uniqtranscale_reg_value;
3261 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003262
3263 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303264 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003265 preemph_reg_value = 0x0004000;
3266 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303267 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003268 demph_reg_value = 0x2B405555;
3269 uniqtranscale_reg_value = 0x552AB83A;
3270 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003272 demph_reg_value = 0x2B404040;
3273 uniqtranscale_reg_value = 0x5548B83A;
3274 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003276 demph_reg_value = 0x2B245555;
3277 uniqtranscale_reg_value = 0x5560B83A;
3278 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303279 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003280 demph_reg_value = 0x2B405555;
3281 uniqtranscale_reg_value = 0x5598DA3A;
3282 break;
3283 default:
3284 return 0;
3285 }
3286 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003288 preemph_reg_value = 0x0002000;
3289 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003291 demph_reg_value = 0x2B404040;
3292 uniqtranscale_reg_value = 0x5552B83A;
3293 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303294 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003295 demph_reg_value = 0x2B404848;
3296 uniqtranscale_reg_value = 0x5580B83A;
3297 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303298 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003299 demph_reg_value = 0x2B404040;
3300 uniqtranscale_reg_value = 0x55ADDA3A;
3301 break;
3302 default:
3303 return 0;
3304 }
3305 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303306 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003307 preemph_reg_value = 0x0000000;
3308 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303309 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003310 demph_reg_value = 0x2B305555;
3311 uniqtranscale_reg_value = 0x5570B83A;
3312 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303313 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003314 demph_reg_value = 0x2B2B4040;
3315 uniqtranscale_reg_value = 0x55ADDA3A;
3316 break;
3317 default:
3318 return 0;
3319 }
3320 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003322 preemph_reg_value = 0x0006000;
3323 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003325 demph_reg_value = 0x1B405555;
3326 uniqtranscale_reg_value = 0x55ADDA3A;
3327 break;
3328 default:
3329 return 0;
3330 }
3331 break;
3332 default:
3333 return 0;
3334 }
3335
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003336 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3337 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003338
3339 return 0;
3340}
3341
Daniel Vetter5829975c2015-04-16 11:36:52 +02003342static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003343{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003344 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3345 u32 deemph_reg_value, margin_reg_value;
3346 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003347 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003348
3349 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303350 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003351 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303352 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003353 deemph_reg_value = 128;
3354 margin_reg_value = 52;
3355 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303356 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003357 deemph_reg_value = 128;
3358 margin_reg_value = 77;
3359 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003361 deemph_reg_value = 128;
3362 margin_reg_value = 102;
3363 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303364 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003365 deemph_reg_value = 128;
3366 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003367 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003368 break;
3369 default:
3370 return 0;
3371 }
3372 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303373 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003374 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303375 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003376 deemph_reg_value = 85;
3377 margin_reg_value = 78;
3378 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003380 deemph_reg_value = 85;
3381 margin_reg_value = 116;
3382 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003384 deemph_reg_value = 85;
3385 margin_reg_value = 154;
3386 break;
3387 default:
3388 return 0;
3389 }
3390 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303391 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003392 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303393 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003394 deemph_reg_value = 64;
3395 margin_reg_value = 104;
3396 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303397 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003398 deemph_reg_value = 64;
3399 margin_reg_value = 154;
3400 break;
3401 default:
3402 return 0;
3403 }
3404 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303405 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003406 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303407 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003408 deemph_reg_value = 43;
3409 margin_reg_value = 154;
3410 break;
3411 default:
3412 return 0;
3413 }
3414 break;
3415 default:
3416 return 0;
3417 }
3418
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003419 chv_set_phy_signal_level(encoder, deemph_reg_value,
3420 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003421
3422 return 0;
3423}
3424
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003425static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003426gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003427{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003428 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003429
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003430 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303431 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003432 default:
3433 signal_levels |= DP_VOLTAGE_0_4;
3434 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303435 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003436 signal_levels |= DP_VOLTAGE_0_6;
3437 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303438 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003439 signal_levels |= DP_VOLTAGE_0_8;
3440 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303441 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003442 signal_levels |= DP_VOLTAGE_1_2;
3443 break;
3444 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003445 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303446 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003447 default:
3448 signal_levels |= DP_PRE_EMPHASIS_0;
3449 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303450 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003451 signal_levels |= DP_PRE_EMPHASIS_3_5;
3452 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303453 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003454 signal_levels |= DP_PRE_EMPHASIS_6;
3455 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303456 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003457 signal_levels |= DP_PRE_EMPHASIS_9_5;
3458 break;
3459 }
3460 return signal_levels;
3461}
3462
Zhenyu Wange3421a12010-04-08 09:43:27 +08003463/* Gen6's DP voltage swing and pre-emphasis control */
3464static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003465gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003466{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003467 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3468 DP_TRAIN_PRE_EMPHASIS_MASK);
3469 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303470 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3471 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003472 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303473 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003474 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303475 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3476 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003477 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303478 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003480 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303481 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3482 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003483 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003484 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003485 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3486 "0x%x\n", signal_levels);
3487 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003488 }
3489}
3490
Keith Packard1a2eb462011-11-16 16:26:07 -08003491/* Gen7's DP voltage swing and pre-emphasis control */
3492static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003493gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003494{
3495 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3496 DP_TRAIN_PRE_EMPHASIS_MASK);
3497 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303498 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003499 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303500 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003501 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303502 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003503 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3504
Sonika Jindalbd600182014-08-08 16:23:41 +05303505 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003506 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303507 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003508 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3509
Sonika Jindalbd600182014-08-08 16:23:41 +05303510 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003511 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303512 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003513 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3514
3515 default:
3516 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3517 "0x%x\n", signal_levels);
3518 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3519 }
3520}
3521
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003522void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003523intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003524{
3525 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003526 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003527 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003528 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003529 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003530 uint8_t train_set = intel_dp->train_set[0];
3531
Rodrigo Vivid509af62017-08-29 16:22:24 -07003532 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3533 signal_levels = bxt_signal_levels(intel_dp);
3534 } else if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003535 signal_levels = ddi_signal_levels(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07003536 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003537 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003538 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003539 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003540 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003541 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003542 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003543 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003544 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003545 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003546 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3547 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003548 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003549 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3550 }
3551
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303552 if (mask)
3553 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3554
3555 DRM_DEBUG_KMS("Using vswing level %d\n",
3556 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3557 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3558 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3559 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003560
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003561 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003562
3563 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3564 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003565}
3566
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003567void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003568intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3569 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003570{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003571 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003572 struct drm_i915_private *dev_priv =
3573 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003574
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003575 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003576
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003577 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003578 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003579}
3580
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003581void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003582{
3583 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3584 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003585 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003586 enum port port = intel_dig_port->port;
3587 uint32_t val;
3588
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003589 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003590 return;
3591
3592 val = I915_READ(DP_TP_CTL(port));
3593 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3594 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3595 I915_WRITE(DP_TP_CTL(port), val);
3596
3597 /*
3598 * On PORT_A we can have only eDP in SST mode. There the only reason
3599 * we need to set idle transmission mode is to work around a HW issue
3600 * where we enable the pipe while not in idle link-training mode.
3601 * In this case there is requirement to wait for a minimum number of
3602 * idle patterns to be sent.
3603 */
3604 if (port == PORT_A)
3605 return;
3606
Chris Wilsona7670172016-06-30 15:33:10 +01003607 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3608 DP_TP_STATUS_IDLE_DONE,
3609 DP_TP_STATUS_IDLE_DONE,
3610 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003611 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3612}
3613
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003614static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003615intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003616{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003617 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003618 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003619 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003620 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003621 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003622 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003623
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003624 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003625 return;
3626
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003627 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003628 return;
3629
Zhao Yakui28c97732009-10-09 11:39:41 +08003630 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003631
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003632 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003633 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003634 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003635 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003636 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003637 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003638 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3639 else
3640 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003641 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003642 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003643 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003644 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003645
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003646 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3647 I915_WRITE(intel_dp->output_reg, DP);
3648 POSTING_READ(intel_dp->output_reg);
3649
3650 /*
3651 * HW workaround for IBX, we need to move the port
3652 * to transcoder A after disabling it to allow the
3653 * matching HDMI port to be enabled on transcoder A.
3654 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003655 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003656 /*
3657 * We get CPU/PCH FIFO underruns on the other pipe when
3658 * doing the workaround. Sweep them under the rug.
3659 */
3660 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3661 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3662
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003663 /* always enable with pattern 1 (as per spec) */
3664 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3665 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3666 I915_WRITE(intel_dp->output_reg, DP);
3667 POSTING_READ(intel_dp->output_reg);
3668
3669 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003670 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003671 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003672
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003673 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003674 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3675 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003676 }
3677
Keith Packardf01eca22011-09-28 16:48:10 -07003678 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003679
3680 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003681
3682 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3683 pps_lock(intel_dp);
3684 intel_dp->active_pipe = INVALID_PIPE;
3685 pps_unlock(intel_dp);
3686 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003687}
3688
Imre Deak24e807e2016-10-24 19:33:28 +03003689bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003690intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003691{
Lyude9f085eb2016-04-13 10:58:33 -04003692 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3693 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003694 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003695
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003696 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003697
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003698 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3699}
3700
3701static bool
3702intel_edp_init_dpcd(struct intel_dp *intel_dp)
3703{
3704 struct drm_i915_private *dev_priv =
3705 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3706
3707 /* this function is meant to be called only once */
3708 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3709
3710 if (!intel_dp_read_dpcd(intel_dp))
3711 return false;
3712
Jani Nikula84c36752017-05-18 14:10:23 +03003713 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3714 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003715
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003716 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3717 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3718 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3719
3720 /* Check if the panel supports PSR */
3721 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3722 intel_dp->psr_dpcd,
3723 sizeof(intel_dp->psr_dpcd));
3724 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3725 dev_priv->psr.sink_support = true;
3726 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3727 }
3728
3729 if (INTEL_GEN(dev_priv) >= 9 &&
3730 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3731 uint8_t frame_sync_cap;
3732
3733 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003734 if (drm_dp_dpcd_readb(&intel_dp->aux,
3735 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3736 &frame_sync_cap) != 1)
3737 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003738 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3739 /* PSR2 needs frame sync as well */
3740 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3741 DRM_DEBUG_KMS("PSR2 %s on sink",
3742 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303743
3744 if (dev_priv->psr.psr2_support) {
3745 dev_priv->psr.y_cord_support =
3746 intel_dp_get_y_cord_status(intel_dp);
3747 dev_priv->psr.colorimetry_support =
3748 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303749 dev_priv->psr.alpm =
3750 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303751 }
3752
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003753 }
3754
3755 /* Read the eDP Display control capabilities registers */
3756 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3757 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003758 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3759 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003760 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3761 intel_dp->edp_dpcd);
3762
3763 /* Intermediate frequency support */
3764 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3765 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3766 int i;
3767
3768 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3769 sink_rates, sizeof(sink_rates));
3770
3771 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3772 int val = le16_to_cpu(sink_rates[i]);
3773
3774 if (val == 0)
3775 break;
3776
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003777 /* Value read multiplied by 200kHz gives the per-lane
3778 * link rate in kHz. The source rates are, however,
3779 * stored in terms of LS_Clk kHz. The full conversion
3780 * back to symbols is
3781 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3782 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003783 intel_dp->sink_rates[i] = (val * 200) / 10;
3784 }
3785 intel_dp->num_sink_rates = i;
3786 }
3787
Jani Nikula68f357c2017-03-28 17:59:05 +03003788 if (intel_dp->num_sink_rates)
3789 intel_dp->use_rate_select = true;
3790 else
3791 intel_dp_set_sink_rates(intel_dp);
3792
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003793 intel_dp_set_common_rates(intel_dp);
3794
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003795 return true;
3796}
3797
3798
3799static bool
3800intel_dp_get_dpcd(struct intel_dp *intel_dp)
3801{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003802 u8 sink_count;
3803
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003804 if (!intel_dp_read_dpcd(intel_dp))
3805 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003806
Jani Nikula68f357c2017-03-28 17:59:05 +03003807 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003808 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003809 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003810 intel_dp_set_common_rates(intel_dp);
3811 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003812
Jani Nikula27dbefb2017-04-06 16:44:17 +03003813 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303814 return false;
3815
3816 /*
3817 * Sink count can change between short pulse hpd hence
3818 * a member variable in intel_dp will track any changes
3819 * between short pulse interrupts.
3820 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003821 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303822
3823 /*
3824 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3825 * a dongle is present but no display. Unless we require to know
3826 * if a dongle is present or not, we don't need to update
3827 * downstream port information. So, an early return here saves
3828 * time from performing other operations which are not required.
3829 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003830 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303831 return false;
3832
Imre Deakc726ad02016-10-24 19:33:24 +03003833 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003834 return true; /* native DP sink */
3835
3836 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3837 return true; /* no per-port downstream info */
3838
Lyude9f085eb2016-04-13 10:58:33 -04003839 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3840 intel_dp->downstream_ports,
3841 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003842 return false; /* downstream port status fetch failed */
3843
3844 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003845}
3846
Dave Airlie0e32b392014-05-02 14:02:48 +10003847static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003848intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003849{
Jani Nikula010b9b32017-04-06 16:44:16 +03003850 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003851
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003852 if (!i915_modparams.enable_dp_mst)
Nathan Schulte7cc96132016-03-15 10:14:05 -05003853 return false;
3854
Dave Airlie0e32b392014-05-02 14:02:48 +10003855 if (!intel_dp->can_mst)
3856 return false;
3857
3858 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3859 return false;
3860
Jani Nikula010b9b32017-04-06 16:44:16 +03003861 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003862 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003863
Jani Nikula010b9b32017-04-06 16:44:16 +03003864 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003865}
3866
3867static void
3868intel_dp_configure_mst(struct intel_dp *intel_dp)
3869{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003870 if (!i915_modparams.enable_dp_mst)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003871 return;
3872
3873 if (!intel_dp->can_mst)
3874 return;
3875
3876 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3877
3878 if (intel_dp->is_mst)
3879 DRM_DEBUG_KMS("Sink is MST capable\n");
3880 else
3881 DRM_DEBUG_KMS("Sink is not MST capable\n");
3882
3883 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3884 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003885}
3886
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003887static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003888{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003889 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003890 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003891 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003892 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003893 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003894 int count = 0;
3895 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003896
3897 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003898 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003899 ret = -EIO;
3900 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003901 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003902
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003903 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003904 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003905 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003906 ret = -EIO;
3907 goto out;
3908 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003909
Rodrigo Vivic6297842015-11-05 10:50:20 -08003910 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003911 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003912
3913 if (drm_dp_dpcd_readb(&intel_dp->aux,
3914 DP_TEST_SINK_MISC, &buf) < 0) {
3915 ret = -EIO;
3916 goto out;
3917 }
3918 count = buf & DP_TEST_COUNT_MASK;
3919 } while (--attempts && count);
3920
3921 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003922 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003923 ret = -ETIMEDOUT;
3924 }
3925
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003926 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003927 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003928 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003929}
3930
3931static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3932{
3933 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003934 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003935 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3936 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003937 int ret;
3938
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003939 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3940 return -EIO;
3941
3942 if (!(buf & DP_TEST_CRC_SUPPORTED))
3943 return -ENOTTY;
3944
3945 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3946 return -EIO;
3947
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003948 if (buf & DP_TEST_SINK_START) {
3949 ret = intel_dp_sink_crc_stop(intel_dp);
3950 if (ret)
3951 return ret;
3952 }
3953
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003954 hsw_disable_ips(intel_crtc);
3955
3956 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3957 buf | DP_TEST_SINK_START) < 0) {
3958 hsw_enable_ips(intel_crtc);
3959 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003960 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003961
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003962 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003963 return 0;
3964}
3965
3966int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3967{
3968 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003969 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003970 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3971 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003972 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003973 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003974
3975 ret = intel_dp_sink_crc_start(intel_dp);
3976 if (ret)
3977 return ret;
3978
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003979 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003980 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003981
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003982 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003983 DP_TEST_SINK_MISC, &buf) < 0) {
3984 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003985 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003986 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003987 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003988
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003989 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003990
3991 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003992 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3993 ret = -ETIMEDOUT;
3994 goto stop;
3995 }
3996
3997 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3998 ret = -EIO;
3999 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004000 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004001
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004002stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004003 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004004 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004005}
4006
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004007static bool
4008intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4009{
Jani Nikula010b9b32017-04-06 16:44:16 +03004010 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4011 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004012}
4013
Dave Airlie0e32b392014-05-02 14:02:48 +10004014static bool
4015intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4016{
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004017 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4018 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4019 DP_DPRX_ESI_LEN;
Dave Airlie0e32b392014-05-02 14:02:48 +10004020}
4021
Todd Previtec5d5ab72015-04-15 08:38:38 -07004022static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004023{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004024 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004025 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004026 uint8_t test_lane_count, test_link_bw;
4027 /* (DP CTS 1.2)
4028 * 4.3.1.11
4029 */
4030 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4031 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4032 &test_lane_count);
4033
4034 if (status <= 0) {
4035 DRM_DEBUG_KMS("Lane count read failed\n");
4036 return DP_TEST_NAK;
4037 }
4038 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004039
4040 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4041 &test_link_bw);
4042 if (status <= 0) {
4043 DRM_DEBUG_KMS("Link Rate read failed\n");
4044 return DP_TEST_NAK;
4045 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004046 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004047
4048 /* Validate the requested link rate and lane count */
4049 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4050 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004051 return DP_TEST_NAK;
4052
4053 intel_dp->compliance.test_lane_count = test_lane_count;
4054 intel_dp->compliance.test_link_rate = test_link_rate;
4055
4056 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004057}
4058
4059static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4060{
Manasi Navare611032b2017-01-24 08:21:49 -08004061 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004062 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004063 __be16 h_width, v_height;
4064 int status = 0;
4065
4066 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004067 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4068 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004069 if (status <= 0) {
4070 DRM_DEBUG_KMS("Test pattern read failed\n");
4071 return DP_TEST_NAK;
4072 }
4073 if (test_pattern != DP_COLOR_RAMP)
4074 return DP_TEST_NAK;
4075
4076 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4077 &h_width, 2);
4078 if (status <= 0) {
4079 DRM_DEBUG_KMS("H Width read failed\n");
4080 return DP_TEST_NAK;
4081 }
4082
4083 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4084 &v_height, 2);
4085 if (status <= 0) {
4086 DRM_DEBUG_KMS("V Height read failed\n");
4087 return DP_TEST_NAK;
4088 }
4089
Jani Nikula010b9b32017-04-06 16:44:16 +03004090 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4091 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004092 if (status <= 0) {
4093 DRM_DEBUG_KMS("TEST MISC read failed\n");
4094 return DP_TEST_NAK;
4095 }
4096 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4097 return DP_TEST_NAK;
4098 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4099 return DP_TEST_NAK;
4100 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4101 case DP_TEST_BIT_DEPTH_6:
4102 intel_dp->compliance.test_data.bpc = 6;
4103 break;
4104 case DP_TEST_BIT_DEPTH_8:
4105 intel_dp->compliance.test_data.bpc = 8;
4106 break;
4107 default:
4108 return DP_TEST_NAK;
4109 }
4110
4111 intel_dp->compliance.test_data.video_pattern = test_pattern;
4112 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4113 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4114 /* Set test active flag here so userspace doesn't interrupt things */
4115 intel_dp->compliance.test_active = 1;
4116
4117 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004118}
4119
4120static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4121{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004122 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004123 struct intel_connector *intel_connector = intel_dp->attached_connector;
4124 struct drm_connector *connector = &intel_connector->base;
4125
4126 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004127 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004128 intel_dp->aux.i2c_defer_count > 6) {
4129 /* Check EDID read for NACKs, DEFERs and corruption
4130 * (DP CTS 1.2 Core r1.1)
4131 * 4.2.2.4 : Failed EDID read, I2C_NAK
4132 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4133 * 4.2.2.6 : EDID corruption detected
4134 * Use failsafe mode for all cases
4135 */
4136 if (intel_dp->aux.i2c_nack_count > 0 ||
4137 intel_dp->aux.i2c_defer_count > 0)
4138 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4139 intel_dp->aux.i2c_nack_count,
4140 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004141 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004142 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304143 struct edid *block = intel_connector->detect_edid;
4144
4145 /* We have to write the checksum
4146 * of the last block read
4147 */
4148 block += intel_connector->detect_edid->extensions;
4149
Jani Nikula010b9b32017-04-06 16:44:16 +03004150 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4151 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004152 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4153
4154 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004155 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004156 }
4157
4158 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004159 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004160
Todd Previtec5d5ab72015-04-15 08:38:38 -07004161 return test_result;
4162}
4163
4164static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4165{
4166 uint8_t test_result = DP_TEST_NAK;
4167 return test_result;
4168}
4169
4170static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4171{
4172 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004173 uint8_t request = 0;
4174 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004175
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004176 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004177 if (status <= 0) {
4178 DRM_DEBUG_KMS("Could not read test request from sink\n");
4179 goto update_status;
4180 }
4181
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004182 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004183 case DP_TEST_LINK_TRAINING:
4184 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004185 response = intel_dp_autotest_link_training(intel_dp);
4186 break;
4187 case DP_TEST_LINK_VIDEO_PATTERN:
4188 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004189 response = intel_dp_autotest_video_pattern(intel_dp);
4190 break;
4191 case DP_TEST_LINK_EDID_READ:
4192 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004193 response = intel_dp_autotest_edid(intel_dp);
4194 break;
4195 case DP_TEST_LINK_PHY_TEST_PATTERN:
4196 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004197 response = intel_dp_autotest_phy_pattern(intel_dp);
4198 break;
4199 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004200 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004201 break;
4202 }
4203
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004204 if (response & DP_TEST_ACK)
4205 intel_dp->compliance.test_type = request;
4206
Todd Previtec5d5ab72015-04-15 08:38:38 -07004207update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004208 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004209 if (status <= 0)
4210 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004211}
4212
Dave Airlie0e32b392014-05-02 14:02:48 +10004213static int
4214intel_dp_check_mst_status(struct intel_dp *intel_dp)
4215{
4216 bool bret;
4217
4218 if (intel_dp->is_mst) {
Pandiyan, Dhinakarane8b25772017-09-18 15:21:39 -07004219 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
Dave Airlie0e32b392014-05-02 14:02:48 +10004220 int ret = 0;
4221 int retry;
4222 bool handled;
4223 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4224go_again:
4225 if (bret == true) {
4226
4227 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004228 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004229 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004230 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4231 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004232 intel_dp_stop_link_train(intel_dp);
4233 }
4234
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004235 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004236 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4237
4238 if (handled) {
4239 for (retry = 0; retry < 3; retry++) {
4240 int wret;
4241 wret = drm_dp_dpcd_write(&intel_dp->aux,
4242 DP_SINK_COUNT_ESI+1,
4243 &esi[1], 3);
4244 if (wret == 3) {
4245 break;
4246 }
4247 }
4248
4249 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4250 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004251 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004252 goto go_again;
4253 }
4254 } else
4255 ret = 0;
4256
4257 return ret;
4258 } else {
4259 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4260 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4261 intel_dp->is_mst = false;
4262 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4263 /* send a hotplug event */
4264 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4265 }
4266 }
4267 return -EINVAL;
4268}
4269
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304270static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004271intel_dp_retrain_link(struct intel_dp *intel_dp)
4272{
4273 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4274 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4275 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4276
4277 /* Suppress underruns caused by re-training */
4278 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4279 if (crtc->config->has_pch_encoder)
4280 intel_set_pch_fifo_underrun_reporting(dev_priv,
4281 intel_crtc_pch_transcoder(crtc), false);
4282
4283 intel_dp_start_link_train(intel_dp);
4284 intel_dp_stop_link_train(intel_dp);
4285
4286 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004287 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004288
4289 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4290 if (crtc->config->has_pch_encoder)
4291 intel_set_pch_fifo_underrun_reporting(dev_priv,
4292 intel_crtc_pch_transcoder(crtc), true);
4293}
4294
4295static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304296intel_dp_check_link_status(struct intel_dp *intel_dp)
4297{
4298 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4299 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4300 u8 link_status[DP_LINK_STATUS_SIZE];
4301
4302 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4303
4304 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4305 DRM_ERROR("Failed to get link status\n");
4306 return;
4307 }
4308
4309 if (!intel_encoder->base.crtc)
4310 return;
4311
4312 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4313 return;
4314
Manasi Navare14c562c2017-04-06 14:00:12 -07004315 /*
4316 * Validate the cached values of intel_dp->link_rate and
4317 * intel_dp->lane_count before attempting to retrain.
4318 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004319 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4320 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004321 return;
4322
Manasi Navareda15f7c2017-01-24 08:16:34 -08004323 /* Retrain if Channel EQ or CR not ok */
4324 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304325 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4326 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004327
4328 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304329 }
4330}
4331
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004332/*
4333 * According to DP spec
4334 * 5.1.2:
4335 * 1. Read DPCD
4336 * 2. Configure link according to Receiver Capabilities
4337 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4338 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304339 *
4340 * intel_dp_short_pulse - handles short pulse interrupts
4341 * when full detection is not required.
4342 * Returns %true if short pulse is handled and full detection
4343 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004344 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304345static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304346intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004347{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004348 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004349 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004350 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304351 u8 old_sink_count = intel_dp->sink_count;
4352 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004353
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304354 /*
4355 * Clearing compliance test variables to allow capturing
4356 * of values for next automated test request.
4357 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004358 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304359
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304360 /*
4361 * Now read the DPCD to see if it's actually running
4362 * If the current value of sink count doesn't match with
4363 * the value that was stored earlier or dpcd read failed
4364 * we need to do full detection
4365 */
4366 ret = intel_dp_get_dpcd(intel_dp);
4367
4368 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4369 /* No need to proceed if we are going to do full detect */
4370 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004371 }
4372
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004373 /* Try to read the source of the interrupt */
4374 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004375 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4376 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004377 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004378 drm_dp_dpcd_writeb(&intel_dp->aux,
4379 DP_DEVICE_SERVICE_IRQ_VECTOR,
4380 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004381
4382 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004383 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004384 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4385 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4386 }
4387
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304388 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4389 intel_dp_check_link_status(intel_dp);
4390 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004391 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4392 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4393 /* Send a Hotplug Uevent to userspace to start modeset */
4394 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4395 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304396
4397 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004398}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004399
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004400/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004401static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004402intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004403{
Imre Deake393d0d2017-02-22 17:10:52 +02004404 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004405 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004406 uint8_t type;
4407
Imre Deake393d0d2017-02-22 17:10:52 +02004408 if (lspcon->active)
4409 lspcon_resume(lspcon);
4410
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004411 if (!intel_dp_get_dpcd(intel_dp))
4412 return connector_status_disconnected;
4413
Jani Nikula1853a9d2017-08-18 12:30:20 +03004414 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304415 return connector_status_connected;
4416
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004417 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004418 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004419 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004420
4421 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004422 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4423 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004424
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304425 return intel_dp->sink_count ?
4426 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004427 }
4428
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004429 if (intel_dp_can_mst(intel_dp))
4430 return connector_status_connected;
4431
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004432 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004433 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004434 return connector_status_connected;
4435
4436 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004437 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4438 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4439 if (type == DP_DS_PORT_TYPE_VGA ||
4440 type == DP_DS_PORT_TYPE_NON_EDID)
4441 return connector_status_unknown;
4442 } else {
4443 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4444 DP_DWN_STRM_PORT_TYPE_MASK;
4445 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4446 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4447 return connector_status_unknown;
4448 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004449
4450 /* Anything else is out of spec, warn and ignore */
4451 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004452 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004453}
4454
4455static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004456edp_detect(struct intel_dp *intel_dp)
4457{
4458 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004459 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004460 enum drm_connector_status status;
4461
Mika Kahola1650be72016-12-13 10:02:47 +02004462 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004463 if (status == connector_status_unknown)
4464 status = connector_status_connected;
4465
4466 return status;
4467}
4468
Jani Nikulab93433c2015-08-20 10:47:36 +03004469static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4470 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004471{
Jani Nikulab93433c2015-08-20 10:47:36 +03004472 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004473
Jani Nikula0df53b72015-08-20 10:47:40 +03004474 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004475 case PORT_B:
4476 bit = SDE_PORTB_HOTPLUG;
4477 break;
4478 case PORT_C:
4479 bit = SDE_PORTC_HOTPLUG;
4480 break;
4481 case PORT_D:
4482 bit = SDE_PORTD_HOTPLUG;
4483 break;
4484 default:
4485 MISSING_CASE(port->port);
4486 return false;
4487 }
4488
4489 return I915_READ(SDEISR) & bit;
4490}
4491
4492static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4493 struct intel_digital_port *port)
4494{
4495 u32 bit;
4496
4497 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004498 case PORT_B:
4499 bit = SDE_PORTB_HOTPLUG_CPT;
4500 break;
4501 case PORT_C:
4502 bit = SDE_PORTC_HOTPLUG_CPT;
4503 break;
4504 case PORT_D:
4505 bit = SDE_PORTD_HOTPLUG_CPT;
4506 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004507 default:
4508 MISSING_CASE(port->port);
4509 return false;
4510 }
4511
4512 return I915_READ(SDEISR) & bit;
4513}
4514
4515static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4516 struct intel_digital_port *port)
4517{
4518 u32 bit;
4519
4520 switch (port->port) {
4521 case PORT_A:
4522 bit = SDE_PORTA_HOTPLUG_SPT;
4523 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004524 case PORT_E:
4525 bit = SDE_PORTE_HOTPLUG_SPT;
4526 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004527 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004528 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004529 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004530
Jani Nikulab93433c2015-08-20 10:47:36 +03004531 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004532}
4533
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004534static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004535 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004536{
Jani Nikula9642c812015-08-20 10:47:41 +03004537 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004538
Jani Nikula9642c812015-08-20 10:47:41 +03004539 switch (port->port) {
4540 case PORT_B:
4541 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4542 break;
4543 case PORT_C:
4544 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4545 break;
4546 case PORT_D:
4547 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4548 break;
4549 default:
4550 MISSING_CASE(port->port);
4551 return false;
4552 }
4553
4554 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4555}
4556
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004557static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4558 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004559{
4560 u32 bit;
4561
4562 switch (port->port) {
4563 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004564 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004565 break;
4566 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004567 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004568 break;
4569 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004570 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004571 break;
4572 default:
4573 MISSING_CASE(port->port);
4574 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004575 }
4576
Jani Nikula1d245982015-08-20 10:47:37 +03004577 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004578}
4579
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004580static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4581 struct intel_digital_port *port)
4582{
4583 if (port->port == PORT_A)
4584 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4585 else
4586 return ibx_digital_port_connected(dev_priv, port);
4587}
4588
4589static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4590 struct intel_digital_port *port)
4591{
4592 if (port->port == PORT_A)
4593 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4594 else
4595 return cpt_digital_port_connected(dev_priv, port);
4596}
4597
4598static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4599 struct intel_digital_port *port)
4600{
4601 if (port->port == PORT_A)
4602 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4603 else
4604 return cpt_digital_port_connected(dev_priv, port);
4605}
4606
4607static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4608 struct intel_digital_port *port)
4609{
4610 if (port->port == PORT_A)
4611 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4612 else
4613 return cpt_digital_port_connected(dev_priv, port);
4614}
4615
Jani Nikulae464bfd2015-08-20 10:47:42 +03004616static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304617 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004618{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304619 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4620 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004621 u32 bit;
4622
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07004623 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304624 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004625 case PORT_A:
4626 bit = BXT_DE_PORT_HP_DDIA;
4627 break;
4628 case PORT_B:
4629 bit = BXT_DE_PORT_HP_DDIB;
4630 break;
4631 case PORT_C:
4632 bit = BXT_DE_PORT_HP_DDIC;
4633 break;
4634 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304635 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004636 return false;
4637 }
4638
4639 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4640}
4641
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004642/*
4643 * intel_digital_port_connected - is the specified port connected?
4644 * @dev_priv: i915 private structure
4645 * @port: the port to test
4646 *
4647 * Return %true if @port is connected, %false otherwise.
4648 */
Imre Deak390b4e02017-01-27 11:39:19 +02004649bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4650 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004651{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004652 if (HAS_GMCH_DISPLAY(dev_priv)) {
4653 if (IS_GM45(dev_priv))
4654 return gm45_digital_port_connected(dev_priv, port);
4655 else
4656 return g4x_digital_port_connected(dev_priv, port);
4657 }
4658
4659 if (IS_GEN5(dev_priv))
4660 return ilk_digital_port_connected(dev_priv, port);
4661 else if (IS_GEN6(dev_priv))
4662 return snb_digital_port_connected(dev_priv, port);
4663 else if (IS_GEN7(dev_priv))
4664 return ivb_digital_port_connected(dev_priv, port);
4665 else if (IS_GEN8(dev_priv))
4666 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004667 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004668 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004669 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004670 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004671}
4672
Keith Packard8c241fe2011-09-28 16:38:44 -07004673static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004674intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004675{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004676 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004677
Jani Nikula9cd300e2012-10-19 14:51:52 +03004678 /* use cached edid if we have one */
4679 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004680 /* invalid edid */
4681 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004682 return NULL;
4683
Jani Nikula55e9ede2013-10-01 10:38:54 +03004684 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004685 } else
4686 return drm_get_edid(&intel_connector->base,
4687 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004688}
4689
Chris Wilsonbeb60602014-09-02 20:04:00 +01004690static void
4691intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004692{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004693 struct intel_connector *intel_connector = intel_dp->attached_connector;
4694 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004695
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304696 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004697 edid = intel_dp_get_edid(intel_dp);
4698 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004699
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004700 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004701}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004702
Chris Wilsonbeb60602014-09-02 20:04:00 +01004703static void
4704intel_dp_unset_edid(struct intel_dp *intel_dp)
4705{
4706 struct intel_connector *intel_connector = intel_dp->attached_connector;
4707
4708 kfree(intel_connector->detect_edid);
4709 intel_connector->detect_edid = NULL;
4710
4711 intel_dp->has_audio = false;
4712}
4713
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004714static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304715intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004716{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304717 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004718 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004719 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4720 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004721 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004722 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004723 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004724
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004725 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4726
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004727 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004728
Chris Wilsond410b562014-09-02 20:03:59 +01004729 /* Can't disconnect eDP, but you can close the lid... */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004730 if (intel_dp_is_edp(intel_dp))
Chris Wilsond410b562014-09-02 20:03:59 +01004731 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004732 else if (intel_digital_port_connected(to_i915(dev),
4733 dp_to_dig_port(intel_dp)))
4734 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004735 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004736 status = connector_status_disconnected;
4737
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004738 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004739 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304740
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004741 if (intel_dp->is_mst) {
4742 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4743 intel_dp->is_mst,
4744 intel_dp->mst_mgr.mst_state);
4745 intel_dp->is_mst = false;
4746 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4747 intel_dp->is_mst);
4748 }
4749
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004750 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304751 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004752
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304753 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004754 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304755
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004756 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4757 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4758 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4759
Manasi Navared7e8ef02017-02-07 16:54:11 -08004760 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004761 /* Initial max link lane count */
4762 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004763
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004764 /* Initial max link rate */
4765 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004766
4767 intel_dp->reset_link_params = false;
4768 }
Manasi Navaref4829842016-12-05 16:27:36 -08004769
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004770 intel_dp_print_rates(intel_dp);
4771
Jani Nikula84c36752017-05-18 14:10:23 +03004772 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4773 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004774
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004775 intel_dp_configure_mst(intel_dp);
4776
4777 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304778 /*
4779 * If we are in MST mode then this connector
4780 * won't appear connected or have anything
4781 * with EDID on it
4782 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004783 status = connector_status_disconnected;
4784 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004785 } else {
4786 /*
4787 * If display is now connected check links status,
4788 * there has been known issues of link loss triggerring
4789 * long pulse.
4790 *
4791 * Some sinks (eg. ASUS PB287Q) seem to perform some
4792 * weird HPD ping pong during modesets. So we can apparently
4793 * end up with HPD going low during a modeset, and then
4794 * going back up soon after. And once that happens we must
4795 * retrain the link to get a picture. That's in case no
4796 * userspace component reacted to intermittent HPD dip.
4797 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304798 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004799 }
4800
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304801 /*
4802 * Clearing NACK and defer counts to get their exact values
4803 * while reading EDID which are required by Compliance tests
4804 * 4.2.2.4 and 4.2.2.5
4805 */
4806 intel_dp->aux.i2c_nack_count = 0;
4807 intel_dp->aux.i2c_defer_count = 0;
4808
Chris Wilsonbeb60602014-09-02 20:04:00 +01004809 intel_dp_set_edid(intel_dp);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004810 if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004811 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304812 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004813
Todd Previte09b1eb12015-04-20 15:27:34 -07004814 /* Try to read the source of the interrupt */
4815 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004816 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4817 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004818 /* Clear interrupt source */
4819 drm_dp_dpcd_writeb(&intel_dp->aux,
4820 DP_DEVICE_SERVICE_IRQ_VECTOR,
4821 sink_irq_vector);
4822
4823 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4824 intel_dp_handle_test_request(intel_dp);
4825 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4826 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4827 }
4828
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004829out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004830 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304831 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304832
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004833 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004834 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304835}
4836
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004837static int
4838intel_dp_detect(struct drm_connector *connector,
4839 struct drm_modeset_acquire_ctx *ctx,
4840 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304841{
4842 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004843 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304844
4845 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4846 connector->base.id, connector->name);
4847
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304848 /* If full detect is not performed yet, do a full detect */
4849 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004850 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304851
4852 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304853
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004854 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004855}
4856
Chris Wilsonbeb60602014-09-02 20:04:00 +01004857static void
4858intel_dp_force(struct drm_connector *connector)
4859{
4860 struct intel_dp *intel_dp = intel_attached_dp(connector);
4861 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004862 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004863
4864 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4865 connector->base.id, connector->name);
4866 intel_dp_unset_edid(intel_dp);
4867
4868 if (connector->status != connector_status_connected)
4869 return;
4870
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004871 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004872
4873 intel_dp_set_edid(intel_dp);
4874
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004875 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004876
4877 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004878 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004879}
4880
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004881static int intel_dp_get_modes(struct drm_connector *connector)
4882{
Jani Nikuladd06f902012-10-19 14:51:50 +03004883 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004884 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004885
Chris Wilsonbeb60602014-09-02 20:04:00 +01004886 edid = intel_connector->detect_edid;
4887 if (edid) {
4888 int ret = intel_connector_update_modes(connector, edid);
4889 if (ret)
4890 return ret;
4891 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004892
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004893 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004894 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004895 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004896 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004897
4898 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004899 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004900 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004901 drm_mode_probed_add(connector, mode);
4902 return 1;
4903 }
4904 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004905
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004906 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004907}
4908
Chris Wilsonf6849602010-09-19 09:29:33 +01004909static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004910intel_dp_connector_register(struct drm_connector *connector)
4911{
4912 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004913 int ret;
4914
4915 ret = intel_connector_register(connector);
4916 if (ret)
4917 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004918
4919 i915_debugfs_connector_add(connector);
4920
4921 DRM_DEBUG_KMS("registering %s bus for %s\n",
4922 intel_dp->aux.name, connector->kdev->kobj.name);
4923
4924 intel_dp->aux.dev = connector->kdev;
4925 return drm_dp_aux_register(&intel_dp->aux);
4926}
4927
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004928static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004929intel_dp_connector_unregister(struct drm_connector *connector)
4930{
4931 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4932 intel_connector_unregister(connector);
4933}
4934
4935static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004936intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004937{
Jani Nikula1d508702012-10-19 14:51:49 +03004938 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004939
Chris Wilson10e972d2014-09-04 21:43:45 +01004940 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004941
Jani Nikula9cd300e2012-10-19 14:51:52 +03004942 if (!IS_ERR_OR_NULL(intel_connector->edid))
4943 kfree(intel_connector->edid);
4944
Jani Nikula1853a9d2017-08-18 12:30:20 +03004945 /*
4946 * Can't call intel_dp_is_edp() since the encoder may have been
4947 * destroyed already.
4948 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004949 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004950 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004951
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004952 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004953 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004954}
4955
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004956void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004957{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004958 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4959 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004960
Dave Airlie0e32b392014-05-02 14:02:48 +10004961 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004962 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004963 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004964 /*
4965 * vdd might still be enabled do to the delayed vdd off.
4966 * Make sure vdd is actually turned off here.
4967 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004968 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004969 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004970 pps_unlock(intel_dp);
4971
Clint Taylor01527b32014-07-07 13:01:46 -07004972 if (intel_dp->edp_notifier.notifier_call) {
4973 unregister_reboot_notifier(&intel_dp->edp_notifier);
4974 intel_dp->edp_notifier.notifier_call = NULL;
4975 }
Keith Packardbd943152011-09-18 23:09:52 -07004976 }
Chris Wilson99681882016-06-20 09:29:17 +01004977
4978 intel_dp_aux_fini(intel_dp);
4979
Imre Deakc8bd0e42014-12-12 17:57:38 +02004980 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004981 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004982}
4983
Imre Deakbf93ba62016-04-18 10:04:21 +03004984void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004985{
4986 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4987
Jani Nikula1853a9d2017-08-18 12:30:20 +03004988 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03004989 return;
4990
Ville Syrjälä951468f2014-09-04 14:55:31 +03004991 /*
4992 * vdd might still be enabled do to the delayed vdd off.
4993 * Make sure vdd is actually turned off here.
4994 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004995 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004996 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004997 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004998 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004999}
5000
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005001static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
5002{
5003 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5004 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005005 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005006
5007 lockdep_assert_held(&dev_priv->pps_mutex);
5008
5009 if (!edp_have_panel_vdd(intel_dp))
5010 return;
5011
5012 /*
5013 * The VDD bit needs a power domain reference, so if the bit is
5014 * already enabled when we boot or resume, grab this reference and
5015 * schedule a vdd off, so we don't hold on to the reference
5016 * indefinitely.
5017 */
5018 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005019 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005020
5021 edp_panel_vdd_schedule_off(intel_dp);
5022}
5023
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005024static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5025{
5026 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5027
5028 if ((intel_dp->DP & DP_PORT_EN) == 0)
5029 return INVALID_PIPE;
5030
5031 if (IS_CHERRYVIEW(dev_priv))
5032 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5033 else
5034 return PORT_TO_PIPE(intel_dp->DP);
5035}
5036
Imre Deakbf93ba62016-04-18 10:04:21 +03005037void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005038{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005039 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005040 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5041 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005042
5043 if (!HAS_DDI(dev_priv))
5044 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005045
Imre Deakdd75f6d2016-11-21 21:15:05 +02005046 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305047 lspcon_resume(lspcon);
5048
Manasi Navared7e8ef02017-02-07 16:54:11 -08005049 intel_dp->reset_link_params = true;
5050
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005051 pps_lock(intel_dp);
5052
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005053 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5054 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5055
Jani Nikula1853a9d2017-08-18 12:30:20 +03005056 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005057 /* Reinit the power sequencer, in case BIOS did something with it. */
5058 intel_dp_pps_init(encoder->dev, intel_dp);
5059 intel_edp_panel_vdd_sanitize(intel_dp);
5060 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005061
5062 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005063}
5064
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005065static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005066 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005067 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005068 .atomic_get_property = intel_digital_connector_atomic_get_property,
5069 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005070 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005071 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005072 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005073 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005074 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005075};
5076
5077static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005078 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005079 .get_modes = intel_dp_get_modes,
5080 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005081 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005082};
5083
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005084static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005085 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005086 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005087};
5088
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005089enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005090intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5091{
5092 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005093 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005094 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005095 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005096
Takashi Iwai25400582015-11-19 12:09:56 +01005097 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5098 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005099 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005100
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005101 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5102 /*
5103 * vdd off can generate a long pulse on eDP which
5104 * would require vdd on to handle it, and thus we
5105 * would end up in an endless cycle of
5106 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5107 */
5108 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5109 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005110 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005111 }
5112
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005113 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5114 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005115 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005116
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005117 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005118 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005119 intel_dp->detect_done = false;
5120 return IRQ_NONE;
5121 }
5122
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005123 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005124
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005125 if (intel_dp->is_mst) {
5126 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5127 /*
5128 * If we were in MST mode, and device is not
5129 * there, get out of MST mode
5130 */
5131 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5132 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5133 intel_dp->is_mst = false;
5134 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5135 intel_dp->is_mst);
5136 intel_dp->detect_done = false;
5137 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005138 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005139 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005140
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005141 if (!intel_dp->is_mst) {
5142 if (!intel_dp_short_pulse(intel_dp)) {
5143 intel_dp->detect_done = false;
5144 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305145 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005146 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005147
5148 ret = IRQ_HANDLED;
5149
Imre Deak1c767b32014-08-18 14:42:42 +03005150put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005151 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005152
5153 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005154}
5155
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005156/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005157bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005158{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005159 /*
5160 * eDP not supported on g4x. so bail out early just
5161 * for a bit extra safety in case the VBT is bonkers.
5162 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005163 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005164 return false;
5165
Imre Deaka98d9c12016-12-21 12:17:24 +02005166 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005167 return true;
5168
Jani Nikula951d9ef2016-03-16 12:43:31 +02005169 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005170}
5171
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005172static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005173intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5174{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005175 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5176
Chris Wilson3f43c482011-05-12 22:17:24 +01005177 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005178 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005179
Jani Nikula1853a9d2017-08-18 12:30:20 +03005180 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005181 u32 allowed_scalers;
5182
5183 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5184 if (!HAS_GMCH_DISPLAY(dev_priv))
5185 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5186
5187 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5188
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005189 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005190
Yuly Novikov53b41832012-10-26 12:04:00 +03005191 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005192}
5193
Imre Deakdada1a92014-01-29 13:25:41 +02005194static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5195{
Abhay Kumard28d4732016-01-22 17:39:04 -08005196 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005197 intel_dp->last_power_on = jiffies;
5198 intel_dp->last_backlight_off = jiffies;
5199}
5200
Daniel Vetter67a54562012-10-20 20:57:45 +02005201static void
Imre Deak54648612016-06-16 16:37:22 +03005202intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5203 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005204{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305205 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005206 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005207
Imre Deak8e8232d2016-06-16 16:37:21 +03005208 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005209
5210 /* Workaround: Need to write PP_CONTROL with the unlock key as
5211 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305212 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005213
Imre Deak8e8232d2016-06-16 16:37:21 +03005214 pp_on = I915_READ(regs.pp_on);
5215 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005216 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005217 I915_WRITE(regs.pp_ctrl, pp_ctl);
5218 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305219 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005220
5221 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005222 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5223 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005224
Imre Deak54648612016-06-16 16:37:22 +03005225 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5226 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005227
Imre Deak54648612016-06-16 16:37:22 +03005228 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5229 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005230
Imre Deak54648612016-06-16 16:37:22 +03005231 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5232 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005233
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005234 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005235 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5236 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305237 } else {
Imre Deak54648612016-06-16 16:37:22 +03005238 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005239 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305240 }
Imre Deak54648612016-06-16 16:37:22 +03005241}
5242
5243static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005244intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5245{
5246 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5247 state_name,
5248 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5249}
5250
5251static void
5252intel_pps_verify_state(struct drm_i915_private *dev_priv,
5253 struct intel_dp *intel_dp)
5254{
5255 struct edp_power_seq hw;
5256 struct edp_power_seq *sw = &intel_dp->pps_delays;
5257
5258 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5259
5260 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5261 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5262 DRM_ERROR("PPS state mismatch\n");
5263 intel_pps_dump_state("sw", sw);
5264 intel_pps_dump_state("hw", &hw);
5265 }
5266}
5267
5268static void
Imre Deak54648612016-06-16 16:37:22 +03005269intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5270 struct intel_dp *intel_dp)
5271{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005272 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005273 struct edp_power_seq cur, vbt, spec,
5274 *final = &intel_dp->pps_delays;
5275
5276 lockdep_assert_held(&dev_priv->pps_mutex);
5277
5278 /* already initialized? */
5279 if (final->t11_t12 != 0)
5280 return;
5281
5282 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005283
Imre Deakde9c1b62016-06-16 20:01:46 +03005284 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005285
Jani Nikula6aa23e62016-03-24 17:50:20 +02005286 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005287 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5288 * of 500ms appears to be too short. Ocassionally the panel
5289 * just fails to power back on. Increasing the delay to 800ms
5290 * seems sufficient to avoid this problem.
5291 */
5292 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
Manasi Navaree8f345e2017-08-15 11:59:51 -07005293 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 900 * 10);
Manasi Navarec99a2592017-06-30 09:33:48 -07005294 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5295 vbt.t11_t12);
5296 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005297 /* T11_T12 delay is special and actually in units of 100ms, but zero
5298 * based in the hw (so we need to add 100 ms). But the sw vbt
5299 * table multiplies it with 1000 to make it in units of 100usec,
5300 * too. */
5301 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005302
5303 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5304 * our hw here, which are all in 100usec. */
5305 spec.t1_t3 = 210 * 10;
5306 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5307 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5308 spec.t10 = 500 * 10;
5309 /* This one is special and actually in units of 100ms, but zero
5310 * based in the hw (so we need to add 100 ms). But the sw vbt
5311 * table multiplies it with 1000 to make it in units of 100usec,
5312 * too. */
5313 spec.t11_t12 = (510 + 100) * 10;
5314
Imre Deakde9c1b62016-06-16 20:01:46 +03005315 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005316
5317 /* Use the max of the register settings and vbt. If both are
5318 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005319#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005320 spec.field : \
5321 max(cur.field, vbt.field))
5322 assign_final(t1_t3);
5323 assign_final(t8);
5324 assign_final(t9);
5325 assign_final(t10);
5326 assign_final(t11_t12);
5327#undef assign_final
5328
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005329#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005330 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5331 intel_dp->backlight_on_delay = get_delay(t8);
5332 intel_dp->backlight_off_delay = get_delay(t9);
5333 intel_dp->panel_power_down_delay = get_delay(t10);
5334 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5335#undef get_delay
5336
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005337 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5338 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5339 intel_dp->panel_power_cycle_delay);
5340
5341 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5342 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005343
5344 /*
5345 * We override the HW backlight delays to 1 because we do manual waits
5346 * on them. For T8, even BSpec recommends doing it. For T9, if we
5347 * don't do this, we'll end up waiting for the backlight off delay
5348 * twice: once when we do the manual sleep, and once when we disable
5349 * the panel and wait for the PP_STATUS bit to become zero.
5350 */
5351 final->t8 = 1;
5352 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005353}
5354
5355static void
5356intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005357 struct intel_dp *intel_dp,
5358 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005359{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005360 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005361 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005362 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005363 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005364 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005365 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005366
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005367 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005368
Imre Deak8e8232d2016-06-16 16:37:21 +03005369 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005370
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005371 /*
5372 * On some VLV machines the BIOS can leave the VDD
5373 * enabled even on power seqeuencers which aren't
5374 * hooked up to any port. This would mess up the
5375 * power domain tracking the first time we pick
5376 * one of these power sequencers for use since
5377 * edp_panel_vdd_on() would notice that the VDD was
5378 * already on and therefore wouldn't grab the power
5379 * domain reference. Disable VDD first to avoid this.
5380 * This also avoids spuriously turning the VDD on as
5381 * soon as the new power seqeuencer gets initialized.
5382 */
5383 if (force_disable_vdd) {
5384 u32 pp = ironlake_get_pp_control(intel_dp);
5385
5386 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5387
5388 if (pp & EDP_FORCE_VDD)
5389 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5390
5391 pp &= ~EDP_FORCE_VDD;
5392
5393 I915_WRITE(regs.pp_ctrl, pp);
5394 }
5395
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005396 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005397 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5398 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005399 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005400 /* Compute the divisor for the pp clock, simply match the Bspec
5401 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005402 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005403 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305404 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005405 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305406 << BXT_POWER_CYCLE_DELAY_SHIFT);
5407 } else {
5408 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5409 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5410 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5411 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005412
5413 /* Haswell doesn't have any port selection bits for the panel
5414 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005415 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005416 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005417 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005418 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005419 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005420 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005421 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005422 }
5423
Jesse Barnes453c5422013-03-28 09:55:41 -07005424 pp_on |= port_sel;
5425
Imre Deak8e8232d2016-06-16 16:37:21 +03005426 I915_WRITE(regs.pp_on, pp_on);
5427 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005428 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005429 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305430 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005431 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005432
Daniel Vetter67a54562012-10-20 20:57:45 +02005433 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 +03005434 I915_READ(regs.pp_on),
5435 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005436 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005437 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5438 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005439}
5440
Imre Deak335f7522016-08-10 14:07:32 +03005441static void intel_dp_pps_init(struct drm_device *dev,
5442 struct intel_dp *intel_dp)
5443{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005444 struct drm_i915_private *dev_priv = to_i915(dev);
5445
5446 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005447 vlv_initial_power_sequencer_setup(intel_dp);
5448 } else {
5449 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005450 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005451 }
5452}
5453
Vandana Kannanb33a2812015-02-13 15:33:03 +05305454/**
5455 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005456 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005457 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305458 * @refresh_rate: RR to be programmed
5459 *
5460 * This function gets called when refresh rate (RR) has to be changed from
5461 * one frequency to another. Switches can be between high and low RR
5462 * supported by the panel or to any other RR based on media playback (in
5463 * this case, RR value needs to be passed from user space).
5464 *
5465 * The caller of this function needs to take a lock on dev_priv->drrs.
5466 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005467static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005468 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005469 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305470{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305471 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305472 struct intel_digital_port *dig_port = NULL;
5473 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005474 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305475 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305476
5477 if (refresh_rate <= 0) {
5478 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5479 return;
5480 }
5481
Vandana Kannan96178ee2015-01-10 02:25:56 +05305482 if (intel_dp == NULL) {
5483 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305484 return;
5485 }
5486
Vandana Kannan96178ee2015-01-10 02:25:56 +05305487 dig_port = dp_to_dig_port(intel_dp);
5488 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005489 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305490
5491 if (!intel_crtc) {
5492 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5493 return;
5494 }
5495
Vandana Kannan96178ee2015-01-10 02:25:56 +05305496 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305497 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5498 return;
5499 }
5500
Vandana Kannan96178ee2015-01-10 02:25:56 +05305501 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5502 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305503 index = DRRS_LOW_RR;
5504
Vandana Kannan96178ee2015-01-10 02:25:56 +05305505 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305506 DRM_DEBUG_KMS(
5507 "DRRS requested for previously set RR...ignoring\n");
5508 return;
5509 }
5510
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005511 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305512 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5513 return;
5514 }
5515
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005516 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305517 switch (index) {
5518 case DRRS_HIGH_RR:
5519 intel_dp_set_m_n(intel_crtc, M1_N1);
5520 break;
5521 case DRRS_LOW_RR:
5522 intel_dp_set_m_n(intel_crtc, M2_N2);
5523 break;
5524 case DRRS_MAX_RR:
5525 default:
5526 DRM_ERROR("Unsupported refreshrate type\n");
5527 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005528 } else if (INTEL_GEN(dev_priv) > 6) {
5529 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005530 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305531
Ville Syrjälä649636e2015-09-22 19:50:01 +03005532 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305533 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005534 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305535 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5536 else
5537 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305538 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005539 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305540 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5541 else
5542 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305543 }
5544 I915_WRITE(reg, val);
5545 }
5546
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305547 dev_priv->drrs.refresh_rate_type = index;
5548
5549 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5550}
5551
Vandana Kannanb33a2812015-02-13 15:33:03 +05305552/**
5553 * intel_edp_drrs_enable - init drrs struct if supported
5554 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005555 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305556 *
5557 * Initializes frontbuffer_bits and drrs.dp
5558 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005559void intel_edp_drrs_enable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005560 const struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305561{
5562 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005563 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305564
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005565 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305566 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5567 return;
5568 }
5569
Radhakrishna Sripadada83ef82017-09-14 11:16:41 -07005570 if (dev_priv->psr.enabled) {
5571 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5572 return;
5573 }
5574
Vandana Kannanc3955782015-01-22 15:17:40 +05305575 mutex_lock(&dev_priv->drrs.mutex);
5576 if (WARN_ON(dev_priv->drrs.dp)) {
5577 DRM_ERROR("DRRS already enabled\n");
5578 goto unlock;
5579 }
5580
5581 dev_priv->drrs.busy_frontbuffer_bits = 0;
5582
5583 dev_priv->drrs.dp = intel_dp;
5584
5585unlock:
5586 mutex_unlock(&dev_priv->drrs.mutex);
5587}
5588
Vandana Kannanb33a2812015-02-13 15:33:03 +05305589/**
5590 * intel_edp_drrs_disable - Disable DRRS
5591 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005592 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305593 *
5594 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005595void intel_edp_drrs_disable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005596 const struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305597{
5598 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005599 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305600
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005601 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305602 return;
5603
5604 mutex_lock(&dev_priv->drrs.mutex);
5605 if (!dev_priv->drrs.dp) {
5606 mutex_unlock(&dev_priv->drrs.mutex);
5607 return;
5608 }
5609
5610 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005611 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5612 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305613
5614 dev_priv->drrs.dp = NULL;
5615 mutex_unlock(&dev_priv->drrs.mutex);
5616
5617 cancel_delayed_work_sync(&dev_priv->drrs.work);
5618}
5619
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305620static void intel_edp_drrs_downclock_work(struct work_struct *work)
5621{
5622 struct drm_i915_private *dev_priv =
5623 container_of(work, typeof(*dev_priv), drrs.work.work);
5624 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305625
Vandana Kannan96178ee2015-01-10 02:25:56 +05305626 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305627
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305628 intel_dp = dev_priv->drrs.dp;
5629
5630 if (!intel_dp)
5631 goto unlock;
5632
5633 /*
5634 * The delayed work can race with an invalidate hence we need to
5635 * recheck.
5636 */
5637
5638 if (dev_priv->drrs.busy_frontbuffer_bits)
5639 goto unlock;
5640
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005641 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5642 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5643
5644 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5645 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5646 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305647
5648unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305649 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305650}
5651
Vandana Kannanb33a2812015-02-13 15:33:03 +05305652/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305653 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005654 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305655 * @frontbuffer_bits: frontbuffer plane tracking bits
5656 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305657 * This function gets called everytime rendering on the given planes start.
5658 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305659 *
5660 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5661 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005662void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5663 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305664{
Vandana Kannana93fad02015-01-10 02:25:59 +05305665 struct drm_crtc *crtc;
5666 enum pipe pipe;
5667
Daniel Vetter9da7d692015-04-09 16:44:15 +02005668 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305669 return;
5670
Daniel Vetter88f933a2015-04-09 16:44:16 +02005671 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305672
Vandana Kannana93fad02015-01-10 02:25:59 +05305673 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005674 if (!dev_priv->drrs.dp) {
5675 mutex_unlock(&dev_priv->drrs.mutex);
5676 return;
5677 }
5678
Vandana Kannana93fad02015-01-10 02:25:59 +05305679 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5680 pipe = to_intel_crtc(crtc)->pipe;
5681
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005682 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5683 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5684
Ramalingam C0ddfd202015-06-15 20:50:05 +05305685 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005686 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005687 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5688 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305689
Vandana Kannana93fad02015-01-10 02:25:59 +05305690 mutex_unlock(&dev_priv->drrs.mutex);
5691}
5692
Vandana Kannanb33a2812015-02-13 15:33:03 +05305693/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305694 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005695 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305696 * @frontbuffer_bits: frontbuffer plane tracking bits
5697 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305698 * This function gets called every time rendering on the given planes has
5699 * completed or flip on a crtc is completed. So DRRS should be upclocked
5700 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5701 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305702 *
5703 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5704 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005705void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5706 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305707{
Vandana Kannana93fad02015-01-10 02:25:59 +05305708 struct drm_crtc *crtc;
5709 enum pipe pipe;
5710
Daniel Vetter9da7d692015-04-09 16:44:15 +02005711 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305712 return;
5713
Daniel Vetter88f933a2015-04-09 16:44:16 +02005714 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305715
Vandana Kannana93fad02015-01-10 02:25:59 +05305716 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005717 if (!dev_priv->drrs.dp) {
5718 mutex_unlock(&dev_priv->drrs.mutex);
5719 return;
5720 }
5721
Vandana Kannana93fad02015-01-10 02:25:59 +05305722 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5723 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005724
5725 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305726 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5727
Ramalingam C0ddfd202015-06-15 20:50:05 +05305728 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005729 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005730 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5731 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305732
5733 /*
5734 * flush also means no more activity hence schedule downclock, if all
5735 * other fbs are quiescent too
5736 */
5737 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305738 schedule_delayed_work(&dev_priv->drrs.work,
5739 msecs_to_jiffies(1000));
5740 mutex_unlock(&dev_priv->drrs.mutex);
5741}
5742
Vandana Kannanb33a2812015-02-13 15:33:03 +05305743/**
5744 * DOC: Display Refresh Rate Switching (DRRS)
5745 *
5746 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5747 * which enables swtching between low and high refresh rates,
5748 * dynamically, based on the usage scenario. This feature is applicable
5749 * for internal panels.
5750 *
5751 * Indication that the panel supports DRRS is given by the panel EDID, which
5752 * would list multiple refresh rates for one resolution.
5753 *
5754 * DRRS is of 2 types - static and seamless.
5755 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5756 * (may appear as a blink on screen) and is used in dock-undock scenario.
5757 * Seamless DRRS involves changing RR without any visual effect to the user
5758 * and can be used during normal system usage. This is done by programming
5759 * certain registers.
5760 *
5761 * Support for static/seamless DRRS may be indicated in the VBT based on
5762 * inputs from the panel spec.
5763 *
5764 * DRRS saves power by switching to low RR based on usage scenarios.
5765 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005766 * The implementation is based on frontbuffer tracking implementation. When
5767 * there is a disturbance on the screen triggered by user activity or a periodic
5768 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5769 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5770 * made.
5771 *
5772 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5773 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305774 *
5775 * DRRS can be further extended to support other internal panels and also
5776 * the scenario of video playback wherein RR is set based on the rate
5777 * requested by userspace.
5778 */
5779
5780/**
5781 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5782 * @intel_connector: eDP connector
5783 * @fixed_mode: preferred mode of panel
5784 *
5785 * This function is called only once at driver load to initialize basic
5786 * DRRS stuff.
5787 *
5788 * Returns:
5789 * Downclock mode if panel supports it, else return NULL.
5790 * DRRS support is determined by the presence of downclock mode (apart
5791 * from VBT setting).
5792 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305793static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305794intel_dp_drrs_init(struct intel_connector *intel_connector,
5795 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305796{
5797 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305798 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005799 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305800 struct drm_display_mode *downclock_mode = NULL;
5801
Daniel Vetter9da7d692015-04-09 16:44:15 +02005802 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5803 mutex_init(&dev_priv->drrs.mutex);
5804
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005805 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305806 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5807 return NULL;
5808 }
5809
5810 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005811 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305812 return NULL;
5813 }
5814
5815 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005816 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305817
5818 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305819 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305820 return NULL;
5821 }
5822
Vandana Kannan96178ee2015-01-10 02:25:56 +05305823 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305824
Vandana Kannan96178ee2015-01-10 02:25:56 +05305825 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005826 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305827 return downclock_mode;
5828}
5829
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005830static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005831 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005832{
5833 struct drm_connector *connector = &intel_connector->base;
5834 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005835 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5836 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005837 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005838 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07005839 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305840 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005841 bool has_dpcd;
5842 struct drm_display_mode *scan;
5843 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005844 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005845
Jani Nikula1853a9d2017-08-18 12:30:20 +03005846 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005847 return true;
5848
Imre Deak97a824e12016-06-21 11:51:47 +03005849 /*
5850 * On IBX/CPT we may get here with LVDS already registered. Since the
5851 * driver uses the only internal power sequencer available for both
5852 * eDP and LVDS bail out early in this case to prevent interfering
5853 * with an already powered-on LVDS power sequencer.
5854 */
5855 if (intel_get_lvds_encoder(dev)) {
5856 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5857 DRM_INFO("LVDS was detected, not registering eDP\n");
5858
5859 return false;
5860 }
5861
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005862 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005863
5864 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005865 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005866 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005867
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005868 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005869
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005870 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005871 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005872
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005873 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005874 /* if this fails, presume the device is a ghost */
5875 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005876 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005877 }
5878
Daniel Vetter060c8772014-03-21 23:22:35 +01005879 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005880 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005881 if (edid) {
5882 if (drm_add_edid_modes(connector, edid)) {
5883 drm_mode_connector_update_edid_property(connector,
5884 edid);
5885 drm_edid_to_eld(connector, edid);
5886 } else {
5887 kfree(edid);
5888 edid = ERR_PTR(-EINVAL);
5889 }
5890 } else {
5891 edid = ERR_PTR(-ENOENT);
5892 }
5893 intel_connector->edid = edid;
5894
Jim Bridedc911f52017-08-09 12:48:53 -07005895 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005896 list_for_each_entry(scan, &connector->probed_modes, head) {
5897 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5898 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305899 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305900 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07005901 } else if (!alt_fixed_mode) {
5902 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005903 }
5904 }
5905
5906 /* fallback to VBT if available for eDP */
5907 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5908 fixed_mode = drm_mode_duplicate(dev,
5909 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005910 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005911 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005912 connector->display_info.width_mm = fixed_mode->width_mm;
5913 connector->display_info.height_mm = fixed_mode->height_mm;
5914 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005915 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005916 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005917
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005918 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005919 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5920 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005921
5922 /*
5923 * Figure out the current pipe for the initial backlight setup.
5924 * If the current pipe isn't valid, try the PPS pipe, and if that
5925 * fails just assume pipe A.
5926 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005927 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005928
5929 if (pipe != PIPE_A && pipe != PIPE_B)
5930 pipe = intel_dp->pps_pipe;
5931
5932 if (pipe != PIPE_A && pipe != PIPE_B)
5933 pipe = PIPE_A;
5934
5935 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5936 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005937 }
5938
Jim Bridedc911f52017-08-09 12:48:53 -07005939 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5940 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005941 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005942 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005943
5944 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005945
5946out_vdd_off:
5947 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5948 /*
5949 * vdd might still be enabled do to the delayed vdd off.
5950 * Make sure vdd is actually turned off here.
5951 */
5952 pps_lock(intel_dp);
5953 edp_panel_vdd_off_sync(intel_dp);
5954 pps_unlock(intel_dp);
5955
5956 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005957}
5958
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005959/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005960static void
5961intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5962{
5963 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005964 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005965
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005966 encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port);
5967
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005968 switch (intel_dig_port->port) {
5969 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005970 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005971 break;
5972 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005973 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005974 break;
5975 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005976 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005977 break;
5978 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005979 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005980 break;
5981 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005982 /* FIXME: Check VBT for actual wiring of PORT E */
5983 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005984 break;
5985 default:
5986 MISSING_CASE(intel_dig_port->port);
5987 }
5988}
5989
Manasi Navare93013972017-04-06 16:44:19 +03005990static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5991{
5992 struct intel_connector *intel_connector;
5993 struct drm_connector *connector;
5994
5995 intel_connector = container_of(work, typeof(*intel_connector),
5996 modeset_retry_work);
5997 connector = &intel_connector->base;
5998 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5999 connector->name);
6000
6001 /* Grab the locks before changing connector property*/
6002 mutex_lock(&connector->dev->mode_config.mutex);
6003 /* Set connector link status to BAD and send a Uevent to notify
6004 * userspace to do a modeset.
6005 */
6006 drm_mode_connector_set_link_status_property(connector,
6007 DRM_MODE_LINK_STATUS_BAD);
6008 mutex_unlock(&connector->dev->mode_config.mutex);
6009 /* Send Hotplug uevent so userspace can reprobe */
6010 drm_kms_helper_hotplug_event(connector->dev);
6011}
6012
Paulo Zanoni16c25532013-06-12 17:27:25 -03006013bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006014intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6015 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006016{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006017 struct drm_connector *connector = &intel_connector->base;
6018 struct intel_dp *intel_dp = &intel_dig_port->dp;
6019 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6020 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006021 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02006022 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006023 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006024
Manasi Navare93013972017-04-06 16:44:19 +03006025 /* Initialize the work for modeset in case of link train failure */
6026 INIT_WORK(&intel_connector->modeset_retry_work,
6027 intel_dp_modeset_retry_work_fn);
6028
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006029 if (WARN(intel_dig_port->max_lanes < 1,
6030 "Not enough lanes (%d) for DP on port %c\n",
6031 intel_dig_port->max_lanes, port_name(port)))
6032 return false;
6033
Jani Nikula55cfc582017-03-28 17:59:04 +03006034 intel_dp_set_source_rates(intel_dp);
6035
Manasi Navared7e8ef02017-02-07 16:54:11 -08006036 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006037 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006038 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006039
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006040 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006041 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006042 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006043 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006044 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006045 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006046 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6047 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006048 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006049
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006050 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006051 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6052 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006053 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006054
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006055 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006056 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6057
Daniel Vetter07679352012-09-06 22:15:42 +02006058 /* Preserve the current hw state. */
6059 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006060 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006061
Jani Nikula7b91bf72017-08-18 12:30:19 +03006062 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306063 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006064 else
6065 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006066
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006067 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6068 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6069
Imre Deakf7d24902013-05-08 13:14:05 +03006070 /*
6071 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6072 * for DP the encoder type can be set by the caller to
6073 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6074 */
6075 if (type == DRM_MODE_CONNECTOR_eDP)
6076 intel_encoder->type = INTEL_OUTPUT_EDP;
6077
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006078 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006079 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006080 intel_dp_is_edp(intel_dp) &&
6081 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006082 return false;
6083
Imre Deake7281ea2013-05-08 13:14:08 +03006084 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6085 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6086 port_name(port));
6087
Adam Jacksonb3295302010-07-16 14:46:28 -04006088 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006089 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6090
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006091 connector->interlace_allowed = true;
6092 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006093
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006094 intel_dp_init_connector_port_info(intel_dig_port);
6095
Mika Kaholab6339582016-09-09 14:10:52 +03006096 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006097
Daniel Vetter66a92782012-07-12 20:08:18 +02006098 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006099 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006100
Chris Wilsondf0e9242010-09-09 16:20:55 +01006101 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006102
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006103 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006104 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6105 else
6106 intel_connector->get_hw_state = intel_connector_get_hw_state;
6107
Dave Airlie0e32b392014-05-02 14:02:48 +10006108 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006109 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006110 (port == PORT_B || port == PORT_C || port == PORT_D))
6111 intel_dp_mst_encoder_init(intel_dig_port,
6112 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006113
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006114 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006115 intel_dp_aux_fini(intel_dp);
6116 intel_dp_mst_encoder_cleanup(intel_dig_port);
6117 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006118 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006119
Chris Wilsonf6849602010-09-19 09:29:33 +01006120 intel_dp_add_properties(intel_dp, connector);
6121
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006122 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6123 * 0xd. Failure to do so will result in spurious interrupts being
6124 * generated on the port when a cable is not attached.
6125 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006126 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006127 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6128 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6129 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006130
6131 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006132
6133fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006134 drm_connector_cleanup(connector);
6135
6136 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006137}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006138
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006139bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006140 i915_reg_t output_reg,
6141 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006142{
6143 struct intel_digital_port *intel_dig_port;
6144 struct intel_encoder *intel_encoder;
6145 struct drm_encoder *encoder;
6146 struct intel_connector *intel_connector;
6147
Daniel Vetterb14c5672013-09-19 12:18:32 +02006148 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006149 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006150 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006151
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006152 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306153 if (!intel_connector)
6154 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006155
6156 intel_encoder = &intel_dig_port->base;
6157 encoder = &intel_encoder->base;
6158
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006159 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6160 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6161 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306162 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006163
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006164 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006165 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006166 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006167 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006168 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006169 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006170 intel_encoder->pre_enable = chv_pre_enable_dp;
6171 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006172 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006173 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006174 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006175 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006176 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006177 intel_encoder->pre_enable = vlv_pre_enable_dp;
6178 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006179 intel_encoder->disable = vlv_disable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006180 intel_encoder->post_disable = vlv_post_disable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006181 } else if (INTEL_GEN(dev_priv) >= 5) {
6182 intel_encoder->pre_enable = g4x_pre_enable_dp;
6183 intel_encoder->enable = g4x_enable_dp;
6184 intel_encoder->disable = ilk_disable_dp;
6185 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006186 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006187 intel_encoder->pre_enable = g4x_pre_enable_dp;
6188 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä1a8ff602017-09-20 18:12:51 +03006189 intel_encoder->disable = g4x_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006190 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006191
Paulo Zanoni174edf12012-10-26 19:05:50 -02006192 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006193 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006194 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006195
Ville Syrjäläcca05022016-06-22 21:57:06 +03006196 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006197 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006198 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006199 if (port == PORT_D)
6200 intel_encoder->crtc_mask = 1 << 2;
6201 else
6202 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6203 } else {
6204 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6205 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006206 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006207 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006208
Dave Airlie13cf5502014-06-18 11:29:35 +10006209 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006210 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006211
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006212 if (port != PORT_A)
6213 intel_infoframe_init(intel_dig_port);
6214
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306215 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6216 goto err_init_connector;
6217
Chris Wilson457c52d2016-06-01 08:27:50 +01006218 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306219
6220err_init_connector:
6221 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306222err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306223 kfree(intel_connector);
6224err_connector_alloc:
6225 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006226 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006227}
Dave Airlie0e32b392014-05-02 14:02:48 +10006228
6229void intel_dp_mst_suspend(struct drm_device *dev)
6230{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006231 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006232 int i;
6233
6234 /* disable MST */
6235 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006236 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006237
6238 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006239 continue;
6240
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006241 if (intel_dig_port->dp.is_mst)
6242 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006243 }
6244}
6245
6246void intel_dp_mst_resume(struct drm_device *dev)
6247{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006248 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006249 int i;
6250
6251 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006252 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006253 int ret;
6254
6255 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006256 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006257
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006258 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6259 if (ret)
6260 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006261 }
6262}