blob: 95f2278700e3aa293a8d425508d3a1811c4ff2ad [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)
45
Todd Previte559be302015-05-04 07:48:20 -070046/* Compliance test status bits */
47#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
48#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030053 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080054 struct dpll dpll;
55};
56
57static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030060 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080061 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
62};
63
64static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030067 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080068 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
69};
70
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080071static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080073 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030074 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080075 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
76};
77
Chon Ming Leeef9348c2014-04-09 13:28:18 +030078/*
79 * CHV supports eDP 1.4 that have more link rates.
80 * Below only provides the fixed rate but exclude variable rate.
81 */
82static const struct dp_link_dpll chv_dpll[] = {
83 /*
84 * CHV requires to program fractional division for m2.
85 * m2 is stored in fixed point format using formula below
86 * (m2_int << 22) | m2_fraction
87 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030092 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030093 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
94};
Sonika Jindal637a9c62015-05-07 09:52:08 +053095
Sonika Jindal64987fc2015-05-26 17:50:13 +053096static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
97 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053098static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020099 324000, 432000, 540000 };
100static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300101
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700102/**
103 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
104 * @intel_dp: DP struct
105 *
106 * If a CPU or PCH DP output is attached to an eDP panel, this function
107 * will return true, and false otherwise.
108 */
109static bool is_edp(struct intel_dp *intel_dp)
110{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200111 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
112
113 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114}
115
Imre Deak68b4d822013-05-08 13:14:06 +0300116static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700117{
Imre Deak68b4d822013-05-08 13:14:06 +0300118 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
119
120 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121}
122
Chris Wilsondf0e9242010-09-09 16:20:55 +0100123static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
124{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200125 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100126}
127
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300129static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100130static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300131static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300132static void vlv_steal_power_sequencer(struct drm_device *dev,
133 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530134static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135
Jani Nikula68f357c2017-03-28 17:59:05 +0300136static int intel_dp_num_rates(u8 link_bw_code)
137{
138 switch (link_bw_code) {
139 default:
140 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
141 link_bw_code);
142 case DP_LINK_BW_1_62:
143 return 1;
144 case DP_LINK_BW_2_7:
145 return 2;
146 case DP_LINK_BW_5_4:
147 return 3;
148 }
149}
150
151/* update sink rates from dpcd */
152static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
153{
154 int i, num_rates;
155
156 num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]);
157
158 for (i = 0; i < num_rates; i++)
159 intel_dp->sink_rates[i] = default_rates[i];
160
161 intel_dp->num_sink_rates = num_rates;
162}
163
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300164/* Theoretical max between source and sink */
165static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300167 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168}
169
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300170/* Theoretical max between source and sink */
171static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300172{
173 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300174 int source_max = intel_dig_port->max_lanes;
175 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300176
177 return min(source_max, sink_max);
178}
179
Jani Nikula3d65a732017-04-06 16:44:14 +0300180int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300181{
182 return intel_dp->max_link_lane_count;
183}
184
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800185int
Keith Packardc8982612012-01-25 08:16:25 -0800186intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700187{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800188 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
189 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700190}
191
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800192int
Dave Airliefe27d532010-06-30 11:46:17 +1000193intel_dp_max_data_rate(int max_link_clock, int max_lanes)
194{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800195 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
196 * link rate that is generally expressed in Gbps. Since, 8 bits of data
197 * is transmitted every LS_Clk per lane, there is no need to account for
198 * the channel encoding that is done in the PHY layer here.
199 */
200
201 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000202}
203
Mika Kahola70ec0642016-09-09 14:10:55 +0300204static int
205intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
206{
207 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
208 struct intel_encoder *encoder = &intel_dig_port->base;
209 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
210 int max_dotclk = dev_priv->max_dotclk_freq;
211 int ds_max_dotclk;
212
213 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
214
215 if (type != DP_DS_PORT_TYPE_VGA)
216 return max_dotclk;
217
218 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
219 intel_dp->downstream_ports);
220
221 if (ds_max_dotclk != 0)
222 max_dotclk = min(max_dotclk, ds_max_dotclk);
223
224 return max_dotclk;
225}
226
Jani Nikula55cfc582017-03-28 17:59:04 +0300227static void
228intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700229{
230 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
231 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Jani Nikula55cfc582017-03-28 17:59:04 +0300232 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700233 int size;
234
Jani Nikula55cfc582017-03-28 17:59:04 +0300235 /* This should only be done once */
236 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
237
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200238 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300239 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700240 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800241 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300242 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700243 size = ARRAY_SIZE(skl_rates);
244 } else {
Jani Nikula55cfc582017-03-28 17:59:04 +0300245 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700246 size = ARRAY_SIZE(default_rates);
247 }
248
249 /* This depends on the fact that 5.4 is last value in the array */
250 if (!intel_dp_source_supports_hbr2(intel_dp))
251 size--;
252
Jani Nikula55cfc582017-03-28 17:59:04 +0300253 intel_dp->source_rates = source_rates;
254 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700255}
256
257static int intersect_rates(const int *source_rates, int source_len,
258 const int *sink_rates, int sink_len,
259 int *common_rates)
260{
261 int i = 0, j = 0, k = 0;
262
263 while (i < source_len && j < sink_len) {
264 if (source_rates[i] == sink_rates[j]) {
265 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
266 return k;
267 common_rates[k] = source_rates[i];
268 ++k;
269 ++i;
270 ++j;
271 } else if (source_rates[i] < sink_rates[j]) {
272 ++i;
273 } else {
274 ++j;
275 }
276 }
277 return k;
278}
279
Jani Nikula8001b752017-03-28 17:59:03 +0300280/* return index of rate in rates array, or -1 if not found */
281static int intel_dp_rate_index(const int *rates, int len, int rate)
282{
283 int i;
284
285 for (i = 0; i < len; i++)
286 if (rate == rates[i])
287 return i;
288
289 return -1;
290}
291
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300292static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700293{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300294 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700295
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300296 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
297 intel_dp->num_source_rates,
298 intel_dp->sink_rates,
299 intel_dp->num_sink_rates,
300 intel_dp->common_rates);
301
302 /* Paranoia, there should always be something in common. */
303 if (WARN_ON(intel_dp->num_common_rates == 0)) {
304 intel_dp->common_rates[0] = default_rates[0];
305 intel_dp->num_common_rates = 1;
306 }
307}
308
309/* get length of common rates potentially limited by max_rate */
310static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
311 int max_rate)
312{
313 const int *common_rates = intel_dp->common_rates;
314 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700315
Jani Nikula68f357c2017-03-28 17:59:05 +0300316 /* Limit results by potentially reduced max rate */
317 for (i = 0; i < common_len; i++) {
318 if (common_rates[common_len - i - 1] <= max_rate)
319 return common_len - i;
320 }
321
322 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700323}
324
Manasi Navarefdb14d32016-12-08 19:05:12 -0800325int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
326 int link_rate, uint8_t lane_count)
327{
Jani Nikulab1810a72017-04-06 16:44:11 +0300328 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800329
Jani Nikulab1810a72017-04-06 16:44:11 +0300330 index = intel_dp_rate_index(intel_dp->common_rates,
331 intel_dp->num_common_rates,
332 link_rate);
333 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300334 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
335 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800336 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300337 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300338 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800339 } else {
340 DRM_ERROR("Link Training Unsuccessful\n");
341 return -1;
342 }
343
344 return 0;
345}
346
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000347static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700348intel_dp_mode_valid(struct drm_connector *connector,
349 struct drm_display_mode *mode)
350{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100351 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300352 struct intel_connector *intel_connector = to_intel_connector(connector);
353 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100354 int target_clock = mode->clock;
355 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300356 int max_dotclk;
357
358 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700359
Jani Nikuladd06f902012-10-19 14:51:50 +0300360 if (is_edp(intel_dp) && fixed_mode) {
361 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100362 return MODE_PANEL;
363
Jani Nikuladd06f902012-10-19 14:51:50 +0300364 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100365 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200366
367 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100368 }
369
Ville Syrjälä50fec212015-03-12 17:10:34 +0200370 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300371 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100372
373 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
374 mode_rate = intel_dp_link_required(target_clock, 18);
375
Mika Kahola799487f2016-02-02 15:16:38 +0200376 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200377 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700378
379 if (mode->clock < 10000)
380 return MODE_CLOCK_LOW;
381
Daniel Vetter0af78a22012-05-23 11:30:55 +0200382 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
383 return MODE_H_ILLEGAL;
384
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700385 return MODE_OK;
386}
387
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800388uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700389{
390 int i;
391 uint32_t v = 0;
392
393 if (src_bytes > 4)
394 src_bytes = 4;
395 for (i = 0; i < src_bytes; i++)
396 v |= ((uint32_t) src[i]) << ((3-i) * 8);
397 return v;
398}
399
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000400static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700401{
402 int i;
403 if (dst_bytes > 4)
404 dst_bytes = 4;
405 for (i = 0; i < dst_bytes; i++)
406 dst[i] = src >> ((3-i) * 8);
407}
408
Jani Nikulabf13e812013-09-06 07:40:05 +0300409static void
410intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300411 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300412static void
413intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200414 struct intel_dp *intel_dp,
415 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300416static void
417intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300418
Ville Syrjälä773538e82014-09-04 14:54:56 +0300419static void pps_lock(struct intel_dp *intel_dp)
420{
421 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
422 struct intel_encoder *encoder = &intel_dig_port->base;
423 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100424 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300425
426 /*
427 * See vlv_power_sequencer_reset() why we need
428 * a power domain reference here.
429 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200430 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300431
432 mutex_lock(&dev_priv->pps_mutex);
433}
434
435static void pps_unlock(struct intel_dp *intel_dp)
436{
437 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
438 struct intel_encoder *encoder = &intel_dig_port->base;
439 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100440 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300441
442 mutex_unlock(&dev_priv->pps_mutex);
443
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200444 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300445}
446
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300447static void
448vlv_power_sequencer_kick(struct intel_dp *intel_dp)
449{
450 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200451 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300452 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300453 bool pll_enabled, release_cl_override = false;
454 enum dpio_phy phy = DPIO_PHY(pipe);
455 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300456 uint32_t DP;
457
458 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
459 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
460 pipe_name(pipe), port_name(intel_dig_port->port)))
461 return;
462
463 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
464 pipe_name(pipe), port_name(intel_dig_port->port));
465
466 /* Preserve the BIOS-computed detected bit. This is
467 * supposed to be read-only.
468 */
469 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
470 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
471 DP |= DP_PORT_WIDTH(1);
472 DP |= DP_LINK_TRAIN_PAT_1;
473
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100474 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300475 DP |= DP_PIPE_SELECT_CHV(pipe);
476 else if (pipe == PIPE_B)
477 DP |= DP_PIPEB_SELECT;
478
Ville Syrjäläd288f652014-10-28 13:20:22 +0200479 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
480
481 /*
482 * The DPLL for the pipe must be enabled for this to work.
483 * So enable temporarily it if it's not already enabled.
484 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300485 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100486 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300487 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
488
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200489 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000490 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
491 DRM_ERROR("Failed to force on pll for pipe %c!\n",
492 pipe_name(pipe));
493 return;
494 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300495 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200496
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300497 /*
498 * Similar magic as in intel_dp_enable_port().
499 * We _must_ do this port enable + disable trick
500 * to make this power seqeuencer lock onto the port.
501 * Otherwise even VDD force bit won't work.
502 */
503 I915_WRITE(intel_dp->output_reg, DP);
504 POSTING_READ(intel_dp->output_reg);
505
506 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
507 POSTING_READ(intel_dp->output_reg);
508
509 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
510 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200511
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300512 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200513 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300514
515 if (release_cl_override)
516 chv_phy_powergate_ch(dev_priv, phy, ch, false);
517 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300518}
519
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200520static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
521{
522 struct intel_encoder *encoder;
523 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
524
525 /*
526 * We don't have power sequencer currently.
527 * Pick one that's not used by other ports.
528 */
529 for_each_intel_encoder(&dev_priv->drm, encoder) {
530 struct intel_dp *intel_dp;
531
532 if (encoder->type != INTEL_OUTPUT_DP &&
533 encoder->type != INTEL_OUTPUT_EDP)
534 continue;
535
536 intel_dp = enc_to_intel_dp(&encoder->base);
537
538 if (encoder->type == INTEL_OUTPUT_EDP) {
539 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
540 intel_dp->active_pipe != intel_dp->pps_pipe);
541
542 if (intel_dp->pps_pipe != INVALID_PIPE)
543 pipes &= ~(1 << intel_dp->pps_pipe);
544 } else {
545 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
546
547 if (intel_dp->active_pipe != INVALID_PIPE)
548 pipes &= ~(1 << intel_dp->active_pipe);
549 }
550 }
551
552 if (pipes == 0)
553 return INVALID_PIPE;
554
555 return ffs(pipes) - 1;
556}
557
Jani Nikulabf13e812013-09-06 07:40:05 +0300558static enum pipe
559vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
560{
561 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300562 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100563 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300564 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300565
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300566 lockdep_assert_held(&dev_priv->pps_mutex);
567
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300568 /* We should never land here with regular DP ports */
569 WARN_ON(!is_edp(intel_dp));
570
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200571 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
572 intel_dp->active_pipe != intel_dp->pps_pipe);
573
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300574 if (intel_dp->pps_pipe != INVALID_PIPE)
575 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300576
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200577 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300578
579 /*
580 * Didn't find one. This should not happen since there
581 * are two power sequencers and up to two eDP ports.
582 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200583 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300584 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300585
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300586 vlv_steal_power_sequencer(dev, pipe);
587 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300588
589 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
590 pipe_name(intel_dp->pps_pipe),
591 port_name(intel_dig_port->port));
592
593 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300594 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200595 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300596
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300597 /*
598 * Even vdd force doesn't work until we've made
599 * the power sequencer lock in on the port.
600 */
601 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300602
603 return intel_dp->pps_pipe;
604}
605
Imre Deak78597992016-06-16 16:37:20 +0300606static int
607bxt_power_sequencer_idx(struct intel_dp *intel_dp)
608{
609 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
610 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100611 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300612
613 lockdep_assert_held(&dev_priv->pps_mutex);
614
615 /* We should never land here with regular DP ports */
616 WARN_ON(!is_edp(intel_dp));
617
618 /*
619 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
620 * mapping needs to be retrieved from VBT, for now just hard-code to
621 * use instance #0 always.
622 */
623 if (!intel_dp->pps_reset)
624 return 0;
625
626 intel_dp->pps_reset = false;
627
628 /*
629 * Only the HW needs to be reprogrammed, the SW state is fixed and
630 * has been setup during connector init.
631 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200632 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300633
634 return 0;
635}
636
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300637typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
638 enum pipe pipe);
639
640static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
641 enum pipe pipe)
642{
Imre Deak44cb7342016-08-10 14:07:29 +0300643 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300644}
645
646static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
647 enum pipe pipe)
648{
Imre Deak44cb7342016-08-10 14:07:29 +0300649 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300650}
651
652static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
653 enum pipe pipe)
654{
655 return true;
656}
657
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300658static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300659vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
660 enum port port,
661 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300662{
Jani Nikulabf13e812013-09-06 07:40:05 +0300663 enum pipe pipe;
664
Jani Nikulabf13e812013-09-06 07:40:05 +0300665 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300666 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300667 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300668
669 if (port_sel != PANEL_PORT_SELECT_VLV(port))
670 continue;
671
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300672 if (!pipe_check(dev_priv, pipe))
673 continue;
674
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300675 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300676 }
677
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300678 return INVALID_PIPE;
679}
680
681static void
682vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
683{
684 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
685 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100686 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300687 enum port port = intel_dig_port->port;
688
689 lockdep_assert_held(&dev_priv->pps_mutex);
690
691 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300692 /* first pick one where the panel is on */
693 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
694 vlv_pipe_has_pp_on);
695 /* didn't find one? pick one where vdd is on */
696 if (intel_dp->pps_pipe == INVALID_PIPE)
697 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
698 vlv_pipe_has_vdd_on);
699 /* didn't find one? pick one with just the correct port */
700 if (intel_dp->pps_pipe == INVALID_PIPE)
701 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
702 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300703
704 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
705 if (intel_dp->pps_pipe == INVALID_PIPE) {
706 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
707 port_name(port));
708 return;
709 }
710
711 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
712 port_name(port), pipe_name(intel_dp->pps_pipe));
713
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300714 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200715 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300716}
717
Imre Deak78597992016-06-16 16:37:20 +0300718void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300719{
Chris Wilson91c8a322016-07-05 10:40:23 +0100720 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300721 struct intel_encoder *encoder;
722
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100723 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200724 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300725 return;
726
727 /*
728 * We can't grab pps_mutex here due to deadlock with power_domain
729 * mutex when power_domain functions are called while holding pps_mutex.
730 * That also means that in order to use pps_pipe the code needs to
731 * hold both a power domain reference and pps_mutex, and the power domain
732 * reference get/put must be done while _not_ holding pps_mutex.
733 * pps_{lock,unlock}() do these steps in the correct order, so one
734 * should use them always.
735 */
736
Jani Nikula19c80542015-12-16 12:48:16 +0200737 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300738 struct intel_dp *intel_dp;
739
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200740 if (encoder->type != INTEL_OUTPUT_DP &&
741 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300742 continue;
743
744 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200745
746 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
747
748 if (encoder->type != INTEL_OUTPUT_EDP)
749 continue;
750
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200751 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300752 intel_dp->pps_reset = true;
753 else
754 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300755 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300756}
757
Imre Deak8e8232d2016-06-16 16:37:21 +0300758struct pps_registers {
759 i915_reg_t pp_ctrl;
760 i915_reg_t pp_stat;
761 i915_reg_t pp_on;
762 i915_reg_t pp_off;
763 i915_reg_t pp_div;
764};
765
766static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
767 struct intel_dp *intel_dp,
768 struct pps_registers *regs)
769{
Imre Deak44cb7342016-08-10 14:07:29 +0300770 int pps_idx = 0;
771
Imre Deak8e8232d2016-06-16 16:37:21 +0300772 memset(regs, 0, sizeof(*regs));
773
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200774 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300775 pps_idx = bxt_power_sequencer_idx(intel_dp);
776 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
777 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300778
Imre Deak44cb7342016-08-10 14:07:29 +0300779 regs->pp_ctrl = PP_CONTROL(pps_idx);
780 regs->pp_stat = PP_STATUS(pps_idx);
781 regs->pp_on = PP_ON_DELAYS(pps_idx);
782 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200783 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300784 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300785}
786
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200787static i915_reg_t
788_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300789{
Imre Deak8e8232d2016-06-16 16:37:21 +0300790 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300791
Imre Deak8e8232d2016-06-16 16:37:21 +0300792 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
793 &regs);
794
795 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300796}
797
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200798static i915_reg_t
799_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300800{
Imre Deak8e8232d2016-06-16 16:37:21 +0300801 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300802
Imre Deak8e8232d2016-06-16 16:37:21 +0300803 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
804 &regs);
805
806 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300807}
808
Clint Taylor01527b32014-07-07 13:01:46 -0700809/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
810 This function only applicable when panel PM state is not to be tracked */
811static int edp_notify_handler(struct notifier_block *this, unsigned long code,
812 void *unused)
813{
814 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
815 edp_notifier);
816 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100817 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700818
819 if (!is_edp(intel_dp) || code != SYS_RESTART)
820 return 0;
821
Ville Syrjälä773538e82014-09-04 14:54:56 +0300822 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300823
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100824 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300825 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200826 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300827 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300828
Imre Deak44cb7342016-08-10 14:07:29 +0300829 pp_ctrl_reg = PP_CONTROL(pipe);
830 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700831 pp_div = I915_READ(pp_div_reg);
832 pp_div &= PP_REFERENCE_DIVIDER_MASK;
833
834 /* 0x1F write to PP_DIV_REG sets max cycle delay */
835 I915_WRITE(pp_div_reg, pp_div | 0x1F);
836 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
837 msleep(intel_dp->panel_power_cycle_delay);
838 }
839
Ville Syrjälä773538e82014-09-04 14:54:56 +0300840 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300841
Clint Taylor01527b32014-07-07 13:01:46 -0700842 return 0;
843}
844
Daniel Vetter4be73782014-01-17 14:39:48 +0100845static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700846{
Paulo Zanoni30add222012-10-26 19:05:45 -0200847 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100848 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700849
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300850 lockdep_assert_held(&dev_priv->pps_mutex);
851
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100852 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300853 intel_dp->pps_pipe == INVALID_PIPE)
854 return false;
855
Jani Nikulabf13e812013-09-06 07:40:05 +0300856 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700857}
858
Daniel Vetter4be73782014-01-17 14:39:48 +0100859static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700860{
Paulo Zanoni30add222012-10-26 19:05:45 -0200861 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100862 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700863
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300864 lockdep_assert_held(&dev_priv->pps_mutex);
865
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100866 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300867 intel_dp->pps_pipe == INVALID_PIPE)
868 return false;
869
Ville Syrjälä773538e82014-09-04 14:54:56 +0300870 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700871}
872
Keith Packard9b984da2011-09-19 13:54:47 -0700873static void
874intel_dp_check_edp(struct intel_dp *intel_dp)
875{
Paulo Zanoni30add222012-10-26 19:05:45 -0200876 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100877 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700878
Keith Packard9b984da2011-09-19 13:54:47 -0700879 if (!is_edp(intel_dp))
880 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700881
Daniel Vetter4be73782014-01-17 14:39:48 +0100882 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700883 WARN(1, "eDP powered off while attempting aux channel communication.\n");
884 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300885 I915_READ(_pp_stat_reg(intel_dp)),
886 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700887 }
888}
889
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100890static uint32_t
891intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
892{
893 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
894 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100895 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200896 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100897 uint32_t status;
898 bool done;
899
Daniel Vetteref04f002012-12-01 21:03:59 +0100900#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100901 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300902 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300903 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100904 else
Imre Deak713a6b662016-06-28 13:37:33 +0300905 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100906 if (!done)
907 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
908 has_aux_irq);
909#undef C
910
911 return status;
912}
913
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200914static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000915{
916 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200917 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000918
Ville Syrjäläa457f542016-03-02 17:22:17 +0200919 if (index)
920 return 0;
921
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000922 /*
923 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200924 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000925 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200926 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000927}
928
929static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
930{
931 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200932 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000933
934 if (index)
935 return 0;
936
Ville Syrjäläa457f542016-03-02 17:22:17 +0200937 /*
938 * The clock divider is based off the cdclk or PCH rawclk, and would
939 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
940 * divide by 2000 and use that
941 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200942 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200943 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200944 else
945 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000946}
947
948static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300949{
950 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200951 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300952
Ville Syrjäläa457f542016-03-02 17:22:17 +0200953 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300954 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100955 switch (index) {
956 case 0: return 63;
957 case 1: return 72;
958 default: return 0;
959 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300960 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200961
962 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300963}
964
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000965static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
966{
967 /*
968 * SKL doesn't need us to program the AUX clock divider (Hardware will
969 * derive the clock from CDCLK automatically). We still implement the
970 * get_aux_clock_divider vfunc to plug-in into the existing code.
971 */
972 return index ? 0 : 1;
973}
974
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200975static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
976 bool has_aux_irq,
977 int send_bytes,
978 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000979{
980 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100981 struct drm_i915_private *dev_priv =
982 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000983 uint32_t precharge, timeout;
984
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100985 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000986 precharge = 3;
987 else
988 precharge = 5;
989
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100990 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000991 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
992 else
993 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
994
995 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000996 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000997 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000998 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000999 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001000 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001001 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1002 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001003 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001004}
1005
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001006static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1007 bool has_aux_irq,
1008 int send_bytes,
1009 uint32_t unused)
1010{
1011 return DP_AUX_CH_CTL_SEND_BUSY |
1012 DP_AUX_CH_CTL_DONE |
1013 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1014 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1015 DP_AUX_CH_CTL_TIME_OUT_1600us |
1016 DP_AUX_CH_CTL_RECEIVE_ERROR |
1017 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001018 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001019 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1020}
1021
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001022static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001023intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001024 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001025 uint8_t *recv, int recv_size)
1026{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001027 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001028 struct drm_i915_private *dev_priv =
1029 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001030 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001031 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001032 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001033 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001034 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001035 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001036 bool vdd;
1037
Ville Syrjälä773538e82014-09-04 14:54:56 +03001038 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001039
Ville Syrjälä72c35002014-08-18 22:16:00 +03001040 /*
1041 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1042 * In such cases we want to leave VDD enabled and it's up to upper layers
1043 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1044 * ourselves.
1045 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001046 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001047
1048 /* dp aux is extremely sensitive to irq latency, hence request the
1049 * lowest possible wakeup latency and so prevent the cpu from going into
1050 * deep sleep states.
1051 */
1052 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001053
Keith Packard9b984da2011-09-19 13:54:47 -07001054 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001055
Jesse Barnes11bee432011-08-01 15:02:20 -07001056 /* Try to wait for any previous AUX channel activity */
1057 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001058 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001059 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1060 break;
1061 msleep(1);
1062 }
1063
1064 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001065 static u32 last_status = -1;
1066 const u32 status = I915_READ(ch_ctl);
1067
1068 if (status != last_status) {
1069 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1070 status);
1071 last_status = status;
1072 }
1073
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001074 ret = -EBUSY;
1075 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001076 }
1077
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001078 /* Only 5 data registers! */
1079 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1080 ret = -E2BIG;
1081 goto out;
1082 }
1083
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001084 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001085 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1086 has_aux_irq,
1087 send_bytes,
1088 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001089
Chris Wilsonbc866252013-07-21 16:00:03 +01001090 /* Must try at least 3 times according to DP spec */
1091 for (try = 0; try < 5; try++) {
1092 /* Load the send data into the aux channel data registers */
1093 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001094 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001095 intel_dp_pack_aux(send + i,
1096 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001097
Chris Wilsonbc866252013-07-21 16:00:03 +01001098 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001099 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001100
Chris Wilsonbc866252013-07-21 16:00:03 +01001101 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001102
Chris Wilsonbc866252013-07-21 16:00:03 +01001103 /* Clear done status and any errors */
1104 I915_WRITE(ch_ctl,
1105 status |
1106 DP_AUX_CH_CTL_DONE |
1107 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1108 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001109
Todd Previte74ebf292015-04-15 08:38:41 -07001110 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001111 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001112
1113 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1114 * 400us delay required for errors and timeouts
1115 * Timeout errors from the HW already meet this
1116 * requirement so skip to next iteration
1117 */
1118 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1119 usleep_range(400, 500);
1120 continue;
1121 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001122 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001123 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001124 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001125 }
1126
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001127 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001128 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001129 ret = -EBUSY;
1130 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001131 }
1132
Jim Bridee058c942015-05-27 10:21:48 -07001133done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001134 /* Check for timeout or receive error.
1135 * Timeouts occur when the sink is not connected
1136 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001137 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001138 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001139 ret = -EIO;
1140 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001141 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001142
1143 /* Timeouts occur when the device isn't connected, so they're
1144 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001145 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001146 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001147 ret = -ETIMEDOUT;
1148 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001149 }
1150
1151 /* Unload any bytes sent back from the other side */
1152 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1153 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001154
1155 /*
1156 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1157 * We have no idea of what happened so we return -EBUSY so
1158 * drm layer takes care for the necessary retries.
1159 */
1160 if (recv_bytes == 0 || recv_bytes > 20) {
1161 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1162 recv_bytes);
1163 /*
1164 * FIXME: This patch was created on top of a series that
1165 * organize the retries at drm level. There EBUSY should
1166 * also take care for 1ms wait before retrying.
1167 * That aux retries re-org is still needed and after that is
1168 * merged we remove this sleep from here.
1169 */
1170 usleep_range(1000, 1500);
1171 ret = -EBUSY;
1172 goto out;
1173 }
1174
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001175 if (recv_bytes > recv_size)
1176 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001177
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001178 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001179 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001180 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001182 ret = recv_bytes;
1183out:
1184 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1185
Jani Nikula884f19e2014-03-14 16:51:14 +02001186 if (vdd)
1187 edp_panel_vdd_off(intel_dp, false);
1188
Ville Syrjälä773538e82014-09-04 14:54:56 +03001189 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001190
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001191 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001192}
1193
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001194#define BARE_ADDRESS_SIZE 3
1195#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001196static ssize_t
1197intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001198{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001199 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1200 uint8_t txbuf[20], rxbuf[20];
1201 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001202 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001203
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001204 txbuf[0] = (msg->request << 4) |
1205 ((msg->address >> 16) & 0xf);
1206 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001207 txbuf[2] = msg->address & 0xff;
1208 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001209
Jani Nikula9d1a1032014-03-14 16:51:15 +02001210 switch (msg->request & ~DP_AUX_I2C_MOT) {
1211 case DP_AUX_NATIVE_WRITE:
1212 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001213 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001214 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001215 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001216
Jani Nikula9d1a1032014-03-14 16:51:15 +02001217 if (WARN_ON(txsize > 20))
1218 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001219
Ville Syrjälädd788092016-07-28 17:55:04 +03001220 WARN_ON(!msg->buffer != !msg->size);
1221
Imre Deakd81a67c2016-01-29 14:52:26 +02001222 if (msg->buffer)
1223 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001224
Jani Nikula9d1a1032014-03-14 16:51:15 +02001225 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1226 if (ret > 0) {
1227 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001228
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001229 if (ret > 1) {
1230 /* Number of bytes written in a short write. */
1231 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1232 } else {
1233 /* Return payload size. */
1234 ret = msg->size;
1235 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001236 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001237 break;
1238
1239 case DP_AUX_NATIVE_READ:
1240 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001241 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001242 rxsize = msg->size + 1;
1243
1244 if (WARN_ON(rxsize > 20))
1245 return -E2BIG;
1246
1247 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1248 if (ret > 0) {
1249 msg->reply = rxbuf[0] >> 4;
1250 /*
1251 * Assume happy day, and copy the data. The caller is
1252 * expected to check msg->reply before touching it.
1253 *
1254 * Return payload size.
1255 */
1256 ret--;
1257 memcpy(msg->buffer, rxbuf + 1, ret);
1258 }
1259 break;
1260
1261 default:
1262 ret = -EINVAL;
1263 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001264 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001265
Jani Nikula9d1a1032014-03-14 16:51:15 +02001266 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001267}
1268
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001269static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1270 enum port port)
1271{
1272 const struct ddi_vbt_port_info *info =
1273 &dev_priv->vbt.ddi_port_info[port];
1274 enum port aux_port;
1275
1276 if (!info->alternate_aux_channel) {
1277 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1278 port_name(port), port_name(port));
1279 return port;
1280 }
1281
1282 switch (info->alternate_aux_channel) {
1283 case DP_AUX_A:
1284 aux_port = PORT_A;
1285 break;
1286 case DP_AUX_B:
1287 aux_port = PORT_B;
1288 break;
1289 case DP_AUX_C:
1290 aux_port = PORT_C;
1291 break;
1292 case DP_AUX_D:
1293 aux_port = PORT_D;
1294 break;
1295 default:
1296 MISSING_CASE(info->alternate_aux_channel);
1297 aux_port = PORT_A;
1298 break;
1299 }
1300
1301 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1302 port_name(aux_port), port_name(port));
1303
1304 return aux_port;
1305}
1306
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001307static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001308 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001309{
1310 switch (port) {
1311 case PORT_B:
1312 case PORT_C:
1313 case PORT_D:
1314 return DP_AUX_CH_CTL(port);
1315 default:
1316 MISSING_CASE(port);
1317 return DP_AUX_CH_CTL(PORT_B);
1318 }
1319}
1320
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001321static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001322 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001323{
1324 switch (port) {
1325 case PORT_B:
1326 case PORT_C:
1327 case PORT_D:
1328 return DP_AUX_CH_DATA(port, index);
1329 default:
1330 MISSING_CASE(port);
1331 return DP_AUX_CH_DATA(PORT_B, index);
1332 }
1333}
1334
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001335static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001336 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001337{
1338 switch (port) {
1339 case PORT_A:
1340 return DP_AUX_CH_CTL(port);
1341 case PORT_B:
1342 case PORT_C:
1343 case PORT_D:
1344 return PCH_DP_AUX_CH_CTL(port);
1345 default:
1346 MISSING_CASE(port);
1347 return DP_AUX_CH_CTL(PORT_A);
1348 }
1349}
1350
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001351static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001352 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001353{
1354 switch (port) {
1355 case PORT_A:
1356 return DP_AUX_CH_DATA(port, index);
1357 case PORT_B:
1358 case PORT_C:
1359 case PORT_D:
1360 return PCH_DP_AUX_CH_DATA(port, index);
1361 default:
1362 MISSING_CASE(port);
1363 return DP_AUX_CH_DATA(PORT_A, index);
1364 }
1365}
1366
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001367static i915_reg_t skl_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{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001370 switch (port) {
1371 case PORT_A:
1372 case PORT_B:
1373 case PORT_C:
1374 case PORT_D:
1375 return DP_AUX_CH_CTL(port);
1376 default:
1377 MISSING_CASE(port);
1378 return DP_AUX_CH_CTL(PORT_A);
1379 }
1380}
1381
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001382static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001383 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001384{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001385 switch (port) {
1386 case PORT_A:
1387 case PORT_B:
1388 case PORT_C:
1389 case PORT_D:
1390 return DP_AUX_CH_DATA(port, index);
1391 default:
1392 MISSING_CASE(port);
1393 return DP_AUX_CH_DATA(PORT_A, index);
1394 }
1395}
1396
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001397static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001398 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001399{
1400 if (INTEL_INFO(dev_priv)->gen >= 9)
1401 return skl_aux_ctl_reg(dev_priv, port);
1402 else if (HAS_PCH_SPLIT(dev_priv))
1403 return ilk_aux_ctl_reg(dev_priv, port);
1404 else
1405 return g4x_aux_ctl_reg(dev_priv, port);
1406}
1407
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001408static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001409 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001410{
1411 if (INTEL_INFO(dev_priv)->gen >= 9)
1412 return skl_aux_data_reg(dev_priv, port, index);
1413 else if (HAS_PCH_SPLIT(dev_priv))
1414 return ilk_aux_data_reg(dev_priv, port, index);
1415 else
1416 return g4x_aux_data_reg(dev_priv, port, index);
1417}
1418
1419static void intel_aux_reg_init(struct intel_dp *intel_dp)
1420{
1421 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001422 enum port port = intel_aux_port(dev_priv,
1423 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001424 int i;
1425
1426 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1427 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1428 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1429}
1430
Jani Nikula9d1a1032014-03-14 16:51:15 +02001431static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001432intel_dp_aux_fini(struct intel_dp *intel_dp)
1433{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001434 kfree(intel_dp->aux.name);
1435}
1436
Chris Wilson7a418e32016-06-24 14:00:14 +01001437static void
Mika Kaholab6339582016-09-09 14:10:52 +03001438intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001439{
Jani Nikula33ad6622014-03-14 16:51:16 +02001440 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1441 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001442
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001443 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001444 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001445
Chris Wilson7a418e32016-06-24 14:00:14 +01001446 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001447 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001448 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001449}
1450
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001451bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301452{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001453 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001454 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001455
Navare, Manasi D577c5432016-09-27 16:36:53 -07001456 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1457 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301458 return true;
1459 else
1460 return false;
1461}
1462
Daniel Vetter0e503382014-07-04 11:26:04 -03001463static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001464intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001465 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001466{
1467 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001468 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001469 const struct dp_link_dpll *divisor = NULL;
1470 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001471
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001472 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001473 divisor = gen4_dpll;
1474 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001475 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001476 divisor = pch_dpll;
1477 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001478 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001479 divisor = chv_dpll;
1480 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001481 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001482 divisor = vlv_dpll;
1483 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001484 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001485
1486 if (divisor && count) {
1487 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001488 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001489 pipe_config->dpll = divisor[i].dpll;
1490 pipe_config->clock_set = true;
1491 break;
1492 }
1493 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001494 }
1495}
1496
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001497static void snprintf_int_array(char *str, size_t len,
1498 const int *array, int nelem)
1499{
1500 int i;
1501
1502 str[0] = '\0';
1503
1504 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001505 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001506 if (r >= len)
1507 return;
1508 str += r;
1509 len -= r;
1510 }
1511}
1512
1513static void intel_dp_print_rates(struct intel_dp *intel_dp)
1514{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001515 char str[128]; /* FIXME: too big for stack? */
1516
1517 if ((drm_debug & DRM_UT_KMS) == 0)
1518 return;
1519
Jani Nikula55cfc582017-03-28 17:59:04 +03001520 snprintf_int_array(str, sizeof(str),
1521 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001522 DRM_DEBUG_KMS("source rates: %s\n", str);
1523
Jani Nikula68f357c2017-03-28 17:59:05 +03001524 snprintf_int_array(str, sizeof(str),
1525 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001526 DRM_DEBUG_KMS("sink rates: %s\n", str);
1527
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001528 snprintf_int_array(str, sizeof(str),
1529 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001530 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001531}
1532
Imre Deak489375c2016-10-24 19:33:31 +03001533bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001534__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001535{
Imre Deak7b3fc172016-10-25 16:12:39 +03001536 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1537 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001538
Imre Deak7b3fc172016-10-25 16:12:39 +03001539 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1540 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001541}
1542
Imre Deak12a47a422016-10-24 19:33:29 +03001543bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001544{
Imre Deak7b3fc172016-10-25 16:12:39 +03001545 struct intel_dp_desc *desc = &intel_dp->desc;
1546 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1547 DP_OUI_SUPPORT;
1548 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001549
Imre Deak7b3fc172016-10-25 16:12:39 +03001550 if (!__intel_dp_read_desc(intel_dp, desc))
1551 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001552
Imre Deak7b3fc172016-10-25 16:12:39 +03001553 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1554 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1555 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1556 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1557 dev_id_len, desc->device_id,
1558 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1559 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001560
Imre Deak7b3fc172016-10-25 16:12:39 +03001561 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001562}
1563
Ville Syrjälä50fec212015-03-12 17:10:34 +02001564int
1565intel_dp_max_link_rate(struct intel_dp *intel_dp)
1566{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001567 int len;
1568
Jani Nikulae6c0c642017-04-06 16:44:12 +03001569 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001570 if (WARN_ON(len <= 0))
1571 return 162000;
1572
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001573 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001574}
1575
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001576int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1577{
Jani Nikula8001b752017-03-28 17:59:03 +03001578 int i = intel_dp_rate_index(intel_dp->sink_rates,
1579 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001580
1581 if (WARN_ON(i < 0))
1582 i = 0;
1583
1584 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001585}
1586
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001587void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1588 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001589{
Jani Nikula68f357c2017-03-28 17:59:05 +03001590 /* eDP 1.4 rate select method. */
1591 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001592 *link_bw = 0;
1593 *rate_select =
1594 intel_dp_rate_select(intel_dp, port_clock);
1595 } else {
1596 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1597 *rate_select = 0;
1598 }
1599}
1600
Jani Nikulaf580bea2016-09-15 16:28:52 +03001601static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1602 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001603{
1604 int bpp, bpc;
1605
1606 bpp = pipe_config->pipe_bpp;
1607 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1608
1609 if (bpc > 0)
1610 bpp = min(bpp, 3*bpc);
1611
Manasi Navare611032b2017-01-24 08:21:49 -08001612 /* For DP Compliance we override the computed bpp for the pipe */
1613 if (intel_dp->compliance.test_data.bpc != 0) {
1614 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1615 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1616 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1617 pipe_config->pipe_bpp);
1618 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001619 return bpp;
1620}
1621
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001622bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001623intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001624 struct intel_crtc_state *pipe_config,
1625 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001626{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001627 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001628 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001629 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001630 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001631 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001632 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001633 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001634 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001635 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001636 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001637 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301638 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001639 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001640 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001641 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001642 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001643 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301644
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001645 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001646 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301647
1648 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001649 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301650
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001651 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001652
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001653 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001654 pipe_config->has_pch_encoder = true;
1655
Vandana Kannanf769cd22014-08-05 07:51:22 -07001656 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001657 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001658
Jani Nikuladd06f902012-10-19 14:51:50 +03001659 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1660 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1661 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001662
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001663 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001664 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001665 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001666 if (ret)
1667 return ret;
1668 }
1669
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001670 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001671 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1672 intel_connector->panel.fitting_mode);
1673 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001674 intel_pch_panel_fitting(intel_crtc, pipe_config,
1675 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001676 }
1677
Daniel Vettercb1793c2012-06-04 18:39:21 +02001678 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001679 return false;
1680
Manasi Navareda15f7c2017-01-24 08:16:34 -08001681 /* Use values requested by Compliance Test Request */
1682 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulab1810a72017-04-06 16:44:11 +03001683 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
1684 intel_dp->num_common_rates,
1685 intel_dp->compliance.test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08001686 if (link_rate_index >= 0)
1687 min_clock = max_clock = link_rate_index;
1688 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1689 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001690 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301691 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001692 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001693 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001694
Daniel Vetter36008362013-03-27 00:44:59 +01001695 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1696 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001697 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001698 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301699
1700 /* Get bpp from vbt only for panels that dont have bpp in edid */
1701 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001702 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001703 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001704 dev_priv->vbt.edp.bpp);
1705 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001706 }
1707
Jani Nikula344c5bb2014-09-09 11:25:13 +03001708 /*
1709 * Use the maximum clock and number of lanes the eDP panel
1710 * advertizes being capable of. The panels are generally
1711 * designed to support only a single clock and lane
1712 * configuration, and typically these values correspond to the
1713 * native resolution of the panel.
1714 */
1715 min_lane_count = max_lane_count;
1716 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001717 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001718
Daniel Vetter36008362013-03-27 00:44:59 +01001719 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001720 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1721 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001722
Dave Airliec6930992014-07-14 11:04:39 +10001723 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301724 for (lane_count = min_lane_count;
1725 lane_count <= max_lane_count;
1726 lane_count <<= 1) {
1727
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001728 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001729 link_avail = intel_dp_max_data_rate(link_clock,
1730 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001731
Daniel Vetter36008362013-03-27 00:44:59 +01001732 if (mode_rate <= link_avail) {
1733 goto found;
1734 }
1735 }
1736 }
1737 }
1738
1739 return false;
1740
1741found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001742 if (intel_dp->color_range_auto) {
1743 /*
1744 * See:
1745 * CEA-861-E - 5.1 Default Encoding Parameters
1746 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1747 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001748 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001749 bpp != 18 &&
1750 drm_default_rgb_quant_range(adjusted_mode) ==
1751 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001752 } else {
1753 pipe_config->limited_color_range =
1754 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001755 }
1756
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001757 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301758
Daniel Vetter657445f2013-05-04 10:09:18 +02001759 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001760 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001761
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001762 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1763 &link_bw, &rate_select);
1764
1765 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1766 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001767 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001768 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1769 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001770
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001771 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001772 adjusted_mode->crtc_clock,
1773 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001774 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001775
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301776 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301777 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001778 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301779 intel_link_compute_m_n(bpp, lane_count,
1780 intel_connector->panel.downclock_mode->clock,
1781 pipe_config->port_clock,
1782 &pipe_config->dp_m2_n2);
1783 }
1784
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001785 /*
1786 * DPLL0 VCO may need to be adjusted to get the correct
1787 * clock for eDP. This will affect cdclk as well.
1788 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001789 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001790 int vco;
1791
1792 switch (pipe_config->port_clock / 2) {
1793 case 108000:
1794 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001795 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001796 break;
1797 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001798 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001799 break;
1800 }
1801
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001802 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001803 }
1804
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001805 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001806 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001807
Daniel Vetter36008362013-03-27 00:44:59 +01001808 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001809}
1810
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001811void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001812 int link_rate, uint8_t lane_count,
1813 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001814{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001815 intel_dp->link_rate = link_rate;
1816 intel_dp->lane_count = lane_count;
1817 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001818}
1819
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001820static void intel_dp_prepare(struct intel_encoder *encoder,
1821 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001822{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001823 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001824 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001825 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001826 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001827 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001828 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001829
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001830 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1831 pipe_config->lane_count,
1832 intel_crtc_has_type(pipe_config,
1833 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001834
Keith Packard417e8222011-11-01 19:54:11 -07001835 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001836 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001837 *
1838 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001839 * SNB CPU
1840 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001841 * CPT PCH
1842 *
1843 * IBX PCH and CPU are the same for almost everything,
1844 * except that the CPU DP PLL is configured in this
1845 * register
1846 *
1847 * CPT PCH is quite different, having many bits moved
1848 * to the TRANS_DP_CTL register instead. That
1849 * configuration happens (oddly) in ironlake_pch_enable
1850 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001851
Keith Packard417e8222011-11-01 19:54:11 -07001852 /* Preserve the BIOS-computed detected bit. This is
1853 * supposed to be read-only.
1854 */
1855 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001856
Keith Packard417e8222011-11-01 19:54:11 -07001857 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001858 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001859 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001860
Keith Packard417e8222011-11-01 19:54:11 -07001861 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001862
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001863 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001864 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1865 intel_dp->DP |= DP_SYNC_HS_HIGH;
1866 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1867 intel_dp->DP |= DP_SYNC_VS_HIGH;
1868 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1869
Jani Nikula6aba5b62013-10-04 15:08:10 +03001870 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001871 intel_dp->DP |= DP_ENHANCED_FRAMING;
1872
Daniel Vetter7c62a162013-06-01 17:16:20 +02001873 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001874 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001875 u32 trans_dp;
1876
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001877 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001878
1879 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1880 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1881 trans_dp |= TRANS_DP_ENH_FRAMING;
1882 else
1883 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1884 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001885 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001886 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001887 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001888
1889 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1890 intel_dp->DP |= DP_SYNC_HS_HIGH;
1891 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1892 intel_dp->DP |= DP_SYNC_VS_HIGH;
1893 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1894
Jani Nikula6aba5b62013-10-04 15:08:10 +03001895 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001896 intel_dp->DP |= DP_ENHANCED_FRAMING;
1897
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001898 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001899 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001900 else if (crtc->pipe == PIPE_B)
1901 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001902 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001903}
1904
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001905#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1906#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001907
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001908#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1909#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001910
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001911#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1912#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001913
Imre Deakde9c1b62016-06-16 20:01:46 +03001914static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1915 struct intel_dp *intel_dp);
1916
Daniel Vetter4be73782014-01-17 14:39:48 +01001917static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001918 u32 mask,
1919 u32 value)
1920{
Paulo Zanoni30add222012-10-26 19:05:45 -02001921 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001922 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001923 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001924
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001925 lockdep_assert_held(&dev_priv->pps_mutex);
1926
Imre Deakde9c1b62016-06-16 20:01:46 +03001927 intel_pps_verify_state(dev_priv, intel_dp);
1928
Jani Nikulabf13e812013-09-06 07:40:05 +03001929 pp_stat_reg = _pp_stat_reg(intel_dp);
1930 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001931
1932 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001933 mask, value,
1934 I915_READ(pp_stat_reg),
1935 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001936
Chris Wilson9036ff02016-06-30 15:33:09 +01001937 if (intel_wait_for_register(dev_priv,
1938 pp_stat_reg, mask, value,
1939 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001940 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001941 I915_READ(pp_stat_reg),
1942 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001943
1944 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001945}
1946
Daniel Vetter4be73782014-01-17 14:39:48 +01001947static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001948{
1949 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001950 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001951}
1952
Daniel Vetter4be73782014-01-17 14:39:48 +01001953static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001954{
Keith Packardbd943152011-09-18 23:09:52 -07001955 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001956 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001957}
Keith Packardbd943152011-09-18 23:09:52 -07001958
Daniel Vetter4be73782014-01-17 14:39:48 +01001959static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001960{
Abhay Kumard28d4732016-01-22 17:39:04 -08001961 ktime_t panel_power_on_time;
1962 s64 panel_power_off_duration;
1963
Keith Packard99ea7122011-11-01 19:57:50 -07001964 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001965
Abhay Kumard28d4732016-01-22 17:39:04 -08001966 /* take the difference of currrent time and panel power off time
1967 * and then make panel wait for t11_t12 if needed. */
1968 panel_power_on_time = ktime_get_boottime();
1969 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1970
Paulo Zanonidce56b32013-12-19 14:29:40 -02001971 /* When we disable the VDD override bit last we have to do the manual
1972 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001973 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1974 wait_remaining_ms_from_jiffies(jiffies,
1975 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001976
Daniel Vetter4be73782014-01-17 14:39:48 +01001977 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001978}
Keith Packardbd943152011-09-18 23:09:52 -07001979
Daniel Vetter4be73782014-01-17 14:39:48 +01001980static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001981{
1982 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1983 intel_dp->backlight_on_delay);
1984}
1985
Daniel Vetter4be73782014-01-17 14:39:48 +01001986static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001987{
1988 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1989 intel_dp->backlight_off_delay);
1990}
Keith Packard99ea7122011-11-01 19:57:50 -07001991
Keith Packard832dd3c2011-11-01 19:34:06 -07001992/* Read the current pp_control value, unlocking the register if it
1993 * is locked
1994 */
1995
Jesse Barnes453c5422013-03-28 09:55:41 -07001996static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001997{
Jesse Barnes453c5422013-03-28 09:55:41 -07001998 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001999 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002000 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002001
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002002 lockdep_assert_held(&dev_priv->pps_mutex);
2003
Jani Nikulabf13e812013-09-06 07:40:05 +03002004 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002005 if (WARN_ON(!HAS_DDI(dev_priv) &&
2006 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302007 control &= ~PANEL_UNLOCK_MASK;
2008 control |= PANEL_UNLOCK_REGS;
2009 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002010 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002011}
2012
Ville Syrjälä951468f2014-09-04 14:55:31 +03002013/*
2014 * Must be paired with edp_panel_vdd_off().
2015 * Must hold pps_mutex around the whole on/off sequence.
2016 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2017 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002018static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002019{
Paulo Zanoni30add222012-10-26 19:05:45 -02002020 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002021 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002022 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002023 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002024 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002025 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002026
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002027 lockdep_assert_held(&dev_priv->pps_mutex);
2028
Keith Packard97af61f572011-09-28 16:23:51 -07002029 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002030 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002031
Egbert Eich2c623c12014-11-25 12:54:57 +01002032 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002033 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002034
Daniel Vetter4be73782014-01-17 14:39:48 +01002035 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002036 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002037
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002038 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002039
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002040 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2041 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002042
Daniel Vetter4be73782014-01-17 14:39:48 +01002043 if (!edp_have_panel_power(intel_dp))
2044 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002045
Jesse Barnes453c5422013-03-28 09:55:41 -07002046 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002047 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002048
Jani Nikulabf13e812013-09-06 07:40:05 +03002049 pp_stat_reg = _pp_stat_reg(intel_dp);
2050 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002051
2052 I915_WRITE(pp_ctrl_reg, pp);
2053 POSTING_READ(pp_ctrl_reg);
2054 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2055 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002056 /*
2057 * If the panel wasn't on, delay before accessing aux channel
2058 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002059 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002060 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2061 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002062 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002063 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002064
2065 return need_to_disable;
2066}
2067
Ville Syrjälä951468f2014-09-04 14:55:31 +03002068/*
2069 * Must be paired with intel_edp_panel_vdd_off() or
2070 * intel_edp_panel_off().
2071 * Nested calls to these functions are not allowed since
2072 * we drop the lock. Caller must use some higher level
2073 * locking to prevent nested calls from other threads.
2074 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002075void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002076{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002077 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002078
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002079 if (!is_edp(intel_dp))
2080 return;
2081
Ville Syrjälä773538e82014-09-04 14:54:56 +03002082 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002083 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002084 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002085
Rob Clarke2c719b2014-12-15 13:56:32 -05002086 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002087 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002088}
2089
Daniel Vetter4be73782014-01-17 14:39:48 +01002090static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002091{
Paulo Zanoni30add222012-10-26 19:05:45 -02002092 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002093 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002094 struct intel_digital_port *intel_dig_port =
2095 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002096 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002097 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002098
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002099 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002100
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002101 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002102
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002103 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002104 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002105
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002106 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2107 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002108
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002109 pp = ironlake_get_pp_control(intel_dp);
2110 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002111
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002112 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2113 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002114
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002115 I915_WRITE(pp_ctrl_reg, pp);
2116 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002117
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002118 /* Make sure sequencer is idle before allowing subsequent activity */
2119 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2120 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002121
Imre Deak5a162e22016-08-10 14:07:30 +03002122 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002123 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002124
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002125 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002126}
2127
Daniel Vetter4be73782014-01-17 14:39:48 +01002128static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002129{
2130 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2131 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002132
Ville Syrjälä773538e82014-09-04 14:54:56 +03002133 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002134 if (!intel_dp->want_panel_vdd)
2135 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002136 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002137}
2138
Imre Deakaba86892014-07-30 15:57:31 +03002139static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2140{
2141 unsigned long delay;
2142
2143 /*
2144 * Queue the timer to fire a long time from now (relative to the power
2145 * down delay) to keep the panel power up across a sequence of
2146 * operations.
2147 */
2148 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2149 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2150}
2151
Ville Syrjälä951468f2014-09-04 14:55:31 +03002152/*
2153 * Must be paired with edp_panel_vdd_on().
2154 * Must hold pps_mutex around the whole on/off sequence.
2155 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2156 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002157static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002158{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002159 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002160
2161 lockdep_assert_held(&dev_priv->pps_mutex);
2162
Keith Packard97af61f572011-09-28 16:23:51 -07002163 if (!is_edp(intel_dp))
2164 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002165
Rob Clarke2c719b2014-12-15 13:56:32 -05002166 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002167 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002168
Keith Packardbd943152011-09-18 23:09:52 -07002169 intel_dp->want_panel_vdd = false;
2170
Imre Deakaba86892014-07-30 15:57:31 +03002171 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002172 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002173 else
2174 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002175}
2176
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002177static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002178{
Paulo Zanoni30add222012-10-26 19:05:45 -02002179 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002180 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002181 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002182 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002183
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002184 lockdep_assert_held(&dev_priv->pps_mutex);
2185
Keith Packard97af61f572011-09-28 16:23:51 -07002186 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002187 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002188
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002189 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2190 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002191
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002192 if (WARN(edp_have_panel_power(intel_dp),
2193 "eDP port %c panel power already on\n",
2194 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002195 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002196
Daniel Vetter4be73782014-01-17 14:39:48 +01002197 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002198
Jani Nikulabf13e812013-09-06 07:40:05 +03002199 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002200 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002201 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002202 /* ILK workaround: disable reset around power sequence */
2203 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002204 I915_WRITE(pp_ctrl_reg, pp);
2205 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002206 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002207
Imre Deak5a162e22016-08-10 14:07:30 +03002208 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002209 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002210 pp |= PANEL_POWER_RESET;
2211
Jesse Barnes453c5422013-03-28 09:55:41 -07002212 I915_WRITE(pp_ctrl_reg, pp);
2213 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002214
Daniel Vetter4be73782014-01-17 14:39:48 +01002215 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002216 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002217
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002218 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002219 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002220 I915_WRITE(pp_ctrl_reg, pp);
2221 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002222 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002223}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002224
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002225void intel_edp_panel_on(struct intel_dp *intel_dp)
2226{
2227 if (!is_edp(intel_dp))
2228 return;
2229
2230 pps_lock(intel_dp);
2231 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002232 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002233}
2234
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002235
2236static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002237{
Paulo Zanoni30add222012-10-26 19:05:45 -02002238 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002239 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002240 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002241 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002242
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002243 lockdep_assert_held(&dev_priv->pps_mutex);
2244
Keith Packard97af61f572011-09-28 16:23:51 -07002245 if (!is_edp(intel_dp))
2246 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002247
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002248 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2249 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002250
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002251 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2252 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002253
Jesse Barnes453c5422013-03-28 09:55:41 -07002254 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002255 /* We need to switch off panel power _and_ force vdd, for otherwise some
2256 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002257 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002258 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002259
Jani Nikulabf13e812013-09-06 07:40:05 +03002260 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002261
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002262 intel_dp->want_panel_vdd = false;
2263
Jesse Barnes453c5422013-03-28 09:55:41 -07002264 I915_WRITE(pp_ctrl_reg, pp);
2265 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002266
Abhay Kumard28d4732016-01-22 17:39:04 -08002267 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002268 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002269
2270 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002271 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002272}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002273
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002274void intel_edp_panel_off(struct intel_dp *intel_dp)
2275{
2276 if (!is_edp(intel_dp))
2277 return;
2278
2279 pps_lock(intel_dp);
2280 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002281 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002282}
2283
Jani Nikula1250d102014-08-12 17:11:39 +03002284/* Enable backlight in the panel power control. */
2285static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002286{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002287 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2288 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002289 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002290 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002291 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002292
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002293 /*
2294 * If we enable the backlight right away following a panel power
2295 * on, we may see slight flicker as the panel syncs with the eDP
2296 * link. So delay a bit to make sure the image is solid before
2297 * allowing it to appear.
2298 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002299 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002300
Ville Syrjälä773538e82014-09-04 14:54:56 +03002301 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002302
Jesse Barnes453c5422013-03-28 09:55:41 -07002303 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002304 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002305
Jani Nikulabf13e812013-09-06 07:40:05 +03002306 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002307
2308 I915_WRITE(pp_ctrl_reg, pp);
2309 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002310
Ville Syrjälä773538e82014-09-04 14:54:56 +03002311 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002312}
2313
Jani Nikula1250d102014-08-12 17:11:39 +03002314/* Enable backlight PWM and backlight PP control. */
2315void intel_edp_backlight_on(struct intel_dp *intel_dp)
2316{
2317 if (!is_edp(intel_dp))
2318 return;
2319
2320 DRM_DEBUG_KMS("\n");
2321
2322 intel_panel_enable_backlight(intel_dp->attached_connector);
2323 _intel_edp_backlight_on(intel_dp);
2324}
2325
2326/* Disable backlight in the panel power control. */
2327static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002328{
Paulo Zanoni30add222012-10-26 19:05:45 -02002329 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002330 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002331 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002332 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002333
Keith Packardf01eca22011-09-28 16:48:10 -07002334 if (!is_edp(intel_dp))
2335 return;
2336
Ville Syrjälä773538e82014-09-04 14:54:56 +03002337 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002338
Jesse Barnes453c5422013-03-28 09:55:41 -07002339 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002340 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002341
Jani Nikulabf13e812013-09-06 07:40:05 +03002342 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002343
2344 I915_WRITE(pp_ctrl_reg, pp);
2345 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002346
Ville Syrjälä773538e82014-09-04 14:54:56 +03002347 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002348
Paulo Zanonidce56b32013-12-19 14:29:40 -02002349 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002350 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002351}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002352
Jani Nikula1250d102014-08-12 17:11:39 +03002353/* Disable backlight PP control and backlight PWM. */
2354void intel_edp_backlight_off(struct intel_dp *intel_dp)
2355{
2356 if (!is_edp(intel_dp))
2357 return;
2358
2359 DRM_DEBUG_KMS("\n");
2360
2361 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002362 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002363}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002364
Jani Nikula73580fb72014-08-12 17:11:41 +03002365/*
2366 * Hook for controlling the panel power control backlight through the bl_power
2367 * sysfs attribute. Take care to handle multiple calls.
2368 */
2369static void intel_edp_backlight_power(struct intel_connector *connector,
2370 bool enable)
2371{
2372 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002373 bool is_enabled;
2374
Ville Syrjälä773538e82014-09-04 14:54:56 +03002375 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002376 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002377 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002378
2379 if (is_enabled == enable)
2380 return;
2381
Jani Nikula23ba9372014-08-27 14:08:43 +03002382 DRM_DEBUG_KMS("panel power control backlight %s\n",
2383 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002384
2385 if (enable)
2386 _intel_edp_backlight_on(intel_dp);
2387 else
2388 _intel_edp_backlight_off(intel_dp);
2389}
2390
Ville Syrjälä64e10772015-10-29 21:26:01 +02002391static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2392{
2393 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2394 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2395 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2396
2397 I915_STATE_WARN(cur_state != state,
2398 "DP port %c state assertion failure (expected %s, current %s)\n",
2399 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002400 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002401}
2402#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2403
2404static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2405{
2406 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2407
2408 I915_STATE_WARN(cur_state != state,
2409 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002410 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002411}
2412#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2413#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2414
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002415static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2416 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002417{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002418 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002419 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002420
Ville Syrjälä64e10772015-10-29 21:26:01 +02002421 assert_pipe_disabled(dev_priv, crtc->pipe);
2422 assert_dp_port_disabled(intel_dp);
2423 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002424
Ville Syrjäläabfce942015-10-29 21:26:03 +02002425 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002426 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002427
2428 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2429
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002430 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002431 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2432 else
2433 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2434
2435 I915_WRITE(DP_A, intel_dp->DP);
2436 POSTING_READ(DP_A);
2437 udelay(500);
2438
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002439 /*
2440 * [DevILK] Work around required when enabling DP PLL
2441 * while a pipe is enabled going to FDI:
2442 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2443 * 2. Program DP PLL enable
2444 */
2445 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002446 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002447
Daniel Vetter07679352012-09-06 22:15:42 +02002448 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002449
Daniel Vetter07679352012-09-06 22:15:42 +02002450 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002451 POSTING_READ(DP_A);
2452 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002453}
2454
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002455static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002456{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002457 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002458 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2459 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002460
Ville Syrjälä64e10772015-10-29 21:26:01 +02002461 assert_pipe_disabled(dev_priv, crtc->pipe);
2462 assert_dp_port_disabled(intel_dp);
2463 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002464
Ville Syrjäläabfce942015-10-29 21:26:03 +02002465 DRM_DEBUG_KMS("disabling eDP PLL\n");
2466
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002467 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002468
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002469 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002470 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002471 udelay(200);
2472}
2473
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002474/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002475void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002476{
2477 int ret, i;
2478
2479 /* Should have a valid DPCD by this point */
2480 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2481 return;
2482
2483 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002484 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2485 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002486 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002487 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2488
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002489 /*
2490 * When turning on, we need to retry for 1ms to give the sink
2491 * time to wake up.
2492 */
2493 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002494 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2495 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002496 if (ret == 1)
2497 break;
2498 msleep(1);
2499 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002500
2501 if (ret == 1 && lspcon->active)
2502 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002503 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002504
2505 if (ret != 1)
2506 DRM_DEBUG_KMS("failed to %s sink power state\n",
2507 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002508}
2509
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002510static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2511 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002512{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002513 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002514 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002515 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002516 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002517 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002518 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002519
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002520 if (!intel_display_power_get_if_enabled(dev_priv,
2521 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002522 return false;
2523
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002524 ret = false;
2525
Imre Deak6d129be2014-03-05 16:20:54 +02002526 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002527
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002528 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002529 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002530
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002531 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002532 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002533 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002534 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002535
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002536 for_each_pipe(dev_priv, p) {
2537 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2538 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2539 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002540 ret = true;
2541
2542 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002543 }
2544 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002545
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002546 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002547 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002548 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002549 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2550 } else {
2551 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002552 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002553
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002554 ret = true;
2555
2556out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002557 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002558
2559 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002560}
2561
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002562static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002563 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002564{
2565 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002566 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002567 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002568 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002569 enum port port = dp_to_dig_port(intel_dp)->port;
2570 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002571
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002572 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002573
2574 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002575
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002576 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002577 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2578
2579 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002580 flags |= DRM_MODE_FLAG_PHSYNC;
2581 else
2582 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002583
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002584 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002585 flags |= DRM_MODE_FLAG_PVSYNC;
2586 else
2587 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002588 } else {
2589 if (tmp & DP_SYNC_HS_HIGH)
2590 flags |= DRM_MODE_FLAG_PHSYNC;
2591 else
2592 flags |= DRM_MODE_FLAG_NHSYNC;
2593
2594 if (tmp & DP_SYNC_VS_HIGH)
2595 flags |= DRM_MODE_FLAG_PVSYNC;
2596 else
2597 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002598 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002599
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002600 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002601
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002602 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002603 pipe_config->limited_color_range = true;
2604
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002605 pipe_config->lane_count =
2606 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2607
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002608 intel_dp_get_m_n(crtc, pipe_config);
2609
Ville Syrjälä18442d02013-09-13 16:00:08 +03002610 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002611 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002612 pipe_config->port_clock = 162000;
2613 else
2614 pipe_config->port_clock = 270000;
2615 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002616
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002617 pipe_config->base.adjusted_mode.crtc_clock =
2618 intel_dotclock_calculate(pipe_config->port_clock,
2619 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002620
Jani Nikula6aa23e62016-03-24 17:50:20 +02002621 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2622 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002623 /*
2624 * This is a big fat ugly hack.
2625 *
2626 * Some machines in UEFI boot mode provide us a VBT that has 18
2627 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2628 * unknown we fail to light up. Yet the same BIOS boots up with
2629 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2630 * max, not what it tells us to use.
2631 *
2632 * Note: This will still be broken if the eDP panel is not lit
2633 * up by the BIOS, and thus we can't get the mode at module
2634 * load.
2635 */
2636 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002637 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2638 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002639 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002640}
2641
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002642static void intel_disable_dp(struct intel_encoder *encoder,
2643 struct intel_crtc_state *old_crtc_state,
2644 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002645{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002646 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002647 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002648
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002649 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002650 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002651
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002652 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002653 intel_psr_disable(intel_dp);
2654
Daniel Vetter6cb49832012-05-20 17:14:50 +02002655 /* Make sure the panel is off before trying to change the mode. But also
2656 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002657 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002658 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002659 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002660 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002661
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002662 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002663 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002664 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002665}
2666
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002667static void ilk_post_disable_dp(struct intel_encoder *encoder,
2668 struct intel_crtc_state *old_crtc_state,
2669 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002670{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002671 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002672 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002673
Ville Syrjälä49277c32014-03-31 18:21:26 +03002674 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002675
2676 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002677 if (port == PORT_A)
2678 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002679}
2680
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002681static void vlv_post_disable_dp(struct intel_encoder *encoder,
2682 struct intel_crtc_state *old_crtc_state,
2683 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002684{
2685 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2686
2687 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002688}
2689
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002690static void chv_post_disable_dp(struct intel_encoder *encoder,
2691 struct intel_crtc_state *old_crtc_state,
2692 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002693{
2694 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002695 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002696 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002697
2698 intel_dp_link_down(intel_dp);
2699
Ville Syrjäläa5805162015-05-26 20:42:30 +03002700 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002701
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002702 /* Assert data lane reset */
2703 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002704
Ville Syrjäläa5805162015-05-26 20:42:30 +03002705 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002706}
2707
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002708static void
2709_intel_dp_set_link_train(struct intel_dp *intel_dp,
2710 uint32_t *DP,
2711 uint8_t dp_train_pat)
2712{
2713 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2714 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002715 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002716 enum port port = intel_dig_port->port;
2717
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002718 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2719 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2720 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2721
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002722 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002723 uint32_t temp = I915_READ(DP_TP_CTL(port));
2724
2725 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2726 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2727 else
2728 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2729
2730 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2731 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2732 case DP_TRAINING_PATTERN_DISABLE:
2733 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2734
2735 break;
2736 case DP_TRAINING_PATTERN_1:
2737 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2738 break;
2739 case DP_TRAINING_PATTERN_2:
2740 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2741 break;
2742 case DP_TRAINING_PATTERN_3:
2743 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2744 break;
2745 }
2746 I915_WRITE(DP_TP_CTL(port), temp);
2747
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002748 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002749 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002750 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2751
2752 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2753 case DP_TRAINING_PATTERN_DISABLE:
2754 *DP |= DP_LINK_TRAIN_OFF_CPT;
2755 break;
2756 case DP_TRAINING_PATTERN_1:
2757 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2758 break;
2759 case DP_TRAINING_PATTERN_2:
2760 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2761 break;
2762 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002763 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002764 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2765 break;
2766 }
2767
2768 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002769 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002770 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2771 else
2772 *DP &= ~DP_LINK_TRAIN_MASK;
2773
2774 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2775 case DP_TRAINING_PATTERN_DISABLE:
2776 *DP |= DP_LINK_TRAIN_OFF;
2777 break;
2778 case DP_TRAINING_PATTERN_1:
2779 *DP |= DP_LINK_TRAIN_PAT_1;
2780 break;
2781 case DP_TRAINING_PATTERN_2:
2782 *DP |= DP_LINK_TRAIN_PAT_2;
2783 break;
2784 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002785 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002786 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2787 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002788 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002789 *DP |= DP_LINK_TRAIN_PAT_2;
2790 }
2791 break;
2792 }
2793 }
2794}
2795
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002796static void intel_dp_enable_port(struct intel_dp *intel_dp,
2797 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002798{
2799 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002800 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002801
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002802 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002803
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002804 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002805
2806 /*
2807 * Magic for VLV/CHV. We _must_ first set up the register
2808 * without actually enabling the port, and then do another
2809 * write to enable the port. Otherwise link training will
2810 * fail when the power sequencer is freshly used for this port.
2811 */
2812 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002813 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002814 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002815
2816 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2817 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002818}
2819
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002820static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002821 struct intel_crtc_state *pipe_config,
2822 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002823{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002824 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2825 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002826 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002827 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002828 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002829 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002830
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002831 if (WARN_ON(dp_reg & DP_PORT_EN))
2832 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002833
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002834 pps_lock(intel_dp);
2835
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002836 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002837 vlv_init_panel_power_sequencer(intel_dp);
2838
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002839 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002840
2841 edp_panel_vdd_on(intel_dp);
2842 edp_panel_on(intel_dp);
2843 edp_panel_vdd_off(intel_dp, true);
2844
2845 pps_unlock(intel_dp);
2846
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002847 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002848 unsigned int lane_mask = 0x0;
2849
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002850 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002851 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002852
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002853 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2854 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002855 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002856
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002857 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2858 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002859 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002860
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002861 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002862 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002863 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002864 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002865 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002866}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002867
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002868static void g4x_enable_dp(struct intel_encoder *encoder,
2869 struct intel_crtc_state *pipe_config,
2870 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002871{
Jani Nikula828f5c62013-09-05 16:44:45 +03002872 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2873
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002874 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002875 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002876}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002877
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002878static void vlv_enable_dp(struct intel_encoder *encoder,
2879 struct intel_crtc_state *pipe_config,
2880 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002881{
Jani Nikula828f5c62013-09-05 16:44:45 +03002882 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2883
Daniel Vetter4be73782014-01-17 14:39:48 +01002884 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002885 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002886}
2887
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002888static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2889 struct intel_crtc_state *pipe_config,
2890 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002891{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002892 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002893 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002894
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002895 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002896
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002897 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002898 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002899 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002900}
2901
Ville Syrjälä83b84592014-10-16 21:29:51 +03002902static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2903{
2904 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002905 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002906 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002907 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002908
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002909 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2910
Ville Syrjäläd1586942017-02-08 19:52:54 +02002911 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2912 return;
2913
Ville Syrjälä83b84592014-10-16 21:29:51 +03002914 edp_panel_vdd_off_sync(intel_dp);
2915
2916 /*
2917 * VLV seems to get confused when multiple power seqeuencers
2918 * have the same port selected (even if only one has power/vdd
2919 * enabled). The failure manifests as vlv_wait_port_ready() failing
2920 * CHV on the other hand doesn't seem to mind having the same port
2921 * selected in multiple power seqeuencers, but let's clear the
2922 * port select always when logically disconnecting a power sequencer
2923 * from a port.
2924 */
2925 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2926 pipe_name(pipe), port_name(intel_dig_port->port));
2927 I915_WRITE(pp_on_reg, 0);
2928 POSTING_READ(pp_on_reg);
2929
2930 intel_dp->pps_pipe = INVALID_PIPE;
2931}
2932
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002933static void vlv_steal_power_sequencer(struct drm_device *dev,
2934 enum pipe pipe)
2935{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002936 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002937 struct intel_encoder *encoder;
2938
2939 lockdep_assert_held(&dev_priv->pps_mutex);
2940
Jani Nikula19c80542015-12-16 12:48:16 +02002941 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002942 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002943 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002944
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002945 if (encoder->type != INTEL_OUTPUT_DP &&
2946 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002947 continue;
2948
2949 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002950 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002951
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002952 WARN(intel_dp->active_pipe == pipe,
2953 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2954 pipe_name(pipe), port_name(port));
2955
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002956 if (intel_dp->pps_pipe != pipe)
2957 continue;
2958
2959 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002960 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002961
2962 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002963 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002964 }
2965}
2966
2967static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2968{
2969 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2970 struct intel_encoder *encoder = &intel_dig_port->base;
2971 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002972 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002973 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002974
2975 lockdep_assert_held(&dev_priv->pps_mutex);
2976
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002977 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002978
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002979 if (intel_dp->pps_pipe != INVALID_PIPE &&
2980 intel_dp->pps_pipe != crtc->pipe) {
2981 /*
2982 * If another power sequencer was being used on this
2983 * port previously make sure to turn off vdd there while
2984 * we still have control of it.
2985 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002986 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002987 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002988
2989 /*
2990 * We may be stealing the power
2991 * sequencer from another port.
2992 */
2993 vlv_steal_power_sequencer(dev, crtc->pipe);
2994
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002995 intel_dp->active_pipe = crtc->pipe;
2996
2997 if (!is_edp(intel_dp))
2998 return;
2999
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003000 /* now it's all ours */
3001 intel_dp->pps_pipe = crtc->pipe;
3002
3003 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3004 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3005
3006 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003007 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003008 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003009}
3010
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003011static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3012 struct intel_crtc_state *pipe_config,
3013 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003014{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003015 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003016
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003017 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003018}
3019
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003020static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3021 struct intel_crtc_state *pipe_config,
3022 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003023{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003024 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003025
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003026 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003027}
3028
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003029static void chv_pre_enable_dp(struct intel_encoder *encoder,
3030 struct intel_crtc_state *pipe_config,
3031 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003032{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003033 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003034
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003035 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003036
3037 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003038 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003039}
3040
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003041static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3042 struct intel_crtc_state *pipe_config,
3043 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003044{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003045 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003046
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003047 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003048}
3049
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003050static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3051 struct intel_crtc_state *pipe_config,
3052 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003053{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003054 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003055}
3056
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003057/*
3058 * Fetch AUX CH registers 0x202 - 0x207 which contain
3059 * link status information
3060 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003061bool
Keith Packard93f62da2011-11-01 19:45:03 -07003062intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003063{
Lyude9f085eb2016-04-13 10:58:33 -04003064 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3065 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003066}
3067
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303068static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3069{
3070 uint8_t psr_caps = 0;
3071
3072 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3073 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3074}
3075
3076static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3077{
3078 uint8_t dprx = 0;
3079
3080 drm_dp_dpcd_readb(&intel_dp->aux,
3081 DP_DPRX_FEATURE_ENUMERATION_LIST,
3082 &dprx);
3083 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3084}
3085
Chris Wilsona76f73d2017-01-14 10:51:13 +00003086static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303087{
3088 uint8_t alpm_caps = 0;
3089
3090 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3091 return alpm_caps & DP_ALPM_CAP;
3092}
3093
Paulo Zanoni11002442014-06-13 18:45:41 -03003094/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003095uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003096intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003097{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003098 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003099 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003100
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003101 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303102 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003103 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003104 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3105 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003106 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003108 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303109 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003110 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303111 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003112 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303113 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003114}
3115
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003116uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003117intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3118{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003119 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003120 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003121
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003122 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003123 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3124 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3125 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3127 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3128 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3129 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303130 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3131 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003132 default:
3133 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3134 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003135 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003136 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3138 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3139 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3140 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3142 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3143 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003144 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303145 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003146 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003147 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003148 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3150 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3151 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3152 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3153 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3154 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3155 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003156 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303157 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003158 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003159 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003160 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303161 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3162 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3163 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3164 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3165 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003166 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303167 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003168 }
3169 } else {
3170 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303171 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3172 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3174 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3176 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003178 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303179 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003180 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003181 }
3182}
3183
Daniel Vetter5829975c2015-04-16 11:36:52 +02003184static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003185{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003186 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003187 unsigned long demph_reg_value, preemph_reg_value,
3188 uniqtranscale_reg_value;
3189 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003190
3191 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303192 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003193 preemph_reg_value = 0x0004000;
3194 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003196 demph_reg_value = 0x2B405555;
3197 uniqtranscale_reg_value = 0x552AB83A;
3198 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003200 demph_reg_value = 0x2B404040;
3201 uniqtranscale_reg_value = 0x5548B83A;
3202 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204 demph_reg_value = 0x2B245555;
3205 uniqtranscale_reg_value = 0x5560B83A;
3206 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303207 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003208 demph_reg_value = 0x2B405555;
3209 uniqtranscale_reg_value = 0x5598DA3A;
3210 break;
3211 default:
3212 return 0;
3213 }
3214 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003216 preemph_reg_value = 0x0002000;
3217 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 demph_reg_value = 0x2B404040;
3220 uniqtranscale_reg_value = 0x5552B83A;
3221 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003223 demph_reg_value = 0x2B404848;
3224 uniqtranscale_reg_value = 0x5580B83A;
3225 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303226 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003227 demph_reg_value = 0x2B404040;
3228 uniqtranscale_reg_value = 0x55ADDA3A;
3229 break;
3230 default:
3231 return 0;
3232 }
3233 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303234 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003235 preemph_reg_value = 0x0000000;
3236 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303237 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003238 demph_reg_value = 0x2B305555;
3239 uniqtranscale_reg_value = 0x5570B83A;
3240 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303241 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003242 demph_reg_value = 0x2B2B4040;
3243 uniqtranscale_reg_value = 0x55ADDA3A;
3244 break;
3245 default:
3246 return 0;
3247 }
3248 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303249 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003250 preemph_reg_value = 0x0006000;
3251 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303252 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003253 demph_reg_value = 0x1B405555;
3254 uniqtranscale_reg_value = 0x55ADDA3A;
3255 break;
3256 default:
3257 return 0;
3258 }
3259 break;
3260 default:
3261 return 0;
3262 }
3263
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003264 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3265 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003266
3267 return 0;
3268}
3269
Daniel Vetter5829975c2015-04-16 11:36:52 +02003270static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003271{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003272 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3273 u32 deemph_reg_value, margin_reg_value;
3274 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003275 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003276
3277 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303278 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003279 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303280 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003281 deemph_reg_value = 128;
3282 margin_reg_value = 52;
3283 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003285 deemph_reg_value = 128;
3286 margin_reg_value = 77;
3287 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003289 deemph_reg_value = 128;
3290 margin_reg_value = 102;
3291 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303292 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003293 deemph_reg_value = 128;
3294 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003295 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003296 break;
3297 default:
3298 return 0;
3299 }
3300 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303301 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003302 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 deemph_reg_value = 85;
3305 margin_reg_value = 78;
3306 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003308 deemph_reg_value = 85;
3309 margin_reg_value = 116;
3310 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303311 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003312 deemph_reg_value = 85;
3313 margin_reg_value = 154;
3314 break;
3315 default:
3316 return 0;
3317 }
3318 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003320 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003322 deemph_reg_value = 64;
3323 margin_reg_value = 104;
3324 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303325 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003326 deemph_reg_value = 64;
3327 margin_reg_value = 154;
3328 break;
3329 default:
3330 return 0;
3331 }
3332 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303333 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003334 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303335 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003336 deemph_reg_value = 43;
3337 margin_reg_value = 154;
3338 break;
3339 default:
3340 return 0;
3341 }
3342 break;
3343 default:
3344 return 0;
3345 }
3346
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003347 chv_set_phy_signal_level(encoder, deemph_reg_value,
3348 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003349
3350 return 0;
3351}
3352
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003353static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003354gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003355{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003356 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003357
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003358 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303359 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003360 default:
3361 signal_levels |= DP_VOLTAGE_0_4;
3362 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303363 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003364 signal_levels |= DP_VOLTAGE_0_6;
3365 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303366 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003367 signal_levels |= DP_VOLTAGE_0_8;
3368 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303369 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003370 signal_levels |= DP_VOLTAGE_1_2;
3371 break;
3372 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003373 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303374 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003375 default:
3376 signal_levels |= DP_PRE_EMPHASIS_0;
3377 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303378 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003379 signal_levels |= DP_PRE_EMPHASIS_3_5;
3380 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303381 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003382 signal_levels |= DP_PRE_EMPHASIS_6;
3383 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303384 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003385 signal_levels |= DP_PRE_EMPHASIS_9_5;
3386 break;
3387 }
3388 return signal_levels;
3389}
3390
Zhenyu Wange3421a12010-04-08 09:43:27 +08003391/* Gen6's DP voltage swing and pre-emphasis control */
3392static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003393gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003394{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003395 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3396 DP_TRAIN_PRE_EMPHASIS_MASK);
3397 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303398 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3399 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003400 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303401 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003402 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303403 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3404 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003405 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303406 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3407 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003408 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303409 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003411 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003412 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003413 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3414 "0x%x\n", signal_levels);
3415 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003416 }
3417}
3418
Keith Packard1a2eb462011-11-16 16:26:07 -08003419/* Gen7's DP voltage swing and pre-emphasis control */
3420static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003421gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003422{
3423 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3424 DP_TRAIN_PRE_EMPHASIS_MASK);
3425 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303426 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003427 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303428 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003429 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303430 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003431 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3432
Sonika Jindalbd600182014-08-08 16:23:41 +05303433 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003434 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303435 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003436 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3437
Sonika Jindalbd600182014-08-08 16:23:41 +05303438 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003439 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303440 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003441 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3442
3443 default:
3444 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3445 "0x%x\n", signal_levels);
3446 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3447 }
3448}
3449
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003450void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003451intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003452{
3453 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003454 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003455 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003456 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003457 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003458 uint8_t train_set = intel_dp->train_set[0];
3459
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003460 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003461 signal_levels = ddi_signal_levels(intel_dp);
3462
Michel Thierry254e0932017-01-09 16:51:35 +02003463 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003464 signal_levels = 0;
3465 else
3466 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003467 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003468 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003469 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003470 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003471 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003472 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003473 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003474 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003475 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003476 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3477 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003478 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003479 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3480 }
3481
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303482 if (mask)
3483 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3484
3485 DRM_DEBUG_KMS("Using vswing level %d\n",
3486 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3487 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3488 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3489 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003490
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003491 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003492
3493 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3494 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003495}
3496
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003497void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003498intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3499 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003500{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003501 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003502 struct drm_i915_private *dev_priv =
3503 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003504
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003505 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003506
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003507 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003508 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003509}
3510
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003511void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003512{
3513 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3514 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003515 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003516 enum port port = intel_dig_port->port;
3517 uint32_t val;
3518
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003519 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003520 return;
3521
3522 val = I915_READ(DP_TP_CTL(port));
3523 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3524 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3525 I915_WRITE(DP_TP_CTL(port), val);
3526
3527 /*
3528 * On PORT_A we can have only eDP in SST mode. There the only reason
3529 * we need to set idle transmission mode is to work around a HW issue
3530 * where we enable the pipe while not in idle link-training mode.
3531 * In this case there is requirement to wait for a minimum number of
3532 * idle patterns to be sent.
3533 */
3534 if (port == PORT_A)
3535 return;
3536
Chris Wilsona7670172016-06-30 15:33:10 +01003537 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3538 DP_TP_STATUS_IDLE_DONE,
3539 DP_TP_STATUS_IDLE_DONE,
3540 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003541 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3542}
3543
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003544static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003545intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003546{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003547 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003548 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003549 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003550 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003551 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003552 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003553
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003554 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003555 return;
3556
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003557 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003558 return;
3559
Zhao Yakui28c97732009-10-09 11:39:41 +08003560 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003561
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003562 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003563 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003564 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003565 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003566 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003567 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003568 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3569 else
3570 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003571 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003572 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003573 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003574 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003575
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003576 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3577 I915_WRITE(intel_dp->output_reg, DP);
3578 POSTING_READ(intel_dp->output_reg);
3579
3580 /*
3581 * HW workaround for IBX, we need to move the port
3582 * to transcoder A after disabling it to allow the
3583 * matching HDMI port to be enabled on transcoder A.
3584 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003585 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003586 /*
3587 * We get CPU/PCH FIFO underruns on the other pipe when
3588 * doing the workaround. Sweep them under the rug.
3589 */
3590 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3591 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3592
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003593 /* always enable with pattern 1 (as per spec) */
3594 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3595 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3596 I915_WRITE(intel_dp->output_reg, DP);
3597 POSTING_READ(intel_dp->output_reg);
3598
3599 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003600 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003601 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003602
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003603 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003604 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3605 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003606 }
3607
Keith Packardf01eca22011-09-28 16:48:10 -07003608 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003609
3610 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003611
3612 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3613 pps_lock(intel_dp);
3614 intel_dp->active_pipe = INVALID_PIPE;
3615 pps_unlock(intel_dp);
3616 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003617}
3618
Imre Deak24e807e2016-10-24 19:33:28 +03003619bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003620intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003621{
Lyude9f085eb2016-04-13 10:58:33 -04003622 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3623 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003624 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003625
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003626 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003627
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003628 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3629}
3630
3631static bool
3632intel_edp_init_dpcd(struct intel_dp *intel_dp)
3633{
3634 struct drm_i915_private *dev_priv =
3635 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3636
3637 /* this function is meant to be called only once */
3638 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3639
3640 if (!intel_dp_read_dpcd(intel_dp))
3641 return false;
3642
Imre Deak12a47a422016-10-24 19:33:29 +03003643 intel_dp_read_desc(intel_dp);
3644
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003645 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3646 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3647 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3648
3649 /* Check if the panel supports PSR */
3650 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3651 intel_dp->psr_dpcd,
3652 sizeof(intel_dp->psr_dpcd));
3653 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3654 dev_priv->psr.sink_support = true;
3655 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3656 }
3657
3658 if (INTEL_GEN(dev_priv) >= 9 &&
3659 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3660 uint8_t frame_sync_cap;
3661
3662 dev_priv->psr.sink_support = true;
3663 drm_dp_dpcd_read(&intel_dp->aux,
3664 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3665 &frame_sync_cap, 1);
3666 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3667 /* PSR2 needs frame sync as well */
3668 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3669 DRM_DEBUG_KMS("PSR2 %s on sink",
3670 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303671
3672 if (dev_priv->psr.psr2_support) {
3673 dev_priv->psr.y_cord_support =
3674 intel_dp_get_y_cord_status(intel_dp);
3675 dev_priv->psr.colorimetry_support =
3676 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303677 dev_priv->psr.alpm =
3678 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303679 }
3680
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003681 }
3682
3683 /* Read the eDP Display control capabilities registers */
3684 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3685 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003686 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3687 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003688 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3689 intel_dp->edp_dpcd);
3690
3691 /* Intermediate frequency support */
3692 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3693 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3694 int i;
3695
3696 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3697 sink_rates, sizeof(sink_rates));
3698
3699 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3700 int val = le16_to_cpu(sink_rates[i]);
3701
3702 if (val == 0)
3703 break;
3704
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003705 /* Value read multiplied by 200kHz gives the per-lane
3706 * link rate in kHz. The source rates are, however,
3707 * stored in terms of LS_Clk kHz. The full conversion
3708 * back to symbols is
3709 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3710 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003711 intel_dp->sink_rates[i] = (val * 200) / 10;
3712 }
3713 intel_dp->num_sink_rates = i;
3714 }
3715
Jani Nikula68f357c2017-03-28 17:59:05 +03003716 if (intel_dp->num_sink_rates)
3717 intel_dp->use_rate_select = true;
3718 else
3719 intel_dp_set_sink_rates(intel_dp);
3720
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003721 intel_dp_set_common_rates(intel_dp);
3722
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003723 return true;
3724}
3725
3726
3727static bool
3728intel_dp_get_dpcd(struct intel_dp *intel_dp)
3729{
3730 if (!intel_dp_read_dpcd(intel_dp))
3731 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003732
Jani Nikula68f357c2017-03-28 17:59:05 +03003733 /* Don't clobber cached eDP rates. */
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003734 if (!is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003735 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003736 intel_dp_set_common_rates(intel_dp);
3737 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003738
Lyude9f085eb2016-04-13 10:58:33 -04003739 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3740 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303741 return false;
3742
3743 /*
3744 * Sink count can change between short pulse hpd hence
3745 * a member variable in intel_dp will track any changes
3746 * between short pulse interrupts.
3747 */
3748 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3749
3750 /*
3751 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3752 * a dongle is present but no display. Unless we require to know
3753 * if a dongle is present or not, we don't need to update
3754 * downstream port information. So, an early return here saves
3755 * time from performing other operations which are not required.
3756 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303757 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303758 return false;
3759
Imre Deakc726ad02016-10-24 19:33:24 +03003760 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003761 return true; /* native DP sink */
3762
3763 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3764 return true; /* no per-port downstream info */
3765
Lyude9f085eb2016-04-13 10:58:33 -04003766 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3767 intel_dp->downstream_ports,
3768 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003769 return false; /* downstream port status fetch failed */
3770
3771 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003772}
3773
Dave Airlie0e32b392014-05-02 14:02:48 +10003774static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003775intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003776{
3777 u8 buf[1];
3778
Nathan Schulte7cc96132016-03-15 10:14:05 -05003779 if (!i915.enable_dp_mst)
3780 return false;
3781
Dave Airlie0e32b392014-05-02 14:02:48 +10003782 if (!intel_dp->can_mst)
3783 return false;
3784
3785 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3786 return false;
3787
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003788 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3789 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003790
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003791 return buf[0] & DP_MST_CAP;
3792}
3793
3794static void
3795intel_dp_configure_mst(struct intel_dp *intel_dp)
3796{
3797 if (!i915.enable_dp_mst)
3798 return;
3799
3800 if (!intel_dp->can_mst)
3801 return;
3802
3803 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3804
3805 if (intel_dp->is_mst)
3806 DRM_DEBUG_KMS("Sink is MST capable\n");
3807 else
3808 DRM_DEBUG_KMS("Sink is not MST capable\n");
3809
3810 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3811 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003812}
3813
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003814static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003815{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003816 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003817 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003818 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003819 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003820 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003821 int count = 0;
3822 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003823
3824 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003825 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003826 ret = -EIO;
3827 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003828 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003829
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003830 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003831 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003832 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003833 ret = -EIO;
3834 goto out;
3835 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003836
Rodrigo Vivic6297842015-11-05 10:50:20 -08003837 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003838 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003839
3840 if (drm_dp_dpcd_readb(&intel_dp->aux,
3841 DP_TEST_SINK_MISC, &buf) < 0) {
3842 ret = -EIO;
3843 goto out;
3844 }
3845 count = buf & DP_TEST_COUNT_MASK;
3846 } while (--attempts && count);
3847
3848 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003849 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003850 ret = -ETIMEDOUT;
3851 }
3852
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003853 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003854 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003855 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003856}
3857
3858static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3859{
3860 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003861 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003862 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3863 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003864 int ret;
3865
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003866 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3867 return -EIO;
3868
3869 if (!(buf & DP_TEST_CRC_SUPPORTED))
3870 return -ENOTTY;
3871
3872 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3873 return -EIO;
3874
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003875 if (buf & DP_TEST_SINK_START) {
3876 ret = intel_dp_sink_crc_stop(intel_dp);
3877 if (ret)
3878 return ret;
3879 }
3880
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003881 hsw_disable_ips(intel_crtc);
3882
3883 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3884 buf | DP_TEST_SINK_START) < 0) {
3885 hsw_enable_ips(intel_crtc);
3886 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003887 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003888
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003889 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003890 return 0;
3891}
3892
3893int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3894{
3895 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003896 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003897 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3898 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003899 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003900 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003901
3902 ret = intel_dp_sink_crc_start(intel_dp);
3903 if (ret)
3904 return ret;
3905
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003906 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003907 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003908
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003909 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003910 DP_TEST_SINK_MISC, &buf) < 0) {
3911 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003912 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003913 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003914 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003915
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003916 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003917
3918 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003919 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3920 ret = -ETIMEDOUT;
3921 goto stop;
3922 }
3923
3924 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3925 ret = -EIO;
3926 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003927 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003928
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003929stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003930 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003931 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003932}
3933
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003934static bool
3935intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3936{
Lyude9f085eb2016-04-13 10:58:33 -04003937 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003938 DP_DEVICE_SERVICE_IRQ_VECTOR,
3939 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003940}
3941
Dave Airlie0e32b392014-05-02 14:02:48 +10003942static bool
3943intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3944{
3945 int ret;
3946
Lyude9f085eb2016-04-13 10:58:33 -04003947 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003948 DP_SINK_COUNT_ESI,
3949 sink_irq_vector, 14);
3950 if (ret != 14)
3951 return false;
3952
3953 return true;
3954}
3955
Todd Previtec5d5ab72015-04-15 08:38:38 -07003956static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003957{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003958 int status = 0;
3959 int min_lane_count = 1;
Manasi Navareda15f7c2017-01-24 08:16:34 -08003960 int link_rate_index, test_link_rate;
3961 uint8_t test_lane_count, test_link_bw;
3962 /* (DP CTS 1.2)
3963 * 4.3.1.11
3964 */
3965 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3966 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3967 &test_lane_count);
3968
3969 if (status <= 0) {
3970 DRM_DEBUG_KMS("Lane count read failed\n");
3971 return DP_TEST_NAK;
3972 }
3973 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3974 /* Validate the requested lane count */
3975 if (test_lane_count < min_lane_count ||
Jani Nikulae6c0c642017-04-06 16:44:12 +03003976 test_lane_count > intel_dp->max_link_lane_count)
Manasi Navareda15f7c2017-01-24 08:16:34 -08003977 return DP_TEST_NAK;
3978
3979 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3980 &test_link_bw);
3981 if (status <= 0) {
3982 DRM_DEBUG_KMS("Link Rate read failed\n");
3983 return DP_TEST_NAK;
3984 }
3985 /* Validate the requested link rate */
3986 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Jani Nikulab1810a72017-04-06 16:44:11 +03003987 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
3988 intel_dp->num_common_rates,
3989 test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08003990 if (link_rate_index < 0)
3991 return DP_TEST_NAK;
3992
3993 intel_dp->compliance.test_lane_count = test_lane_count;
3994 intel_dp->compliance.test_link_rate = test_link_rate;
3995
3996 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003997}
3998
3999static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4000{
Manasi Navare611032b2017-01-24 08:21:49 -08004001 uint8_t test_pattern;
4002 uint16_t test_misc;
4003 __be16 h_width, v_height;
4004 int status = 0;
4005
4006 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4007 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
4008 &test_pattern, 1);
4009 if (status <= 0) {
4010 DRM_DEBUG_KMS("Test pattern read failed\n");
4011 return DP_TEST_NAK;
4012 }
4013 if (test_pattern != DP_COLOR_RAMP)
4014 return DP_TEST_NAK;
4015
4016 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4017 &h_width, 2);
4018 if (status <= 0) {
4019 DRM_DEBUG_KMS("H Width read failed\n");
4020 return DP_TEST_NAK;
4021 }
4022
4023 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4024 &v_height, 2);
4025 if (status <= 0) {
4026 DRM_DEBUG_KMS("V Height read failed\n");
4027 return DP_TEST_NAK;
4028 }
4029
4030 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4031 &test_misc, 1);
4032 if (status <= 0) {
4033 DRM_DEBUG_KMS("TEST MISC read failed\n");
4034 return DP_TEST_NAK;
4035 }
4036 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4037 return DP_TEST_NAK;
4038 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4039 return DP_TEST_NAK;
4040 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4041 case DP_TEST_BIT_DEPTH_6:
4042 intel_dp->compliance.test_data.bpc = 6;
4043 break;
4044 case DP_TEST_BIT_DEPTH_8:
4045 intel_dp->compliance.test_data.bpc = 8;
4046 break;
4047 default:
4048 return DP_TEST_NAK;
4049 }
4050
4051 intel_dp->compliance.test_data.video_pattern = test_pattern;
4052 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4053 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4054 /* Set test active flag here so userspace doesn't interrupt things */
4055 intel_dp->compliance.test_active = 1;
4056
4057 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004058}
4059
4060static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4061{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004062 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004063 struct intel_connector *intel_connector = intel_dp->attached_connector;
4064 struct drm_connector *connector = &intel_connector->base;
4065
4066 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004067 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004068 intel_dp->aux.i2c_defer_count > 6) {
4069 /* Check EDID read for NACKs, DEFERs and corruption
4070 * (DP CTS 1.2 Core r1.1)
4071 * 4.2.2.4 : Failed EDID read, I2C_NAK
4072 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4073 * 4.2.2.6 : EDID corruption detected
4074 * Use failsafe mode for all cases
4075 */
4076 if (intel_dp->aux.i2c_nack_count > 0 ||
4077 intel_dp->aux.i2c_defer_count > 0)
4078 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4079 intel_dp->aux.i2c_nack_count,
4080 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004081 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004082 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304083 struct edid *block = intel_connector->detect_edid;
4084
4085 /* We have to write the checksum
4086 * of the last block read
4087 */
4088 block += intel_connector->detect_edid->extensions;
4089
Todd Previte559be302015-05-04 07:48:20 -07004090 if (!drm_dp_dpcd_write(&intel_dp->aux,
4091 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304092 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004093 1))
Todd Previte559be302015-05-04 07:48:20 -07004094 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4095
4096 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004097 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004098 }
4099
4100 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004101 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004102
Todd Previtec5d5ab72015-04-15 08:38:38 -07004103 return test_result;
4104}
4105
4106static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4107{
4108 uint8_t test_result = DP_TEST_NAK;
4109 return test_result;
4110}
4111
4112static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4113{
4114 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004115 uint8_t request = 0;
4116 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004117
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004118 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004119 if (status <= 0) {
4120 DRM_DEBUG_KMS("Could not read test request from sink\n");
4121 goto update_status;
4122 }
4123
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004124 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004125 case DP_TEST_LINK_TRAINING:
4126 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004127 response = intel_dp_autotest_link_training(intel_dp);
4128 break;
4129 case DP_TEST_LINK_VIDEO_PATTERN:
4130 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004131 response = intel_dp_autotest_video_pattern(intel_dp);
4132 break;
4133 case DP_TEST_LINK_EDID_READ:
4134 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004135 response = intel_dp_autotest_edid(intel_dp);
4136 break;
4137 case DP_TEST_LINK_PHY_TEST_PATTERN:
4138 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004139 response = intel_dp_autotest_phy_pattern(intel_dp);
4140 break;
4141 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004142 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004143 break;
4144 }
4145
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004146 if (response & DP_TEST_ACK)
4147 intel_dp->compliance.test_type = request;
4148
Todd Previtec5d5ab72015-04-15 08:38:38 -07004149update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004150 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004151 if (status <= 0)
4152 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004153}
4154
Dave Airlie0e32b392014-05-02 14:02:48 +10004155static int
4156intel_dp_check_mst_status(struct intel_dp *intel_dp)
4157{
4158 bool bret;
4159
4160 if (intel_dp->is_mst) {
4161 u8 esi[16] = { 0 };
4162 int ret = 0;
4163 int retry;
4164 bool handled;
4165 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4166go_again:
4167 if (bret == true) {
4168
4169 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004170 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004171 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004172 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4173 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004174 intel_dp_stop_link_train(intel_dp);
4175 }
4176
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004177 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004178 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4179
4180 if (handled) {
4181 for (retry = 0; retry < 3; retry++) {
4182 int wret;
4183 wret = drm_dp_dpcd_write(&intel_dp->aux,
4184 DP_SINK_COUNT_ESI+1,
4185 &esi[1], 3);
4186 if (wret == 3) {
4187 break;
4188 }
4189 }
4190
4191 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4192 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004193 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004194 goto go_again;
4195 }
4196 } else
4197 ret = 0;
4198
4199 return ret;
4200 } else {
4201 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4202 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4203 intel_dp->is_mst = false;
4204 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4205 /* send a hotplug event */
4206 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4207 }
4208 }
4209 return -EINVAL;
4210}
4211
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304212static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004213intel_dp_retrain_link(struct intel_dp *intel_dp)
4214{
4215 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4216 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4217 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4218
4219 /* Suppress underruns caused by re-training */
4220 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4221 if (crtc->config->has_pch_encoder)
4222 intel_set_pch_fifo_underrun_reporting(dev_priv,
4223 intel_crtc_pch_transcoder(crtc), false);
4224
4225 intel_dp_start_link_train(intel_dp);
4226 intel_dp_stop_link_train(intel_dp);
4227
4228 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004229 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004230
4231 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4232 if (crtc->config->has_pch_encoder)
4233 intel_set_pch_fifo_underrun_reporting(dev_priv,
4234 intel_crtc_pch_transcoder(crtc), true);
4235}
4236
4237static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304238intel_dp_check_link_status(struct intel_dp *intel_dp)
4239{
4240 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4241 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4242 u8 link_status[DP_LINK_STATUS_SIZE];
4243
4244 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4245
4246 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4247 DRM_ERROR("Failed to get link status\n");
4248 return;
4249 }
4250
4251 if (!intel_encoder->base.crtc)
4252 return;
4253
4254 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4255 return;
4256
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004257 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004258 * readout. Currently fast link training doesn't work on boot-up. */
4259 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004260 return;
4261
Manasi Navareda15f7c2017-01-24 08:16:34 -08004262 /* Retrain if Channel EQ or CR not ok */
4263 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304264 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4265 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004266
4267 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304268 }
4269}
4270
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004271/*
4272 * According to DP spec
4273 * 5.1.2:
4274 * 1. Read DPCD
4275 * 2. Configure link according to Receiver Capabilities
4276 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4277 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304278 *
4279 * intel_dp_short_pulse - handles short pulse interrupts
4280 * when full detection is not required.
4281 * Returns %true if short pulse is handled and full detection
4282 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004283 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304284static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304285intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004286{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004287 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004288 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004289 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304290 u8 old_sink_count = intel_dp->sink_count;
4291 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004292
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304293 /*
4294 * Clearing compliance test variables to allow capturing
4295 * of values for next automated test request.
4296 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004297 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304298
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304299 /*
4300 * Now read the DPCD to see if it's actually running
4301 * If the current value of sink count doesn't match with
4302 * the value that was stored earlier or dpcd read failed
4303 * we need to do full detection
4304 */
4305 ret = intel_dp_get_dpcd(intel_dp);
4306
4307 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4308 /* No need to proceed if we are going to do full detect */
4309 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004310 }
4311
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004312 /* Try to read the source of the interrupt */
4313 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004314 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4315 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004316 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004317 drm_dp_dpcd_writeb(&intel_dp->aux,
4318 DP_DEVICE_SERVICE_IRQ_VECTOR,
4319 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004320
4321 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004322 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004323 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4324 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4325 }
4326
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304327 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4328 intel_dp_check_link_status(intel_dp);
4329 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004330 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4331 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4332 /* Send a Hotplug Uevent to userspace to start modeset */
4333 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4334 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304335
4336 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004337}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004338
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004339/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004340static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004341intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004342{
Imre Deake393d0d2017-02-22 17:10:52 +02004343 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004344 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004345 uint8_t type;
4346
Imre Deake393d0d2017-02-22 17:10:52 +02004347 if (lspcon->active)
4348 lspcon_resume(lspcon);
4349
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004350 if (!intel_dp_get_dpcd(intel_dp))
4351 return connector_status_disconnected;
4352
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304353 if (is_edp(intel_dp))
4354 return connector_status_connected;
4355
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004356 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004357 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004358 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004359
4360 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004361 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4362 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004363
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304364 return intel_dp->sink_count ?
4365 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004366 }
4367
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004368 if (intel_dp_can_mst(intel_dp))
4369 return connector_status_connected;
4370
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004371 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004372 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004373 return connector_status_connected;
4374
4375 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004376 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4377 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4378 if (type == DP_DS_PORT_TYPE_VGA ||
4379 type == DP_DS_PORT_TYPE_NON_EDID)
4380 return connector_status_unknown;
4381 } else {
4382 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4383 DP_DWN_STRM_PORT_TYPE_MASK;
4384 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4385 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4386 return connector_status_unknown;
4387 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004388
4389 /* Anything else is out of spec, warn and ignore */
4390 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004391 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004392}
4393
4394static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004395edp_detect(struct intel_dp *intel_dp)
4396{
4397 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004398 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004399 enum drm_connector_status status;
4400
Mika Kahola1650be72016-12-13 10:02:47 +02004401 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004402 if (status == connector_status_unknown)
4403 status = connector_status_connected;
4404
4405 return status;
4406}
4407
Jani Nikulab93433c2015-08-20 10:47:36 +03004408static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4409 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004410{
Jani Nikulab93433c2015-08-20 10:47:36 +03004411 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004412
Jani Nikula0df53b72015-08-20 10:47:40 +03004413 switch (port->port) {
4414 case PORT_A:
4415 return true;
4416 case PORT_B:
4417 bit = SDE_PORTB_HOTPLUG;
4418 break;
4419 case PORT_C:
4420 bit = SDE_PORTC_HOTPLUG;
4421 break;
4422 case PORT_D:
4423 bit = SDE_PORTD_HOTPLUG;
4424 break;
4425 default:
4426 MISSING_CASE(port->port);
4427 return false;
4428 }
4429
4430 return I915_READ(SDEISR) & bit;
4431}
4432
4433static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4434 struct intel_digital_port *port)
4435{
4436 u32 bit;
4437
4438 switch (port->port) {
4439 case PORT_A:
4440 return true;
4441 case PORT_B:
4442 bit = SDE_PORTB_HOTPLUG_CPT;
4443 break;
4444 case PORT_C:
4445 bit = SDE_PORTC_HOTPLUG_CPT;
4446 break;
4447 case PORT_D:
4448 bit = SDE_PORTD_HOTPLUG_CPT;
4449 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004450 case PORT_E:
4451 bit = SDE_PORTE_HOTPLUG_SPT;
4452 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004453 default:
4454 MISSING_CASE(port->port);
4455 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004456 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004457
Jani Nikulab93433c2015-08-20 10:47:36 +03004458 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004459}
4460
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004461static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004462 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004463{
Jani Nikula9642c812015-08-20 10:47:41 +03004464 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004465
Jani Nikula9642c812015-08-20 10:47:41 +03004466 switch (port->port) {
4467 case PORT_B:
4468 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4469 break;
4470 case PORT_C:
4471 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4472 break;
4473 case PORT_D:
4474 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4475 break;
4476 default:
4477 MISSING_CASE(port->port);
4478 return false;
4479 }
4480
4481 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4482}
4483
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004484static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4485 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004486{
4487 u32 bit;
4488
4489 switch (port->port) {
4490 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004491 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004492 break;
4493 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004494 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004495 break;
4496 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004497 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004498 break;
4499 default:
4500 MISSING_CASE(port->port);
4501 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004502 }
4503
Jani Nikula1d245982015-08-20 10:47:37 +03004504 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004505}
4506
Jani Nikulae464bfd2015-08-20 10:47:42 +03004507static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304508 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004509{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304510 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4511 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004512 u32 bit;
4513
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304514 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4515 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004516 case PORT_A:
4517 bit = BXT_DE_PORT_HP_DDIA;
4518 break;
4519 case PORT_B:
4520 bit = BXT_DE_PORT_HP_DDIB;
4521 break;
4522 case PORT_C:
4523 bit = BXT_DE_PORT_HP_DDIC;
4524 break;
4525 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304526 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004527 return false;
4528 }
4529
4530 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4531}
4532
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004533/*
4534 * intel_digital_port_connected - is the specified port connected?
4535 * @dev_priv: i915 private structure
4536 * @port: the port to test
4537 *
4538 * Return %true if @port is connected, %false otherwise.
4539 */
Imre Deak390b4e02017-01-27 11:39:19 +02004540bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4541 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004542{
Jani Nikula0df53b72015-08-20 10:47:40 +03004543 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004544 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004545 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004546 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004547 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004548 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004549 else if (IS_GM45(dev_priv))
4550 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004551 else
4552 return g4x_digital_port_connected(dev_priv, port);
4553}
4554
Keith Packard8c241fe2011-09-28 16:38:44 -07004555static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004556intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004557{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004558 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004559
Jani Nikula9cd300e2012-10-19 14:51:52 +03004560 /* use cached edid if we have one */
4561 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004562 /* invalid edid */
4563 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004564 return NULL;
4565
Jani Nikula55e9ede2013-10-01 10:38:54 +03004566 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004567 } else
4568 return drm_get_edid(&intel_connector->base,
4569 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004570}
4571
Chris Wilsonbeb60602014-09-02 20:04:00 +01004572static void
4573intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004574{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004575 struct intel_connector *intel_connector = intel_dp->attached_connector;
4576 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004577
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304578 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004579 edid = intel_dp_get_edid(intel_dp);
4580 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004581
Chris Wilsonbeb60602014-09-02 20:04:00 +01004582 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4583 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4584 else
4585 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4586}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004587
Chris Wilsonbeb60602014-09-02 20:04:00 +01004588static void
4589intel_dp_unset_edid(struct intel_dp *intel_dp)
4590{
4591 struct intel_connector *intel_connector = intel_dp->attached_connector;
4592
4593 kfree(intel_connector->detect_edid);
4594 intel_connector->detect_edid = NULL;
4595
4596 intel_dp->has_audio = false;
4597}
4598
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004599static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304600intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004601{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304602 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004603 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004604 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4605 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004606 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004607 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004608 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004609
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004610 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004611
Chris Wilsond410b562014-09-02 20:03:59 +01004612 /* Can't disconnect eDP, but you can close the lid... */
4613 if (is_edp(intel_dp))
4614 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004615 else if (intel_digital_port_connected(to_i915(dev),
4616 dp_to_dig_port(intel_dp)))
4617 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004618 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004619 status = connector_status_disconnected;
4620
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004621 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004622 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304623
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004624 if (intel_dp->is_mst) {
4625 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4626 intel_dp->is_mst,
4627 intel_dp->mst_mgr.mst_state);
4628 intel_dp->is_mst = false;
4629 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4630 intel_dp->is_mst);
4631 }
4632
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004633 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304634 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004635
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304636 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004637 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304638
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004639 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4640 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4641 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4642
Manasi Navared7e8ef02017-02-07 16:54:11 -08004643 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004644 /* Initial max link lane count */
4645 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004646
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004647 /* Initial max link rate */
4648 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004649
4650 intel_dp->reset_link_params = false;
4651 }
Manasi Navaref4829842016-12-05 16:27:36 -08004652
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004653 intel_dp_print_rates(intel_dp);
4654
Imre Deak7b3fc172016-10-25 16:12:39 +03004655 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004656
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004657 intel_dp_configure_mst(intel_dp);
4658
4659 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304660 /*
4661 * If we are in MST mode then this connector
4662 * won't appear connected or have anything
4663 * with EDID on it
4664 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004665 status = connector_status_disconnected;
4666 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304667 } else if (connector->status == connector_status_connected) {
4668 /*
4669 * If display was connected already and is still connected
4670 * check links status, there has been known issues of
4671 * link loss triggerring long pulse!!!!
4672 */
4673 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4674 intel_dp_check_link_status(intel_dp);
4675 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4676 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004677 }
4678
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304679 /*
4680 * Clearing NACK and defer counts to get their exact values
4681 * while reading EDID which are required by Compliance tests
4682 * 4.2.2.4 and 4.2.2.5
4683 */
4684 intel_dp->aux.i2c_nack_count = 0;
4685 intel_dp->aux.i2c_defer_count = 0;
4686
Chris Wilsonbeb60602014-09-02 20:04:00 +01004687 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004688 if (is_edp(intel_dp) || intel_connector->detect_edid)
4689 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304690 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004691
Todd Previte09b1eb12015-04-20 15:27:34 -07004692 /* Try to read the source of the interrupt */
4693 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004694 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4695 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004696 /* Clear interrupt source */
4697 drm_dp_dpcd_writeb(&intel_dp->aux,
4698 DP_DEVICE_SERVICE_IRQ_VECTOR,
4699 sink_irq_vector);
4700
4701 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4702 intel_dp_handle_test_request(intel_dp);
4703 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4704 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4705 }
4706
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004707out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004708 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304709 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304710
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004711 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004712 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304713}
4714
4715static enum drm_connector_status
4716intel_dp_detect(struct drm_connector *connector, bool force)
4717{
4718 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004719 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304720
4721 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4722 connector->base.id, connector->name);
4723
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304724 /* If full detect is not performed yet, do a full detect */
4725 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004726 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304727
4728 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304729
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004730 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004731}
4732
Chris Wilsonbeb60602014-09-02 20:04:00 +01004733static void
4734intel_dp_force(struct drm_connector *connector)
4735{
4736 struct intel_dp *intel_dp = intel_attached_dp(connector);
4737 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004738 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004739
4740 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4741 connector->base.id, connector->name);
4742 intel_dp_unset_edid(intel_dp);
4743
4744 if (connector->status != connector_status_connected)
4745 return;
4746
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004747 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004748
4749 intel_dp_set_edid(intel_dp);
4750
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004751 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004752
4753 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004754 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004755}
4756
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004757static int intel_dp_get_modes(struct drm_connector *connector)
4758{
Jani Nikuladd06f902012-10-19 14:51:50 +03004759 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004760 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004761
Chris Wilsonbeb60602014-09-02 20:04:00 +01004762 edid = intel_connector->detect_edid;
4763 if (edid) {
4764 int ret = intel_connector_update_modes(connector, edid);
4765 if (ret)
4766 return ret;
4767 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004768
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004769 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004770 if (is_edp(intel_attached_dp(connector)) &&
4771 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004772 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004773
4774 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004775 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004776 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004777 drm_mode_probed_add(connector, mode);
4778 return 1;
4779 }
4780 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004781
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004782 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004783}
4784
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004785static bool
4786intel_dp_detect_audio(struct drm_connector *connector)
4787{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004788 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004789 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004790
Chris Wilsonbeb60602014-09-02 20:04:00 +01004791 edid = to_intel_connector(connector)->detect_edid;
4792 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004793 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004794
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004795 return has_audio;
4796}
4797
Chris Wilsonf6849602010-09-19 09:29:33 +01004798static int
4799intel_dp_set_property(struct drm_connector *connector,
4800 struct drm_property *property,
4801 uint64_t val)
4802{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004803 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004804 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004805 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4806 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004807 int ret;
4808
Rob Clark662595d2012-10-11 20:36:04 -05004809 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004810 if (ret)
4811 return ret;
4812
Chris Wilson3f43c482011-05-12 22:17:24 +01004813 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004814 int i = val;
4815 bool has_audio;
4816
4817 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004818 return 0;
4819
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004820 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004821
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004822 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004823 has_audio = intel_dp_detect_audio(connector);
4824 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004825 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004826
4827 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004828 return 0;
4829
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004830 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004831 goto done;
4832 }
4833
Chris Wilsone953fd72011-02-21 22:23:52 +00004834 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004835 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004836 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004837
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004838 switch (val) {
4839 case INTEL_BROADCAST_RGB_AUTO:
4840 intel_dp->color_range_auto = true;
4841 break;
4842 case INTEL_BROADCAST_RGB_FULL:
4843 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004844 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004845 break;
4846 case INTEL_BROADCAST_RGB_LIMITED:
4847 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004848 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004849 break;
4850 default:
4851 return -EINVAL;
4852 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004853
4854 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004855 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004856 return 0;
4857
Chris Wilsone953fd72011-02-21 22:23:52 +00004858 goto done;
4859 }
4860
Yuly Novikov53b41832012-10-26 12:04:00 +03004861 if (is_edp(intel_dp) &&
4862 property == connector->dev->mode_config.scaling_mode_property) {
4863 if (val == DRM_MODE_SCALE_NONE) {
4864 DRM_DEBUG_KMS("no scaling not supported\n");
4865 return -EINVAL;
4866 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004867 if (HAS_GMCH_DISPLAY(dev_priv) &&
4868 val == DRM_MODE_SCALE_CENTER) {
4869 DRM_DEBUG_KMS("centering not supported\n");
4870 return -EINVAL;
4871 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004872
4873 if (intel_connector->panel.fitting_mode == val) {
4874 /* the eDP scaling property is not changed */
4875 return 0;
4876 }
4877 intel_connector->panel.fitting_mode = val;
4878
4879 goto done;
4880 }
4881
Chris Wilsonf6849602010-09-19 09:29:33 +01004882 return -EINVAL;
4883
4884done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004885 if (intel_encoder->base.crtc)
4886 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004887
4888 return 0;
4889}
4890
Chris Wilson7a418e32016-06-24 14:00:14 +01004891static int
4892intel_dp_connector_register(struct drm_connector *connector)
4893{
4894 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004895 int ret;
4896
4897 ret = intel_connector_register(connector);
4898 if (ret)
4899 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004900
4901 i915_debugfs_connector_add(connector);
4902
4903 DRM_DEBUG_KMS("registering %s bus for %s\n",
4904 intel_dp->aux.name, connector->kdev->kobj.name);
4905
4906 intel_dp->aux.dev = connector->kdev;
4907 return drm_dp_aux_register(&intel_dp->aux);
4908}
4909
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004910static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004911intel_dp_connector_unregister(struct drm_connector *connector)
4912{
4913 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4914 intel_connector_unregister(connector);
4915}
4916
4917static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004918intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004919{
Jani Nikula1d508702012-10-19 14:51:49 +03004920 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004921
Chris Wilson10e972d2014-09-04 21:43:45 +01004922 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004923
Jani Nikula9cd300e2012-10-19 14:51:52 +03004924 if (!IS_ERR_OR_NULL(intel_connector->edid))
4925 kfree(intel_connector->edid);
4926
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004927 /* Can't call is_edp() since the encoder may have been destroyed
4928 * already. */
4929 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004930 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004931
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004932 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004933 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004934}
4935
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004936void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004937{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004938 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4939 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004940
Dave Airlie0e32b392014-05-02 14:02:48 +10004941 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004942 if (is_edp(intel_dp)) {
4943 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004944 /*
4945 * vdd might still be enabled do to the delayed vdd off.
4946 * Make sure vdd is actually turned off here.
4947 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004948 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004949 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004950 pps_unlock(intel_dp);
4951
Clint Taylor01527b32014-07-07 13:01:46 -07004952 if (intel_dp->edp_notifier.notifier_call) {
4953 unregister_reboot_notifier(&intel_dp->edp_notifier);
4954 intel_dp->edp_notifier.notifier_call = NULL;
4955 }
Keith Packardbd943152011-09-18 23:09:52 -07004956 }
Chris Wilson99681882016-06-20 09:29:17 +01004957
4958 intel_dp_aux_fini(intel_dp);
4959
Imre Deakc8bd0e42014-12-12 17:57:38 +02004960 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004961 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004962}
4963
Imre Deakbf93ba62016-04-18 10:04:21 +03004964void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004965{
4966 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4967
4968 if (!is_edp(intel_dp))
4969 return;
4970
Ville Syrjälä951468f2014-09-04 14:55:31 +03004971 /*
4972 * vdd might still be enabled do to the delayed vdd off.
4973 * Make sure vdd is actually turned off here.
4974 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004975 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004976 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004977 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004978 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004979}
4980
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004981static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4982{
4983 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4984 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004985 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004986
4987 lockdep_assert_held(&dev_priv->pps_mutex);
4988
4989 if (!edp_have_panel_vdd(intel_dp))
4990 return;
4991
4992 /*
4993 * The VDD bit needs a power domain reference, so if the bit is
4994 * already enabled when we boot or resume, grab this reference and
4995 * schedule a vdd off, so we don't hold on to the reference
4996 * indefinitely.
4997 */
4998 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004999 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005000
5001 edp_panel_vdd_schedule_off(intel_dp);
5002}
5003
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005004static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5005{
5006 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5007
5008 if ((intel_dp->DP & DP_PORT_EN) == 0)
5009 return INVALID_PIPE;
5010
5011 if (IS_CHERRYVIEW(dev_priv))
5012 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5013 else
5014 return PORT_TO_PIPE(intel_dp->DP);
5015}
5016
Imre Deakbf93ba62016-04-18 10:04:21 +03005017void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005018{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005019 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005020 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5021 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005022
5023 if (!HAS_DDI(dev_priv))
5024 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005025
Imre Deakdd75f6d2016-11-21 21:15:05 +02005026 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305027 lspcon_resume(lspcon);
5028
Manasi Navared7e8ef02017-02-07 16:54:11 -08005029 intel_dp->reset_link_params = true;
5030
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005031 pps_lock(intel_dp);
5032
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005033 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5034 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5035
5036 if (is_edp(intel_dp)) {
5037 /* Reinit the power sequencer, in case BIOS did something with it. */
5038 intel_dp_pps_init(encoder->dev, intel_dp);
5039 intel_edp_panel_vdd_sanitize(intel_dp);
5040 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005041
5042 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005043}
5044
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005045static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005046 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005047 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005048 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005049 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005050 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005051 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005052 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005053 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005054 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005055 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005056 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005057};
5058
5059static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5060 .get_modes = intel_dp_get_modes,
5061 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005062};
5063
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005064static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005065 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005066 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005067};
5068
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005069enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005070intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5071{
5072 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005073 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005074 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005075 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005076
Takashi Iwai25400582015-11-19 12:09:56 +01005077 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5078 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005079 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005080
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005081 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5082 /*
5083 * vdd off can generate a long pulse on eDP which
5084 * would require vdd on to handle it, and thus we
5085 * would end up in an endless cycle of
5086 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5087 */
5088 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5089 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005090 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005091 }
5092
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005093 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5094 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005095 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005096
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005097 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005098 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005099 intel_dp->detect_done = false;
5100 return IRQ_NONE;
5101 }
5102
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005103 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005104
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005105 if (intel_dp->is_mst) {
5106 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5107 /*
5108 * If we were in MST mode, and device is not
5109 * there, get out of MST mode
5110 */
5111 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5112 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5113 intel_dp->is_mst = false;
5114 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5115 intel_dp->is_mst);
5116 intel_dp->detect_done = false;
5117 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005118 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005119 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005120
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005121 if (!intel_dp->is_mst) {
5122 if (!intel_dp_short_pulse(intel_dp)) {
5123 intel_dp->detect_done = false;
5124 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305125 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005126 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005127
5128 ret = IRQ_HANDLED;
5129
Imre Deak1c767b32014-08-18 14:42:42 +03005130put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005131 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005132
5133 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005134}
5135
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005136/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005137bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005138{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005139 /*
5140 * eDP not supported on g4x. so bail out early just
5141 * for a bit extra safety in case the VBT is bonkers.
5142 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005143 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005144 return false;
5145
Imre Deaka98d9c12016-12-21 12:17:24 +02005146 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005147 return true;
5148
Jani Nikula951d9ef2016-03-16 12:43:31 +02005149 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005150}
5151
Dave Airlie0e32b392014-05-02 14:02:48 +10005152void
Chris Wilsonf6849602010-09-19 09:29:33 +01005153intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5154{
Yuly Novikov53b41832012-10-26 12:04:00 +03005155 struct intel_connector *intel_connector = to_intel_connector(connector);
5156
Chris Wilson3f43c482011-05-12 22:17:24 +01005157 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005158 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005159 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005160
5161 if (is_edp(intel_dp)) {
5162 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005163 drm_object_attach_property(
5164 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005165 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005166 DRM_MODE_SCALE_ASPECT);
5167 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005168 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005169}
5170
Imre Deakdada1a92014-01-29 13:25:41 +02005171static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5172{
Abhay Kumard28d4732016-01-22 17:39:04 -08005173 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005174 intel_dp->last_power_on = jiffies;
5175 intel_dp->last_backlight_off = jiffies;
5176}
5177
Daniel Vetter67a54562012-10-20 20:57:45 +02005178static void
Imre Deak54648612016-06-16 16:37:22 +03005179intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5180 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005181{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305182 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005183 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005184
Imre Deak8e8232d2016-06-16 16:37:21 +03005185 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005186
5187 /* Workaround: Need to write PP_CONTROL with the unlock key as
5188 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305189 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005190
Imre Deak8e8232d2016-06-16 16:37:21 +03005191 pp_on = I915_READ(regs.pp_on);
5192 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005193 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005194 I915_WRITE(regs.pp_ctrl, pp_ctl);
5195 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305196 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005197
5198 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005199 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5200 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005201
Imre Deak54648612016-06-16 16:37:22 +03005202 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5203 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005204
Imre Deak54648612016-06-16 16:37:22 +03005205 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5206 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005207
Imre Deak54648612016-06-16 16:37:22 +03005208 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5209 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005210
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005211 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305212 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5213 BXT_POWER_CYCLE_DELAY_SHIFT;
5214 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005215 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305216 else
Imre Deak54648612016-06-16 16:37:22 +03005217 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305218 } else {
Imre Deak54648612016-06-16 16:37:22 +03005219 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005220 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305221 }
Imre Deak54648612016-06-16 16:37:22 +03005222}
5223
5224static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005225intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5226{
5227 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5228 state_name,
5229 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5230}
5231
5232static void
5233intel_pps_verify_state(struct drm_i915_private *dev_priv,
5234 struct intel_dp *intel_dp)
5235{
5236 struct edp_power_seq hw;
5237 struct edp_power_seq *sw = &intel_dp->pps_delays;
5238
5239 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5240
5241 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5242 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5243 DRM_ERROR("PPS state mismatch\n");
5244 intel_pps_dump_state("sw", sw);
5245 intel_pps_dump_state("hw", &hw);
5246 }
5247}
5248
5249static void
Imre Deak54648612016-06-16 16:37:22 +03005250intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5251 struct intel_dp *intel_dp)
5252{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005253 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005254 struct edp_power_seq cur, vbt, spec,
5255 *final = &intel_dp->pps_delays;
5256
5257 lockdep_assert_held(&dev_priv->pps_mutex);
5258
5259 /* already initialized? */
5260 if (final->t11_t12 != 0)
5261 return;
5262
5263 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005264
Imre Deakde9c1b62016-06-16 20:01:46 +03005265 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005266
Jani Nikula6aa23e62016-03-24 17:50:20 +02005267 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005268
5269 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5270 * our hw here, which are all in 100usec. */
5271 spec.t1_t3 = 210 * 10;
5272 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5273 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5274 spec.t10 = 500 * 10;
5275 /* This one is special and actually in units of 100ms, but zero
5276 * based in the hw (so we need to add 100 ms). But the sw vbt
5277 * table multiplies it with 1000 to make it in units of 100usec,
5278 * too. */
5279 spec.t11_t12 = (510 + 100) * 10;
5280
Imre Deakde9c1b62016-06-16 20:01:46 +03005281 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005282
5283 /* Use the max of the register settings and vbt. If both are
5284 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005285#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005286 spec.field : \
5287 max(cur.field, vbt.field))
5288 assign_final(t1_t3);
5289 assign_final(t8);
5290 assign_final(t9);
5291 assign_final(t10);
5292 assign_final(t11_t12);
5293#undef assign_final
5294
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005295#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005296 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5297 intel_dp->backlight_on_delay = get_delay(t8);
5298 intel_dp->backlight_off_delay = get_delay(t9);
5299 intel_dp->panel_power_down_delay = get_delay(t10);
5300 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5301#undef get_delay
5302
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005303 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5304 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5305 intel_dp->panel_power_cycle_delay);
5306
5307 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5308 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005309
5310 /*
5311 * We override the HW backlight delays to 1 because we do manual waits
5312 * on them. For T8, even BSpec recommends doing it. For T9, if we
5313 * don't do this, we'll end up waiting for the backlight off delay
5314 * twice: once when we do the manual sleep, and once when we disable
5315 * the panel and wait for the PP_STATUS bit to become zero.
5316 */
5317 final->t8 = 1;
5318 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005319}
5320
5321static void
5322intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005323 struct intel_dp *intel_dp,
5324 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005325{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005326 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005327 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005328 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005329 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005330 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005331 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005332
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005333 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005334
Imre Deak8e8232d2016-06-16 16:37:21 +03005335 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005336
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005337 /*
5338 * On some VLV machines the BIOS can leave the VDD
5339 * enabled even on power seqeuencers which aren't
5340 * hooked up to any port. This would mess up the
5341 * power domain tracking the first time we pick
5342 * one of these power sequencers for use since
5343 * edp_panel_vdd_on() would notice that the VDD was
5344 * already on and therefore wouldn't grab the power
5345 * domain reference. Disable VDD first to avoid this.
5346 * This also avoids spuriously turning the VDD on as
5347 * soon as the new power seqeuencer gets initialized.
5348 */
5349 if (force_disable_vdd) {
5350 u32 pp = ironlake_get_pp_control(intel_dp);
5351
5352 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5353
5354 if (pp & EDP_FORCE_VDD)
5355 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5356
5357 pp &= ~EDP_FORCE_VDD;
5358
5359 I915_WRITE(regs.pp_ctrl, pp);
5360 }
5361
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005362 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005363 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5364 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005365 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005366 /* Compute the divisor for the pp clock, simply match the Bspec
5367 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005368 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005369 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305370 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5371 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5372 << BXT_POWER_CYCLE_DELAY_SHIFT);
5373 } else {
5374 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5375 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5376 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5377 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005378
5379 /* Haswell doesn't have any port selection bits for the panel
5380 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005381 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005382 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005383 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005384 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005385 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005386 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005387 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005388 }
5389
Jesse Barnes453c5422013-03-28 09:55:41 -07005390 pp_on |= port_sel;
5391
Imre Deak8e8232d2016-06-16 16:37:21 +03005392 I915_WRITE(regs.pp_on, pp_on);
5393 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005394 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005395 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305396 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005397 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005398
Daniel Vetter67a54562012-10-20 20:57:45 +02005399 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 +03005400 I915_READ(regs.pp_on),
5401 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005402 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005403 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5404 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005405}
5406
Imre Deak335f7522016-08-10 14:07:32 +03005407static void intel_dp_pps_init(struct drm_device *dev,
5408 struct intel_dp *intel_dp)
5409{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005410 struct drm_i915_private *dev_priv = to_i915(dev);
5411
5412 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005413 vlv_initial_power_sequencer_setup(intel_dp);
5414 } else {
5415 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005416 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005417 }
5418}
5419
Vandana Kannanb33a2812015-02-13 15:33:03 +05305420/**
5421 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005422 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005423 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305424 * @refresh_rate: RR to be programmed
5425 *
5426 * This function gets called when refresh rate (RR) has to be changed from
5427 * one frequency to another. Switches can be between high and low RR
5428 * supported by the panel or to any other RR based on media playback (in
5429 * this case, RR value needs to be passed from user space).
5430 *
5431 * The caller of this function needs to take a lock on dev_priv->drrs.
5432 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005433static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5434 struct intel_crtc_state *crtc_state,
5435 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305436{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305437 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305438 struct intel_digital_port *dig_port = NULL;
5439 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005440 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305441 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305442
5443 if (refresh_rate <= 0) {
5444 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5445 return;
5446 }
5447
Vandana Kannan96178ee2015-01-10 02:25:56 +05305448 if (intel_dp == NULL) {
5449 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305450 return;
5451 }
5452
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005453 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005454 * FIXME: This needs proper synchronization with psr state for some
5455 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005456 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305457
Vandana Kannan96178ee2015-01-10 02:25:56 +05305458 dig_port = dp_to_dig_port(intel_dp);
5459 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005460 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305461
5462 if (!intel_crtc) {
5463 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5464 return;
5465 }
5466
Vandana Kannan96178ee2015-01-10 02:25:56 +05305467 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305468 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5469 return;
5470 }
5471
Vandana Kannan96178ee2015-01-10 02:25:56 +05305472 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5473 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305474 index = DRRS_LOW_RR;
5475
Vandana Kannan96178ee2015-01-10 02:25:56 +05305476 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305477 DRM_DEBUG_KMS(
5478 "DRRS requested for previously set RR...ignoring\n");
5479 return;
5480 }
5481
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005482 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305483 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5484 return;
5485 }
5486
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005487 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305488 switch (index) {
5489 case DRRS_HIGH_RR:
5490 intel_dp_set_m_n(intel_crtc, M1_N1);
5491 break;
5492 case DRRS_LOW_RR:
5493 intel_dp_set_m_n(intel_crtc, M2_N2);
5494 break;
5495 case DRRS_MAX_RR:
5496 default:
5497 DRM_ERROR("Unsupported refreshrate type\n");
5498 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005499 } else if (INTEL_GEN(dev_priv) > 6) {
5500 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005501 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305502
Ville Syrjälä649636e2015-09-22 19:50:01 +03005503 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305504 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005505 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305506 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5507 else
5508 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305509 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005510 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305511 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5512 else
5513 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305514 }
5515 I915_WRITE(reg, val);
5516 }
5517
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305518 dev_priv->drrs.refresh_rate_type = index;
5519
5520 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5521}
5522
Vandana Kannanb33a2812015-02-13 15:33:03 +05305523/**
5524 * intel_edp_drrs_enable - init drrs struct if supported
5525 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005526 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305527 *
5528 * Initializes frontbuffer_bits and drrs.dp
5529 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005530void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5531 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305532{
5533 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005534 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305535
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005536 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305537 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5538 return;
5539 }
5540
5541 mutex_lock(&dev_priv->drrs.mutex);
5542 if (WARN_ON(dev_priv->drrs.dp)) {
5543 DRM_ERROR("DRRS already enabled\n");
5544 goto unlock;
5545 }
5546
5547 dev_priv->drrs.busy_frontbuffer_bits = 0;
5548
5549 dev_priv->drrs.dp = intel_dp;
5550
5551unlock:
5552 mutex_unlock(&dev_priv->drrs.mutex);
5553}
5554
Vandana Kannanb33a2812015-02-13 15:33:03 +05305555/**
5556 * intel_edp_drrs_disable - Disable DRRS
5557 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005558 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305559 *
5560 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005561void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5562 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305563{
5564 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005565 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305566
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005567 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305568 return;
5569
5570 mutex_lock(&dev_priv->drrs.mutex);
5571 if (!dev_priv->drrs.dp) {
5572 mutex_unlock(&dev_priv->drrs.mutex);
5573 return;
5574 }
5575
5576 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005577 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5578 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305579
5580 dev_priv->drrs.dp = NULL;
5581 mutex_unlock(&dev_priv->drrs.mutex);
5582
5583 cancel_delayed_work_sync(&dev_priv->drrs.work);
5584}
5585
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305586static void intel_edp_drrs_downclock_work(struct work_struct *work)
5587{
5588 struct drm_i915_private *dev_priv =
5589 container_of(work, typeof(*dev_priv), drrs.work.work);
5590 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305591
Vandana Kannan96178ee2015-01-10 02:25:56 +05305592 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305593
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305594 intel_dp = dev_priv->drrs.dp;
5595
5596 if (!intel_dp)
5597 goto unlock;
5598
5599 /*
5600 * The delayed work can race with an invalidate hence we need to
5601 * recheck.
5602 */
5603
5604 if (dev_priv->drrs.busy_frontbuffer_bits)
5605 goto unlock;
5606
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005607 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5608 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5609
5610 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5611 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5612 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305613
5614unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305615 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305616}
5617
Vandana Kannanb33a2812015-02-13 15:33:03 +05305618/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305619 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005620 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305621 * @frontbuffer_bits: frontbuffer plane tracking bits
5622 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305623 * This function gets called everytime rendering on the given planes start.
5624 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305625 *
5626 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5627 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005628void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5629 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305630{
Vandana Kannana93fad02015-01-10 02:25:59 +05305631 struct drm_crtc *crtc;
5632 enum pipe pipe;
5633
Daniel Vetter9da7d692015-04-09 16:44:15 +02005634 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305635 return;
5636
Daniel Vetter88f933a2015-04-09 16:44:16 +02005637 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305638
Vandana Kannana93fad02015-01-10 02:25:59 +05305639 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005640 if (!dev_priv->drrs.dp) {
5641 mutex_unlock(&dev_priv->drrs.mutex);
5642 return;
5643 }
5644
Vandana Kannana93fad02015-01-10 02:25:59 +05305645 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5646 pipe = to_intel_crtc(crtc)->pipe;
5647
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005648 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5649 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5650
Ramalingam C0ddfd202015-06-15 20:50:05 +05305651 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005652 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005653 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5654 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305655
Vandana Kannana93fad02015-01-10 02:25:59 +05305656 mutex_unlock(&dev_priv->drrs.mutex);
5657}
5658
Vandana Kannanb33a2812015-02-13 15:33:03 +05305659/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305660 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005661 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305662 * @frontbuffer_bits: frontbuffer plane tracking bits
5663 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305664 * This function gets called every time rendering on the given planes has
5665 * completed or flip on a crtc is completed. So DRRS should be upclocked
5666 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5667 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305668 *
5669 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5670 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005671void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5672 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305673{
Vandana Kannana93fad02015-01-10 02:25:59 +05305674 struct drm_crtc *crtc;
5675 enum pipe pipe;
5676
Daniel Vetter9da7d692015-04-09 16:44:15 +02005677 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305678 return;
5679
Daniel Vetter88f933a2015-04-09 16:44:16 +02005680 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305681
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005683 if (!dev_priv->drrs.dp) {
5684 mutex_unlock(&dev_priv->drrs.mutex);
5685 return;
5686 }
5687
Vandana Kannana93fad02015-01-10 02:25:59 +05305688 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5689 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005690
5691 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305692 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5693
Ramalingam C0ddfd202015-06-15 20:50:05 +05305694 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005695 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005696 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5697 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305698
5699 /*
5700 * flush also means no more activity hence schedule downclock, if all
5701 * other fbs are quiescent too
5702 */
5703 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305704 schedule_delayed_work(&dev_priv->drrs.work,
5705 msecs_to_jiffies(1000));
5706 mutex_unlock(&dev_priv->drrs.mutex);
5707}
5708
Vandana Kannanb33a2812015-02-13 15:33:03 +05305709/**
5710 * DOC: Display Refresh Rate Switching (DRRS)
5711 *
5712 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5713 * which enables swtching between low and high refresh rates,
5714 * dynamically, based on the usage scenario. This feature is applicable
5715 * for internal panels.
5716 *
5717 * Indication that the panel supports DRRS is given by the panel EDID, which
5718 * would list multiple refresh rates for one resolution.
5719 *
5720 * DRRS is of 2 types - static and seamless.
5721 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5722 * (may appear as a blink on screen) and is used in dock-undock scenario.
5723 * Seamless DRRS involves changing RR without any visual effect to the user
5724 * and can be used during normal system usage. This is done by programming
5725 * certain registers.
5726 *
5727 * Support for static/seamless DRRS may be indicated in the VBT based on
5728 * inputs from the panel spec.
5729 *
5730 * DRRS saves power by switching to low RR based on usage scenarios.
5731 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005732 * The implementation is based on frontbuffer tracking implementation. When
5733 * there is a disturbance on the screen triggered by user activity or a periodic
5734 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5735 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5736 * made.
5737 *
5738 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5739 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305740 *
5741 * DRRS can be further extended to support other internal panels and also
5742 * the scenario of video playback wherein RR is set based on the rate
5743 * requested by userspace.
5744 */
5745
5746/**
5747 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5748 * @intel_connector: eDP connector
5749 * @fixed_mode: preferred mode of panel
5750 *
5751 * This function is called only once at driver load to initialize basic
5752 * DRRS stuff.
5753 *
5754 * Returns:
5755 * Downclock mode if panel supports it, else return NULL.
5756 * DRRS support is determined by the presence of downclock mode (apart
5757 * from VBT setting).
5758 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305759static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305760intel_dp_drrs_init(struct intel_connector *intel_connector,
5761 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762{
5763 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305764 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005765 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305766 struct drm_display_mode *downclock_mode = NULL;
5767
Daniel Vetter9da7d692015-04-09 16:44:15 +02005768 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5769 mutex_init(&dev_priv->drrs.mutex);
5770
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005771 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305772 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5773 return NULL;
5774 }
5775
5776 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005777 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305778 return NULL;
5779 }
5780
5781 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005782 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305783
5784 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305785 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305786 return NULL;
5787 }
5788
Vandana Kannan96178ee2015-01-10 02:25:56 +05305789 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305790
Vandana Kannan96178ee2015-01-10 02:25:56 +05305791 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005792 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305793 return downclock_mode;
5794}
5795
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005796static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005797 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005798{
5799 struct drm_connector *connector = &intel_connector->base;
5800 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005801 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5802 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005803 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005804 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305805 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005806 bool has_dpcd;
5807 struct drm_display_mode *scan;
5808 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005809 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005810
5811 if (!is_edp(intel_dp))
5812 return true;
5813
Imre Deak97a824e12016-06-21 11:51:47 +03005814 /*
5815 * On IBX/CPT we may get here with LVDS already registered. Since the
5816 * driver uses the only internal power sequencer available for both
5817 * eDP and LVDS bail out early in this case to prevent interfering
5818 * with an already powered-on LVDS power sequencer.
5819 */
5820 if (intel_get_lvds_encoder(dev)) {
5821 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5822 DRM_INFO("LVDS was detected, not registering eDP\n");
5823
5824 return false;
5825 }
5826
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005827 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005828
5829 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005830 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005831 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005832
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005833 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005834
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005835 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005836 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005837
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005838 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005839 /* if this fails, presume the device is a ghost */
5840 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005841 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005842 }
5843
Daniel Vetter060c8772014-03-21 23:22:35 +01005844 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005845 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005846 if (edid) {
5847 if (drm_add_edid_modes(connector, edid)) {
5848 drm_mode_connector_update_edid_property(connector,
5849 edid);
5850 drm_edid_to_eld(connector, edid);
5851 } else {
5852 kfree(edid);
5853 edid = ERR_PTR(-EINVAL);
5854 }
5855 } else {
5856 edid = ERR_PTR(-ENOENT);
5857 }
5858 intel_connector->edid = edid;
5859
5860 /* prefer fixed mode from EDID if available */
5861 list_for_each_entry(scan, &connector->probed_modes, head) {
5862 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5863 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305864 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305865 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005866 break;
5867 }
5868 }
5869
5870 /* fallback to VBT if available for eDP */
5871 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5872 fixed_mode = drm_mode_duplicate(dev,
5873 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005874 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005875 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005876 connector->display_info.width_mm = fixed_mode->width_mm;
5877 connector->display_info.height_mm = fixed_mode->height_mm;
5878 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005879 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005880 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005881
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005882 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005883 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5884 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005885
5886 /*
5887 * Figure out the current pipe for the initial backlight setup.
5888 * If the current pipe isn't valid, try the PPS pipe, and if that
5889 * fails just assume pipe A.
5890 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005891 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005892
5893 if (pipe != PIPE_A && pipe != PIPE_B)
5894 pipe = intel_dp->pps_pipe;
5895
5896 if (pipe != PIPE_A && pipe != PIPE_B)
5897 pipe = PIPE_A;
5898
5899 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5900 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005901 }
5902
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305903 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005904 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005905 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005906
5907 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005908
5909out_vdd_off:
5910 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5911 /*
5912 * vdd might still be enabled do to the delayed vdd off.
5913 * Make sure vdd is actually turned off here.
5914 */
5915 pps_lock(intel_dp);
5916 edp_panel_vdd_off_sync(intel_dp);
5917 pps_unlock(intel_dp);
5918
5919 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005920}
5921
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005922/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005923static void
5924intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5925{
5926 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005927 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005928
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005929 switch (intel_dig_port->port) {
5930 case PORT_A:
5931 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005932 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005933 break;
5934 case PORT_B:
5935 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005936 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005937 break;
5938 case PORT_C:
5939 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005940 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005941 break;
5942 case PORT_D:
5943 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005944 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005945 break;
5946 case PORT_E:
5947 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005948
5949 /* FIXME: Check VBT for actual wiring of PORT E */
5950 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005951 break;
5952 default:
5953 MISSING_CASE(intel_dig_port->port);
5954 }
5955}
5956
Paulo Zanoni16c25532013-06-12 17:27:25 -03005957bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005958intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5959 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005960{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005961 struct drm_connector *connector = &intel_connector->base;
5962 struct intel_dp *intel_dp = &intel_dig_port->dp;
5963 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5964 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005965 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005966 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005967 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005968
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005969 if (WARN(intel_dig_port->max_lanes < 1,
5970 "Not enough lanes (%d) for DP on port %c\n",
5971 intel_dig_port->max_lanes, port_name(port)))
5972 return false;
5973
Jani Nikula55cfc582017-03-28 17:59:04 +03005974 intel_dp_set_source_rates(intel_dp);
5975
Manasi Navared7e8ef02017-02-07 16:54:11 -08005976 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005977 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005978 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005979
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005980 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005981 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005982 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005983 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005984 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005985 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005986 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5987 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005988 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005989
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005990 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005991 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5992 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005993 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005994
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005995 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005996 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5997
Daniel Vetter07679352012-09-06 22:15:42 +02005998 /* Preserve the current hw state. */
5999 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006000 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006001
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006002 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306003 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006004 else
6005 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006006
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006007 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6008 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6009
Imre Deakf7d24902013-05-08 13:14:05 +03006010 /*
6011 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6012 * for DP the encoder type can be set by the caller to
6013 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6014 */
6015 if (type == DRM_MODE_CONNECTOR_eDP)
6016 intel_encoder->type = INTEL_OUTPUT_EDP;
6017
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006018 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006019 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006020 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006021 return false;
6022
Imre Deake7281ea2013-05-08 13:14:08 +03006023 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6024 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6025 port_name(port));
6026
Adam Jacksonb3295302010-07-16 14:46:28 -04006027 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006028 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6029
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006030 connector->interlace_allowed = true;
6031 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006032
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006033 intel_dp_init_connector_port_info(intel_dig_port);
6034
Mika Kaholab6339582016-09-09 14:10:52 +03006035 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006036
Daniel Vetter66a92782012-07-12 20:08:18 +02006037 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006038 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006039
Chris Wilsondf0e9242010-09-09 16:20:55 +01006040 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006041
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006042 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006043 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6044 else
6045 intel_connector->get_hw_state = intel_connector_get_hw_state;
6046
Dave Airlie0e32b392014-05-02 14:02:48 +10006047 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006048 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006049 (port == PORT_B || port == PORT_C || port == PORT_D))
6050 intel_dp_mst_encoder_init(intel_dig_port,
6051 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006052
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006053 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006054 intel_dp_aux_fini(intel_dp);
6055 intel_dp_mst_encoder_cleanup(intel_dig_port);
6056 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006057 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006058
Chris Wilsonf6849602010-09-19 09:29:33 +01006059 intel_dp_add_properties(intel_dp, connector);
6060
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006061 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6062 * 0xd. Failure to do so will result in spurious interrupts being
6063 * generated on the port when a cable is not attached.
6064 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006065 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006066 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6067 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6068 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006069
6070 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006071
6072fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006073 drm_connector_cleanup(connector);
6074
6075 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006076}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006077
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006078bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006079 i915_reg_t output_reg,
6080 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006081{
6082 struct intel_digital_port *intel_dig_port;
6083 struct intel_encoder *intel_encoder;
6084 struct drm_encoder *encoder;
6085 struct intel_connector *intel_connector;
6086
Daniel Vetterb14c5672013-09-19 12:18:32 +02006087 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006088 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006089 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006090
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006091 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306092 if (!intel_connector)
6093 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006094
6095 intel_encoder = &intel_dig_port->base;
6096 encoder = &intel_encoder->base;
6097
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006098 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6099 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6100 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306101 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006102
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006103 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006104 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006105 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006106 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006107 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006108 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006109 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006110 intel_encoder->pre_enable = chv_pre_enable_dp;
6111 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006112 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006113 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006114 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006115 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006116 intel_encoder->pre_enable = vlv_pre_enable_dp;
6117 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006118 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006119 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006120 intel_encoder->pre_enable = g4x_pre_enable_dp;
6121 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006122 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006123 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006124 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006125
Paulo Zanoni174edf12012-10-26 19:05:50 -02006126 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006127 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006128 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006129
Ville Syrjäläcca05022016-06-22 21:57:06 +03006130 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006131 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006132 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006133 if (port == PORT_D)
6134 intel_encoder->crtc_mask = 1 << 2;
6135 else
6136 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6137 } else {
6138 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6139 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006140 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006141 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006142
Dave Airlie13cf5502014-06-18 11:29:35 +10006143 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006144 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006145
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306146 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6147 goto err_init_connector;
6148
Chris Wilson457c52d2016-06-01 08:27:50 +01006149 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306150
6151err_init_connector:
6152 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306153err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306154 kfree(intel_connector);
6155err_connector_alloc:
6156 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006157 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006158}
Dave Airlie0e32b392014-05-02 14:02:48 +10006159
6160void intel_dp_mst_suspend(struct drm_device *dev)
6161{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006162 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006163 int i;
6164
6165 /* disable MST */
6166 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006167 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006168
6169 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006170 continue;
6171
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006172 if (intel_dig_port->dp.is_mst)
6173 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006174 }
6175}
6176
6177void intel_dp_mst_resume(struct drm_device *dev)
6178{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006179 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006180 int i;
6181
6182 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006183 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006184 int ret;
6185
6186 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006187 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006188
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006189 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6190 if (ret)
6191 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006192 }
6193}