blob: 8389ed1848ac02bdf446dc66ba9a2208312d425a [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;
Daniel Vetter083f9562012-04-20 20:23:49 +02001639 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001640 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001641 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001642 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301643
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001644 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001645 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301646
1647 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001648 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301649
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001650 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001651
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001652 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001653 pipe_config->has_pch_encoder = true;
1654
Vandana Kannanf769cd22014-08-05 07:51:22 -07001655 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001656 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001657
Jani Nikuladd06f902012-10-19 14:51:50 +03001658 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1659 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1660 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001661
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001662 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001663 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001664 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001665 if (ret)
1666 return ret;
1667 }
1668
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001669 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001670 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1671 intel_connector->panel.fitting_mode);
1672 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001673 intel_pch_panel_fitting(intel_crtc, pipe_config,
1674 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001675 }
1676
Daniel Vettercb1793c2012-06-04 18:39:21 +02001677 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001678 return false;
1679
Manasi Navareda15f7c2017-01-24 08:16:34 -08001680 /* Use values requested by Compliance Test Request */
1681 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001682 int index;
1683
1684 index = intel_dp_rate_index(intel_dp->common_rates,
1685 intel_dp->num_common_rates,
1686 intel_dp->compliance.test_link_rate);
1687 if (index >= 0)
1688 min_clock = max_clock = index;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001689 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1690 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001691 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301692 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001693 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001694 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001695
Daniel Vetter36008362013-03-27 00:44:59 +01001696 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1697 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001698 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001699 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301700
1701 /* Get bpp from vbt only for panels that dont have bpp in edid */
1702 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001703 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001704 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001705 dev_priv->vbt.edp.bpp);
1706 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001707 }
1708
Jani Nikula344c5bb2014-09-09 11:25:13 +03001709 /*
1710 * Use the maximum clock and number of lanes the eDP panel
1711 * advertizes being capable of. The panels are generally
1712 * designed to support only a single clock and lane
1713 * configuration, and typically these values correspond to the
1714 * native resolution of the panel.
1715 */
1716 min_lane_count = max_lane_count;
1717 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001718 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001719
Daniel Vetter36008362013-03-27 00:44:59 +01001720 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001721 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1722 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001723
Dave Airliec6930992014-07-14 11:04:39 +10001724 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301725 for (lane_count = min_lane_count;
1726 lane_count <= max_lane_count;
1727 lane_count <<= 1) {
1728
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001729 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001730 link_avail = intel_dp_max_data_rate(link_clock,
1731 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001732
Daniel Vetter36008362013-03-27 00:44:59 +01001733 if (mode_rate <= link_avail) {
1734 goto found;
1735 }
1736 }
1737 }
1738 }
1739
1740 return false;
1741
1742found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001743 if (intel_dp->color_range_auto) {
1744 /*
1745 * See:
1746 * CEA-861-E - 5.1 Default Encoding Parameters
1747 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1748 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001749 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001750 bpp != 18 &&
1751 drm_default_rgb_quant_range(adjusted_mode) ==
1752 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001753 } else {
1754 pipe_config->limited_color_range =
1755 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001756 }
1757
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001758 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301759
Daniel Vetter657445f2013-05-04 10:09:18 +02001760 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001761 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001762
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001763 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1764 &link_bw, &rate_select);
1765
1766 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1767 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001768 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001769 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1770 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001771
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001772 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001773 adjusted_mode->crtc_clock,
1774 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001775 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001776
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301777 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301778 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001779 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301780 intel_link_compute_m_n(bpp, lane_count,
1781 intel_connector->panel.downclock_mode->clock,
1782 pipe_config->port_clock,
1783 &pipe_config->dp_m2_n2);
1784 }
1785
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001786 /*
1787 * DPLL0 VCO may need to be adjusted to get the correct
1788 * clock for eDP. This will affect cdclk as well.
1789 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001790 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001791 int vco;
1792
1793 switch (pipe_config->port_clock / 2) {
1794 case 108000:
1795 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001796 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001797 break;
1798 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001799 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001800 break;
1801 }
1802
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001803 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001804 }
1805
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001806 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001807 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001808
Daniel Vetter36008362013-03-27 00:44:59 +01001809 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001810}
1811
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001812void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001813 int link_rate, uint8_t lane_count,
1814 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001815{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001816 intel_dp->link_rate = link_rate;
1817 intel_dp->lane_count = lane_count;
1818 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001819}
1820
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001821static void intel_dp_prepare(struct intel_encoder *encoder,
1822 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001823{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001824 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001825 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001826 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001827 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001828 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001829 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001830
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001831 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1832 pipe_config->lane_count,
1833 intel_crtc_has_type(pipe_config,
1834 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001835
Keith Packard417e8222011-11-01 19:54:11 -07001836 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001837 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001838 *
1839 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001840 * SNB CPU
1841 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001842 * CPT PCH
1843 *
1844 * IBX PCH and CPU are the same for almost everything,
1845 * except that the CPU DP PLL is configured in this
1846 * register
1847 *
1848 * CPT PCH is quite different, having many bits moved
1849 * to the TRANS_DP_CTL register instead. That
1850 * configuration happens (oddly) in ironlake_pch_enable
1851 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001852
Keith Packard417e8222011-11-01 19:54:11 -07001853 /* Preserve the BIOS-computed detected bit. This is
1854 * supposed to be read-only.
1855 */
1856 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001857
Keith Packard417e8222011-11-01 19:54:11 -07001858 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001859 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001860 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001861
Keith Packard417e8222011-11-01 19:54:11 -07001862 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001863
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001864 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001865 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1866 intel_dp->DP |= DP_SYNC_HS_HIGH;
1867 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1868 intel_dp->DP |= DP_SYNC_VS_HIGH;
1869 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1870
Jani Nikula6aba5b62013-10-04 15:08:10 +03001871 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001872 intel_dp->DP |= DP_ENHANCED_FRAMING;
1873
Daniel Vetter7c62a162013-06-01 17:16:20 +02001874 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001875 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001876 u32 trans_dp;
1877
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001878 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001879
1880 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1881 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1882 trans_dp |= TRANS_DP_ENH_FRAMING;
1883 else
1884 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1885 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001886 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001887 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001888 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001889
1890 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1891 intel_dp->DP |= DP_SYNC_HS_HIGH;
1892 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1893 intel_dp->DP |= DP_SYNC_VS_HIGH;
1894 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1895
Jani Nikula6aba5b62013-10-04 15:08:10 +03001896 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001897 intel_dp->DP |= DP_ENHANCED_FRAMING;
1898
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001899 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001900 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001901 else if (crtc->pipe == PIPE_B)
1902 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001903 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001904}
1905
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001906#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1907#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001908
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001909#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1910#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001911
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001912#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1913#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001914
Imre Deakde9c1b62016-06-16 20:01:46 +03001915static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1916 struct intel_dp *intel_dp);
1917
Daniel Vetter4be73782014-01-17 14:39:48 +01001918static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001919 u32 mask,
1920 u32 value)
1921{
Paulo Zanoni30add222012-10-26 19:05:45 -02001922 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001923 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001924 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001925
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001926 lockdep_assert_held(&dev_priv->pps_mutex);
1927
Imre Deakde9c1b62016-06-16 20:01:46 +03001928 intel_pps_verify_state(dev_priv, intel_dp);
1929
Jani Nikulabf13e812013-09-06 07:40:05 +03001930 pp_stat_reg = _pp_stat_reg(intel_dp);
1931 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001932
1933 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001934 mask, value,
1935 I915_READ(pp_stat_reg),
1936 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001937
Chris Wilson9036ff02016-06-30 15:33:09 +01001938 if (intel_wait_for_register(dev_priv,
1939 pp_stat_reg, mask, value,
1940 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001941 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001942 I915_READ(pp_stat_reg),
1943 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001944
1945 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001946}
1947
Daniel Vetter4be73782014-01-17 14:39:48 +01001948static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001949{
1950 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001951 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001952}
1953
Daniel Vetter4be73782014-01-17 14:39:48 +01001954static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001955{
Keith Packardbd943152011-09-18 23:09:52 -07001956 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001957 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001958}
Keith Packardbd943152011-09-18 23:09:52 -07001959
Daniel Vetter4be73782014-01-17 14:39:48 +01001960static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001961{
Abhay Kumard28d4732016-01-22 17:39:04 -08001962 ktime_t panel_power_on_time;
1963 s64 panel_power_off_duration;
1964
Keith Packard99ea7122011-11-01 19:57:50 -07001965 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001966
Abhay Kumard28d4732016-01-22 17:39:04 -08001967 /* take the difference of currrent time and panel power off time
1968 * and then make panel wait for t11_t12 if needed. */
1969 panel_power_on_time = ktime_get_boottime();
1970 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1971
Paulo Zanonidce56b32013-12-19 14:29:40 -02001972 /* When we disable the VDD override bit last we have to do the manual
1973 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001974 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1975 wait_remaining_ms_from_jiffies(jiffies,
1976 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001977
Daniel Vetter4be73782014-01-17 14:39:48 +01001978 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001979}
Keith Packardbd943152011-09-18 23:09:52 -07001980
Daniel Vetter4be73782014-01-17 14:39:48 +01001981static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001982{
1983 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1984 intel_dp->backlight_on_delay);
1985}
1986
Daniel Vetter4be73782014-01-17 14:39:48 +01001987static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001988{
1989 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1990 intel_dp->backlight_off_delay);
1991}
Keith Packard99ea7122011-11-01 19:57:50 -07001992
Keith Packard832dd3c2011-11-01 19:34:06 -07001993/* Read the current pp_control value, unlocking the register if it
1994 * is locked
1995 */
1996
Jesse Barnes453c5422013-03-28 09:55:41 -07001997static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001998{
Jesse Barnes453c5422013-03-28 09:55:41 -07001999 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002000 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002001 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002002
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002003 lockdep_assert_held(&dev_priv->pps_mutex);
2004
Jani Nikulabf13e812013-09-06 07:40:05 +03002005 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002006 if (WARN_ON(!HAS_DDI(dev_priv) &&
2007 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302008 control &= ~PANEL_UNLOCK_MASK;
2009 control |= PANEL_UNLOCK_REGS;
2010 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002011 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002012}
2013
Ville Syrjälä951468f2014-09-04 14:55:31 +03002014/*
2015 * Must be paired with edp_panel_vdd_off().
2016 * Must hold pps_mutex around the whole on/off sequence.
2017 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2018 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002019static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002020{
Paulo Zanoni30add222012-10-26 19:05:45 -02002021 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002022 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002023 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002024 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002025 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002026 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002027
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002028 lockdep_assert_held(&dev_priv->pps_mutex);
2029
Keith Packard97af61f572011-09-28 16:23:51 -07002030 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002031 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002032
Egbert Eich2c623c12014-11-25 12:54:57 +01002033 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002034 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002035
Daniel Vetter4be73782014-01-17 14:39:48 +01002036 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002037 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002038
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002039 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002040
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002041 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2042 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002043
Daniel Vetter4be73782014-01-17 14:39:48 +01002044 if (!edp_have_panel_power(intel_dp))
2045 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002046
Jesse Barnes453c5422013-03-28 09:55:41 -07002047 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002048 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002049
Jani Nikulabf13e812013-09-06 07:40:05 +03002050 pp_stat_reg = _pp_stat_reg(intel_dp);
2051 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002052
2053 I915_WRITE(pp_ctrl_reg, pp);
2054 POSTING_READ(pp_ctrl_reg);
2055 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2056 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002057 /*
2058 * If the panel wasn't on, delay before accessing aux channel
2059 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002060 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002061 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2062 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002063 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002064 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002065
2066 return need_to_disable;
2067}
2068
Ville Syrjälä951468f2014-09-04 14:55:31 +03002069/*
2070 * Must be paired with intel_edp_panel_vdd_off() or
2071 * intel_edp_panel_off().
2072 * Nested calls to these functions are not allowed since
2073 * we drop the lock. Caller must use some higher level
2074 * locking to prevent nested calls from other threads.
2075 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002076void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002077{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002078 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002079
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002080 if (!is_edp(intel_dp))
2081 return;
2082
Ville Syrjälä773538e82014-09-04 14:54:56 +03002083 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002084 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002085 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002086
Rob Clarke2c719b2014-12-15 13:56:32 -05002087 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002088 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002089}
2090
Daniel Vetter4be73782014-01-17 14:39:48 +01002091static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002092{
Paulo Zanoni30add222012-10-26 19:05:45 -02002093 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002094 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002095 struct intel_digital_port *intel_dig_port =
2096 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002097 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002098 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002099
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002100 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002101
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002102 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002103
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002104 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002105 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002106
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002107 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2108 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002109
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002110 pp = ironlake_get_pp_control(intel_dp);
2111 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002112
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002113 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2114 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002115
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002116 I915_WRITE(pp_ctrl_reg, pp);
2117 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002118
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002119 /* Make sure sequencer is idle before allowing subsequent activity */
2120 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2121 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002122
Imre Deak5a162e22016-08-10 14:07:30 +03002123 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002124 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002125
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002126 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002127}
2128
Daniel Vetter4be73782014-01-17 14:39:48 +01002129static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002130{
2131 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2132 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002133
Ville Syrjälä773538e82014-09-04 14:54:56 +03002134 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002135 if (!intel_dp->want_panel_vdd)
2136 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002137 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002138}
2139
Imre Deakaba86892014-07-30 15:57:31 +03002140static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2141{
2142 unsigned long delay;
2143
2144 /*
2145 * Queue the timer to fire a long time from now (relative to the power
2146 * down delay) to keep the panel power up across a sequence of
2147 * operations.
2148 */
2149 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2150 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2151}
2152
Ville Syrjälä951468f2014-09-04 14:55:31 +03002153/*
2154 * Must be paired with edp_panel_vdd_on().
2155 * Must hold pps_mutex around the whole on/off sequence.
2156 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2157 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002158static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002159{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002160 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002161
2162 lockdep_assert_held(&dev_priv->pps_mutex);
2163
Keith Packard97af61f572011-09-28 16:23:51 -07002164 if (!is_edp(intel_dp))
2165 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002166
Rob Clarke2c719b2014-12-15 13:56:32 -05002167 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002168 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002169
Keith Packardbd943152011-09-18 23:09:52 -07002170 intel_dp->want_panel_vdd = false;
2171
Imre Deakaba86892014-07-30 15:57:31 +03002172 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002173 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002174 else
2175 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002176}
2177
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002178static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002179{
Paulo Zanoni30add222012-10-26 19:05:45 -02002180 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002181 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002182 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002183 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002184
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002185 lockdep_assert_held(&dev_priv->pps_mutex);
2186
Keith Packard97af61f572011-09-28 16:23:51 -07002187 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002188 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002189
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002190 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2191 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002192
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002193 if (WARN(edp_have_panel_power(intel_dp),
2194 "eDP port %c panel power already on\n",
2195 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002196 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002197
Daniel Vetter4be73782014-01-17 14:39:48 +01002198 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002199
Jani Nikulabf13e812013-09-06 07:40:05 +03002200 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002201 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002202 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002203 /* ILK workaround: disable reset around power sequence */
2204 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002205 I915_WRITE(pp_ctrl_reg, pp);
2206 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002207 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002208
Imre Deak5a162e22016-08-10 14:07:30 +03002209 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002210 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002211 pp |= PANEL_POWER_RESET;
2212
Jesse Barnes453c5422013-03-28 09:55:41 -07002213 I915_WRITE(pp_ctrl_reg, pp);
2214 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002215
Daniel Vetter4be73782014-01-17 14:39:48 +01002216 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002217 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002218
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002219 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002220 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002221 I915_WRITE(pp_ctrl_reg, pp);
2222 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002223 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002224}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002225
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002226void intel_edp_panel_on(struct intel_dp *intel_dp)
2227{
2228 if (!is_edp(intel_dp))
2229 return;
2230
2231 pps_lock(intel_dp);
2232 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002233 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002234}
2235
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002236
2237static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002238{
Paulo Zanoni30add222012-10-26 19:05:45 -02002239 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002240 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002241 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002242 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002243
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002244 lockdep_assert_held(&dev_priv->pps_mutex);
2245
Keith Packard97af61f572011-09-28 16:23:51 -07002246 if (!is_edp(intel_dp))
2247 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002248
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002249 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2250 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002251
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002252 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2253 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002254
Jesse Barnes453c5422013-03-28 09:55:41 -07002255 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002256 /* We need to switch off panel power _and_ force vdd, for otherwise some
2257 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002258 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002259 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002260
Jani Nikulabf13e812013-09-06 07:40:05 +03002261 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002262
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002263 intel_dp->want_panel_vdd = false;
2264
Jesse Barnes453c5422013-03-28 09:55:41 -07002265 I915_WRITE(pp_ctrl_reg, pp);
2266 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002267
Abhay Kumard28d4732016-01-22 17:39:04 -08002268 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002269 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002270
2271 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002272 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002273}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002274
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002275void intel_edp_panel_off(struct intel_dp *intel_dp)
2276{
2277 if (!is_edp(intel_dp))
2278 return;
2279
2280 pps_lock(intel_dp);
2281 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002282 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002283}
2284
Jani Nikula1250d102014-08-12 17:11:39 +03002285/* Enable backlight in the panel power control. */
2286static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002287{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002288 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2289 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002290 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002291 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002292 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002293
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002294 /*
2295 * If we enable the backlight right away following a panel power
2296 * on, we may see slight flicker as the panel syncs with the eDP
2297 * link. So delay a bit to make sure the image is solid before
2298 * allowing it to appear.
2299 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002300 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002301
Ville Syrjälä773538e82014-09-04 14:54:56 +03002302 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002303
Jesse Barnes453c5422013-03-28 09:55:41 -07002304 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002305 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002306
Jani Nikulabf13e812013-09-06 07:40:05 +03002307 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002308
2309 I915_WRITE(pp_ctrl_reg, pp);
2310 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002311
Ville Syrjälä773538e82014-09-04 14:54:56 +03002312 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002313}
2314
Jani Nikula1250d102014-08-12 17:11:39 +03002315/* Enable backlight PWM and backlight PP control. */
2316void intel_edp_backlight_on(struct intel_dp *intel_dp)
2317{
2318 if (!is_edp(intel_dp))
2319 return;
2320
2321 DRM_DEBUG_KMS("\n");
2322
2323 intel_panel_enable_backlight(intel_dp->attached_connector);
2324 _intel_edp_backlight_on(intel_dp);
2325}
2326
2327/* Disable backlight in the panel power control. */
2328static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002329{
Paulo Zanoni30add222012-10-26 19:05:45 -02002330 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002331 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002332 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002333 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002334
Keith Packardf01eca22011-09-28 16:48:10 -07002335 if (!is_edp(intel_dp))
2336 return;
2337
Ville Syrjälä773538e82014-09-04 14:54:56 +03002338 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002339
Jesse Barnes453c5422013-03-28 09:55:41 -07002340 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002341 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002342
Jani Nikulabf13e812013-09-06 07:40:05 +03002343 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002344
2345 I915_WRITE(pp_ctrl_reg, pp);
2346 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002347
Ville Syrjälä773538e82014-09-04 14:54:56 +03002348 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002349
Paulo Zanonidce56b32013-12-19 14:29:40 -02002350 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002351 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002352}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002353
Jani Nikula1250d102014-08-12 17:11:39 +03002354/* Disable backlight PP control and backlight PWM. */
2355void intel_edp_backlight_off(struct intel_dp *intel_dp)
2356{
2357 if (!is_edp(intel_dp))
2358 return;
2359
2360 DRM_DEBUG_KMS("\n");
2361
2362 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002363 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002364}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002365
Jani Nikula73580fb72014-08-12 17:11:41 +03002366/*
2367 * Hook for controlling the panel power control backlight through the bl_power
2368 * sysfs attribute. Take care to handle multiple calls.
2369 */
2370static void intel_edp_backlight_power(struct intel_connector *connector,
2371 bool enable)
2372{
2373 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002374 bool is_enabled;
2375
Ville Syrjälä773538e82014-09-04 14:54:56 +03002376 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002377 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002378 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002379
2380 if (is_enabled == enable)
2381 return;
2382
Jani Nikula23ba9372014-08-27 14:08:43 +03002383 DRM_DEBUG_KMS("panel power control backlight %s\n",
2384 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002385
2386 if (enable)
2387 _intel_edp_backlight_on(intel_dp);
2388 else
2389 _intel_edp_backlight_off(intel_dp);
2390}
2391
Ville Syrjälä64e10772015-10-29 21:26:01 +02002392static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2393{
2394 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2395 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2396 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2397
2398 I915_STATE_WARN(cur_state != state,
2399 "DP port %c state assertion failure (expected %s, current %s)\n",
2400 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002401 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002402}
2403#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2404
2405static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2406{
2407 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2408
2409 I915_STATE_WARN(cur_state != state,
2410 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002411 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002412}
2413#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2414#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2415
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002416static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2417 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002418{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002419 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002420 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002421
Ville Syrjälä64e10772015-10-29 21:26:01 +02002422 assert_pipe_disabled(dev_priv, crtc->pipe);
2423 assert_dp_port_disabled(intel_dp);
2424 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002425
Ville Syrjäläabfce942015-10-29 21:26:03 +02002426 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002427 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002428
2429 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2430
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002431 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002432 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2433 else
2434 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2435
2436 I915_WRITE(DP_A, intel_dp->DP);
2437 POSTING_READ(DP_A);
2438 udelay(500);
2439
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002440 /*
2441 * [DevILK] Work around required when enabling DP PLL
2442 * while a pipe is enabled going to FDI:
2443 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2444 * 2. Program DP PLL enable
2445 */
2446 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002447 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002448
Daniel Vetter07679352012-09-06 22:15:42 +02002449 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002450
Daniel Vetter07679352012-09-06 22:15:42 +02002451 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002452 POSTING_READ(DP_A);
2453 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002454}
2455
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002456static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002457{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002458 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002459 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2460 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002461
Ville Syrjälä64e10772015-10-29 21:26:01 +02002462 assert_pipe_disabled(dev_priv, crtc->pipe);
2463 assert_dp_port_disabled(intel_dp);
2464 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002465
Ville Syrjäläabfce942015-10-29 21:26:03 +02002466 DRM_DEBUG_KMS("disabling eDP PLL\n");
2467
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002468 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002469
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002470 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002471 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002472 udelay(200);
2473}
2474
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002475/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002476void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002477{
2478 int ret, i;
2479
2480 /* Should have a valid DPCD by this point */
2481 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2482 return;
2483
2484 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002485 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2486 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002487 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002488 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2489
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002490 /*
2491 * When turning on, we need to retry for 1ms to give the sink
2492 * time to wake up.
2493 */
2494 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002495 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2496 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002497 if (ret == 1)
2498 break;
2499 msleep(1);
2500 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002501
2502 if (ret == 1 && lspcon->active)
2503 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002504 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002505
2506 if (ret != 1)
2507 DRM_DEBUG_KMS("failed to %s sink power state\n",
2508 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002509}
2510
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002511static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2512 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002513{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002514 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002515 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002516 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002517 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002518 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002519 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002520
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002521 if (!intel_display_power_get_if_enabled(dev_priv,
2522 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002523 return false;
2524
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002525 ret = false;
2526
Imre Deak6d129be2014-03-05 16:20:54 +02002527 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002528
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002530 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002531
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002532 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002533 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002534 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002535 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002536
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002537 for_each_pipe(dev_priv, p) {
2538 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2539 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2540 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002541 ret = true;
2542
2543 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002544 }
2545 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002546
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002547 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002548 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002549 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002550 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2551 } else {
2552 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002553 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002554
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002555 ret = true;
2556
2557out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002558 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002559
2560 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002561}
2562
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002563static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002564 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002565{
2566 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002567 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002568 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002569 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002570 enum port port = dp_to_dig_port(intel_dp)->port;
2571 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002572
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002573 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002574
2575 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002576
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002577 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002578 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2579
2580 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002581 flags |= DRM_MODE_FLAG_PHSYNC;
2582 else
2583 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002584
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002585 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002586 flags |= DRM_MODE_FLAG_PVSYNC;
2587 else
2588 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002589 } else {
2590 if (tmp & DP_SYNC_HS_HIGH)
2591 flags |= DRM_MODE_FLAG_PHSYNC;
2592 else
2593 flags |= DRM_MODE_FLAG_NHSYNC;
2594
2595 if (tmp & DP_SYNC_VS_HIGH)
2596 flags |= DRM_MODE_FLAG_PVSYNC;
2597 else
2598 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002599 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002600
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002601 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002602
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002603 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002604 pipe_config->limited_color_range = true;
2605
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002606 pipe_config->lane_count =
2607 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2608
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002609 intel_dp_get_m_n(crtc, pipe_config);
2610
Ville Syrjälä18442d02013-09-13 16:00:08 +03002611 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002612 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002613 pipe_config->port_clock = 162000;
2614 else
2615 pipe_config->port_clock = 270000;
2616 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002617
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002618 pipe_config->base.adjusted_mode.crtc_clock =
2619 intel_dotclock_calculate(pipe_config->port_clock,
2620 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002621
Jani Nikula6aa23e62016-03-24 17:50:20 +02002622 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2623 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002624 /*
2625 * This is a big fat ugly hack.
2626 *
2627 * Some machines in UEFI boot mode provide us a VBT that has 18
2628 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2629 * unknown we fail to light up. Yet the same BIOS boots up with
2630 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2631 * max, not what it tells us to use.
2632 *
2633 * Note: This will still be broken if the eDP panel is not lit
2634 * up by the BIOS, and thus we can't get the mode at module
2635 * load.
2636 */
2637 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002638 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2639 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002640 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002641}
2642
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002643static void intel_disable_dp(struct intel_encoder *encoder,
2644 struct intel_crtc_state *old_crtc_state,
2645 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002646{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002647 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002648 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002649
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002650 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002651 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002652
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002653 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002654 intel_psr_disable(intel_dp);
2655
Daniel Vetter6cb49832012-05-20 17:14:50 +02002656 /* Make sure the panel is off before trying to change the mode. But also
2657 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002658 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002659 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002660 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002661 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002662
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002663 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002664 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002665 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002666}
2667
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002668static void ilk_post_disable_dp(struct intel_encoder *encoder,
2669 struct intel_crtc_state *old_crtc_state,
2670 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002671{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002672 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002673 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002674
Ville Syrjälä49277c32014-03-31 18:21:26 +03002675 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002676
2677 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002678 if (port == PORT_A)
2679 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002680}
2681
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002682static void vlv_post_disable_dp(struct intel_encoder *encoder,
2683 struct intel_crtc_state *old_crtc_state,
2684 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002685{
2686 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2687
2688 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002689}
2690
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002691static void chv_post_disable_dp(struct intel_encoder *encoder,
2692 struct intel_crtc_state *old_crtc_state,
2693 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002694{
2695 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002696 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002697 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002698
2699 intel_dp_link_down(intel_dp);
2700
Ville Syrjäläa5805162015-05-26 20:42:30 +03002701 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002702
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002703 /* Assert data lane reset */
2704 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002705
Ville Syrjäläa5805162015-05-26 20:42:30 +03002706 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002707}
2708
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002709static void
2710_intel_dp_set_link_train(struct intel_dp *intel_dp,
2711 uint32_t *DP,
2712 uint8_t dp_train_pat)
2713{
2714 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2715 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002716 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002717 enum port port = intel_dig_port->port;
2718
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002719 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2720 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2721 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2722
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002723 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002724 uint32_t temp = I915_READ(DP_TP_CTL(port));
2725
2726 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2727 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2728 else
2729 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2730
2731 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2732 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2733 case DP_TRAINING_PATTERN_DISABLE:
2734 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2735
2736 break;
2737 case DP_TRAINING_PATTERN_1:
2738 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2739 break;
2740 case DP_TRAINING_PATTERN_2:
2741 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2742 break;
2743 case DP_TRAINING_PATTERN_3:
2744 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2745 break;
2746 }
2747 I915_WRITE(DP_TP_CTL(port), temp);
2748
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002749 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002750 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002751 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2752
2753 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2754 case DP_TRAINING_PATTERN_DISABLE:
2755 *DP |= DP_LINK_TRAIN_OFF_CPT;
2756 break;
2757 case DP_TRAINING_PATTERN_1:
2758 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2759 break;
2760 case DP_TRAINING_PATTERN_2:
2761 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2762 break;
2763 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002764 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002765 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2766 break;
2767 }
2768
2769 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002770 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002771 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2772 else
2773 *DP &= ~DP_LINK_TRAIN_MASK;
2774
2775 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2776 case DP_TRAINING_PATTERN_DISABLE:
2777 *DP |= DP_LINK_TRAIN_OFF;
2778 break;
2779 case DP_TRAINING_PATTERN_1:
2780 *DP |= DP_LINK_TRAIN_PAT_1;
2781 break;
2782 case DP_TRAINING_PATTERN_2:
2783 *DP |= DP_LINK_TRAIN_PAT_2;
2784 break;
2785 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002786 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002787 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2788 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002789 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002790 *DP |= DP_LINK_TRAIN_PAT_2;
2791 }
2792 break;
2793 }
2794 }
2795}
2796
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002797static void intel_dp_enable_port(struct intel_dp *intel_dp,
2798 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002799{
2800 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002801 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002802
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002803 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002804
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002805 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002806
2807 /*
2808 * Magic for VLV/CHV. We _must_ first set up the register
2809 * without actually enabling the port, and then do another
2810 * write to enable the port. Otherwise link training will
2811 * fail when the power sequencer is freshly used for this port.
2812 */
2813 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002814 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002815 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002816
2817 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2818 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002819}
2820
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002821static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002822 struct intel_crtc_state *pipe_config,
2823 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002824{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002825 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2826 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002827 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002828 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002829 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002830 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002831
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002832 if (WARN_ON(dp_reg & DP_PORT_EN))
2833 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002834
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002835 pps_lock(intel_dp);
2836
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002837 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002838 vlv_init_panel_power_sequencer(intel_dp);
2839
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002840 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002841
2842 edp_panel_vdd_on(intel_dp);
2843 edp_panel_on(intel_dp);
2844 edp_panel_vdd_off(intel_dp, true);
2845
2846 pps_unlock(intel_dp);
2847
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002848 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002849 unsigned int lane_mask = 0x0;
2850
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002851 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002852 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002853
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002854 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2855 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002856 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002857
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002858 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2859 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002860 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002861
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002862 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002863 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002864 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002865 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002866 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002867}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002868
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002869static void g4x_enable_dp(struct intel_encoder *encoder,
2870 struct intel_crtc_state *pipe_config,
2871 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002872{
Jani Nikula828f5c62013-09-05 16:44:45 +03002873 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2874
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002875 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002876 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002877}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002878
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002879static void vlv_enable_dp(struct intel_encoder *encoder,
2880 struct intel_crtc_state *pipe_config,
2881 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002882{
Jani Nikula828f5c62013-09-05 16:44:45 +03002883 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2884
Daniel Vetter4be73782014-01-17 14:39:48 +01002885 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002886 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002887}
2888
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002889static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2890 struct intel_crtc_state *pipe_config,
2891 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002892{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002893 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002894 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002895
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002896 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002897
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002898 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002899 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002900 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002901}
2902
Ville Syrjälä83b84592014-10-16 21:29:51 +03002903static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2904{
2905 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002906 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002907 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002908 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002909
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002910 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2911
Ville Syrjäläd1586942017-02-08 19:52:54 +02002912 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2913 return;
2914
Ville Syrjälä83b84592014-10-16 21:29:51 +03002915 edp_panel_vdd_off_sync(intel_dp);
2916
2917 /*
2918 * VLV seems to get confused when multiple power seqeuencers
2919 * have the same port selected (even if only one has power/vdd
2920 * enabled). The failure manifests as vlv_wait_port_ready() failing
2921 * CHV on the other hand doesn't seem to mind having the same port
2922 * selected in multiple power seqeuencers, but let's clear the
2923 * port select always when logically disconnecting a power sequencer
2924 * from a port.
2925 */
2926 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2927 pipe_name(pipe), port_name(intel_dig_port->port));
2928 I915_WRITE(pp_on_reg, 0);
2929 POSTING_READ(pp_on_reg);
2930
2931 intel_dp->pps_pipe = INVALID_PIPE;
2932}
2933
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002934static void vlv_steal_power_sequencer(struct drm_device *dev,
2935 enum pipe pipe)
2936{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002937 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002938 struct intel_encoder *encoder;
2939
2940 lockdep_assert_held(&dev_priv->pps_mutex);
2941
Jani Nikula19c80542015-12-16 12:48:16 +02002942 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002943 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002944 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002945
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002946 if (encoder->type != INTEL_OUTPUT_DP &&
2947 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002948 continue;
2949
2950 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002951 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002952
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002953 WARN(intel_dp->active_pipe == pipe,
2954 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2955 pipe_name(pipe), port_name(port));
2956
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002957 if (intel_dp->pps_pipe != pipe)
2958 continue;
2959
2960 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002961 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002962
2963 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002964 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002965 }
2966}
2967
2968static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2969{
2970 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2971 struct intel_encoder *encoder = &intel_dig_port->base;
2972 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002973 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002974 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002975
2976 lockdep_assert_held(&dev_priv->pps_mutex);
2977
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002978 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002979
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002980 if (intel_dp->pps_pipe != INVALID_PIPE &&
2981 intel_dp->pps_pipe != crtc->pipe) {
2982 /*
2983 * If another power sequencer was being used on this
2984 * port previously make sure to turn off vdd there while
2985 * we still have control of it.
2986 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002987 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002988 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002989
2990 /*
2991 * We may be stealing the power
2992 * sequencer from another port.
2993 */
2994 vlv_steal_power_sequencer(dev, crtc->pipe);
2995
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002996 intel_dp->active_pipe = crtc->pipe;
2997
2998 if (!is_edp(intel_dp))
2999 return;
3000
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003001 /* now it's all ours */
3002 intel_dp->pps_pipe = crtc->pipe;
3003
3004 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3005 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3006
3007 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003008 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003009 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003010}
3011
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003012static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3013 struct intel_crtc_state *pipe_config,
3014 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003015{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003016 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003017
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003018 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003019}
3020
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003021static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3022 struct intel_crtc_state *pipe_config,
3023 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003024{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003025 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003026
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003027 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003028}
3029
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003030static void chv_pre_enable_dp(struct intel_encoder *encoder,
3031 struct intel_crtc_state *pipe_config,
3032 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003033{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003034 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003035
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003036 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003037
3038 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003039 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003040}
3041
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003042static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3043 struct intel_crtc_state *pipe_config,
3044 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003045{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003046 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003047
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003048 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003049}
3050
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003051static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3052 struct intel_crtc_state *pipe_config,
3053 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003054{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003055 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003056}
3057
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003058/*
3059 * Fetch AUX CH registers 0x202 - 0x207 which contain
3060 * link status information
3061 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003062bool
Keith Packard93f62da2011-11-01 19:45:03 -07003063intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003064{
Lyude9f085eb2016-04-13 10:58:33 -04003065 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3066 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003067}
3068
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303069static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3070{
3071 uint8_t psr_caps = 0;
3072
3073 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3074 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3075}
3076
3077static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3078{
3079 uint8_t dprx = 0;
3080
3081 drm_dp_dpcd_readb(&intel_dp->aux,
3082 DP_DPRX_FEATURE_ENUMERATION_LIST,
3083 &dprx);
3084 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3085}
3086
Chris Wilsona76f73d2017-01-14 10:51:13 +00003087static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303088{
3089 uint8_t alpm_caps = 0;
3090
3091 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3092 return alpm_caps & DP_ALPM_CAP;
3093}
3094
Paulo Zanoni11002442014-06-13 18:45:41 -03003095/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003096uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003097intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003098{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003099 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003100 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003101
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003102 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303103 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003104 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003105 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3106 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003107 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303108 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003109 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303110 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003111 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303112 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003113 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303114 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003115}
3116
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003117uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003118intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3119{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003120 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003121 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003122
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003123 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003124 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3126 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3127 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3128 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3129 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3130 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303131 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3132 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003133 default:
3134 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3135 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003136 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003137 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303138 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3139 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3140 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3141 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3142 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3143 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3144 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003145 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303146 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003147 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003148 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003149 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3151 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3152 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3153 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3154 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3155 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3156 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003157 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303158 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003159 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003160 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003161 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303162 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3163 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3164 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3165 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3166 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003167 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303168 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003169 }
3170 } else {
3171 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3173 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3174 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3175 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3176 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3177 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3178 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003179 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303180 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003181 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003182 }
3183}
3184
Daniel Vetter5829975c2015-04-16 11:36:52 +02003185static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003186{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003187 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003188 unsigned long demph_reg_value, preemph_reg_value,
3189 uniqtranscale_reg_value;
3190 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003191
3192 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003194 preemph_reg_value = 0x0004000;
3195 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003197 demph_reg_value = 0x2B405555;
3198 uniqtranscale_reg_value = 0x552AB83A;
3199 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303200 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003201 demph_reg_value = 0x2B404040;
3202 uniqtranscale_reg_value = 0x5548B83A;
3203 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003205 demph_reg_value = 0x2B245555;
3206 uniqtranscale_reg_value = 0x5560B83A;
3207 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003209 demph_reg_value = 0x2B405555;
3210 uniqtranscale_reg_value = 0x5598DA3A;
3211 break;
3212 default:
3213 return 0;
3214 }
3215 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303216 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217 preemph_reg_value = 0x0002000;
3218 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003220 demph_reg_value = 0x2B404040;
3221 uniqtranscale_reg_value = 0x5552B83A;
3222 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303223 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003224 demph_reg_value = 0x2B404848;
3225 uniqtranscale_reg_value = 0x5580B83A;
3226 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303227 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003228 demph_reg_value = 0x2B404040;
3229 uniqtranscale_reg_value = 0x55ADDA3A;
3230 break;
3231 default:
3232 return 0;
3233 }
3234 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 preemph_reg_value = 0x0000000;
3237 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303238 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003239 demph_reg_value = 0x2B305555;
3240 uniqtranscale_reg_value = 0x5570B83A;
3241 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303242 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003243 demph_reg_value = 0x2B2B4040;
3244 uniqtranscale_reg_value = 0x55ADDA3A;
3245 break;
3246 default:
3247 return 0;
3248 }
3249 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003251 preemph_reg_value = 0x0006000;
3252 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003254 demph_reg_value = 0x1B405555;
3255 uniqtranscale_reg_value = 0x55ADDA3A;
3256 break;
3257 default:
3258 return 0;
3259 }
3260 break;
3261 default:
3262 return 0;
3263 }
3264
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003265 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3266 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003267
3268 return 0;
3269}
3270
Daniel Vetter5829975c2015-04-16 11:36:52 +02003271static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003272{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003273 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3274 u32 deemph_reg_value, margin_reg_value;
3275 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003276 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003277
3278 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303279 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003280 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003282 deemph_reg_value = 128;
3283 margin_reg_value = 52;
3284 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003286 deemph_reg_value = 128;
3287 margin_reg_value = 77;
3288 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290 deemph_reg_value = 128;
3291 margin_reg_value = 102;
3292 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003294 deemph_reg_value = 128;
3295 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003296 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003297 break;
3298 default:
3299 return 0;
3300 }
3301 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303302 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003303 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303304 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003305 deemph_reg_value = 85;
3306 margin_reg_value = 78;
3307 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303308 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003309 deemph_reg_value = 85;
3310 margin_reg_value = 116;
3311 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003313 deemph_reg_value = 85;
3314 margin_reg_value = 154;
3315 break;
3316 default:
3317 return 0;
3318 }
3319 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003321 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003323 deemph_reg_value = 64;
3324 margin_reg_value = 104;
3325 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303326 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003327 deemph_reg_value = 64;
3328 margin_reg_value = 154;
3329 break;
3330 default:
3331 return 0;
3332 }
3333 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303334 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003335 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303336 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003337 deemph_reg_value = 43;
3338 margin_reg_value = 154;
3339 break;
3340 default:
3341 return 0;
3342 }
3343 break;
3344 default:
3345 return 0;
3346 }
3347
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003348 chv_set_phy_signal_level(encoder, deemph_reg_value,
3349 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003350
3351 return 0;
3352}
3353
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003354static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003355gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003356{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003357 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003358
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003359 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003361 default:
3362 signal_levels |= DP_VOLTAGE_0_4;
3363 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303364 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003365 signal_levels |= DP_VOLTAGE_0_6;
3366 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303367 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003368 signal_levels |= DP_VOLTAGE_0_8;
3369 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303370 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003371 signal_levels |= DP_VOLTAGE_1_2;
3372 break;
3373 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003374 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303375 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003376 default:
3377 signal_levels |= DP_PRE_EMPHASIS_0;
3378 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003380 signal_levels |= DP_PRE_EMPHASIS_3_5;
3381 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303382 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003383 signal_levels |= DP_PRE_EMPHASIS_6;
3384 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303385 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003386 signal_levels |= DP_PRE_EMPHASIS_9_5;
3387 break;
3388 }
3389 return signal_levels;
3390}
3391
Zhenyu Wange3421a12010-04-08 09:43:27 +08003392/* Gen6's DP voltage swing and pre-emphasis control */
3393static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003394gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003395{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003396 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3397 DP_TRAIN_PRE_EMPHASIS_MASK);
3398 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303399 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3400 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003401 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303402 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003403 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303404 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003406 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303407 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003409 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3411 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003412 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003413 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003414 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3415 "0x%x\n", signal_levels);
3416 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003417 }
3418}
3419
Keith Packard1a2eb462011-11-16 16:26:07 -08003420/* Gen7's DP voltage swing and pre-emphasis control */
3421static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003422gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003423{
3424 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3425 DP_TRAIN_PRE_EMPHASIS_MASK);
3426 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303427 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003428 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003430 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303431 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003432 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3433
Sonika Jindalbd600182014-08-08 16:23:41 +05303434 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003435 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303436 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003437 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3438
Sonika Jindalbd600182014-08-08 16:23:41 +05303439 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003440 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303441 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003442 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3443
3444 default:
3445 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3446 "0x%x\n", signal_levels);
3447 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3448 }
3449}
3450
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003451void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003452intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003453{
3454 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003455 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003456 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003457 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003458 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003459 uint8_t train_set = intel_dp->train_set[0];
3460
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003461 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003462 signal_levels = ddi_signal_levels(intel_dp);
3463
Michel Thierry254e0932017-01-09 16:51:35 +02003464 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003465 signal_levels = 0;
3466 else
3467 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003468 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003469 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003470 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003471 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003472 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003473 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003474 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003475 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003476 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003477 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3478 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003479 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003480 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3481 }
3482
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303483 if (mask)
3484 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3485
3486 DRM_DEBUG_KMS("Using vswing level %d\n",
3487 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3488 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3489 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3490 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003491
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003492 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003493
3494 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3495 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003496}
3497
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003498void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003499intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3500 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003501{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003502 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003503 struct drm_i915_private *dev_priv =
3504 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003505
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003506 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003507
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003508 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003509 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003510}
3511
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003512void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003513{
3514 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3515 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003516 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003517 enum port port = intel_dig_port->port;
3518 uint32_t val;
3519
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003520 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003521 return;
3522
3523 val = I915_READ(DP_TP_CTL(port));
3524 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3525 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3526 I915_WRITE(DP_TP_CTL(port), val);
3527
3528 /*
3529 * On PORT_A we can have only eDP in SST mode. There the only reason
3530 * we need to set idle transmission mode is to work around a HW issue
3531 * where we enable the pipe while not in idle link-training mode.
3532 * In this case there is requirement to wait for a minimum number of
3533 * idle patterns to be sent.
3534 */
3535 if (port == PORT_A)
3536 return;
3537
Chris Wilsona7670172016-06-30 15:33:10 +01003538 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3539 DP_TP_STATUS_IDLE_DONE,
3540 DP_TP_STATUS_IDLE_DONE,
3541 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003542 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3543}
3544
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003545static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003546intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003547{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003548 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003549 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003550 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003551 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003552 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003553 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003554
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003555 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003556 return;
3557
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003558 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003559 return;
3560
Zhao Yakui28c97732009-10-09 11:39:41 +08003561 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003562
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003563 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003564 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003565 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003566 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003567 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003568 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003569 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3570 else
3571 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003572 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003573 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003574 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003575 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003576
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003577 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3578 I915_WRITE(intel_dp->output_reg, DP);
3579 POSTING_READ(intel_dp->output_reg);
3580
3581 /*
3582 * HW workaround for IBX, we need to move the port
3583 * to transcoder A after disabling it to allow the
3584 * matching HDMI port to be enabled on transcoder A.
3585 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003586 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003587 /*
3588 * We get CPU/PCH FIFO underruns on the other pipe when
3589 * doing the workaround. Sweep them under the rug.
3590 */
3591 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3592 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3593
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003594 /* always enable with pattern 1 (as per spec) */
3595 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3596 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3597 I915_WRITE(intel_dp->output_reg, DP);
3598 POSTING_READ(intel_dp->output_reg);
3599
3600 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003601 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003602 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003603
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003604 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003605 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3606 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003607 }
3608
Keith Packardf01eca22011-09-28 16:48:10 -07003609 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003610
3611 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003612
3613 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3614 pps_lock(intel_dp);
3615 intel_dp->active_pipe = INVALID_PIPE;
3616 pps_unlock(intel_dp);
3617 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003618}
3619
Imre Deak24e807e2016-10-24 19:33:28 +03003620bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003621intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003622{
Lyude9f085eb2016-04-13 10:58:33 -04003623 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3624 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003625 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003626
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003627 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003628
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003629 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3630}
3631
3632static bool
3633intel_edp_init_dpcd(struct intel_dp *intel_dp)
3634{
3635 struct drm_i915_private *dev_priv =
3636 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3637
3638 /* this function is meant to be called only once */
3639 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3640
3641 if (!intel_dp_read_dpcd(intel_dp))
3642 return false;
3643
Imre Deak12a47a422016-10-24 19:33:29 +03003644 intel_dp_read_desc(intel_dp);
3645
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003646 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3647 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3648 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3649
3650 /* Check if the panel supports PSR */
3651 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3652 intel_dp->psr_dpcd,
3653 sizeof(intel_dp->psr_dpcd));
3654 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3655 dev_priv->psr.sink_support = true;
3656 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3657 }
3658
3659 if (INTEL_GEN(dev_priv) >= 9 &&
3660 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3661 uint8_t frame_sync_cap;
3662
3663 dev_priv->psr.sink_support = true;
Jani Nikula010b9b32017-04-06 16:44:16 +03003664 drm_dp_dpcd_readb(&intel_dp->aux,
3665 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3666 &frame_sync_cap);
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003667 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3668 /* PSR2 needs frame sync as well */
3669 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3670 DRM_DEBUG_KMS("PSR2 %s on sink",
3671 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303672
3673 if (dev_priv->psr.psr2_support) {
3674 dev_priv->psr.y_cord_support =
3675 intel_dp_get_y_cord_status(intel_dp);
3676 dev_priv->psr.colorimetry_support =
3677 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303678 dev_priv->psr.alpm =
3679 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303680 }
3681
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003682 }
3683
3684 /* Read the eDP Display control capabilities registers */
3685 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3686 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003687 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3688 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003689 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3690 intel_dp->edp_dpcd);
3691
3692 /* Intermediate frequency support */
3693 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3694 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3695 int i;
3696
3697 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3698 sink_rates, sizeof(sink_rates));
3699
3700 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3701 int val = le16_to_cpu(sink_rates[i]);
3702
3703 if (val == 0)
3704 break;
3705
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003706 /* Value read multiplied by 200kHz gives the per-lane
3707 * link rate in kHz. The source rates are, however,
3708 * stored in terms of LS_Clk kHz. The full conversion
3709 * back to symbols is
3710 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3711 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003712 intel_dp->sink_rates[i] = (val * 200) / 10;
3713 }
3714 intel_dp->num_sink_rates = i;
3715 }
3716
Jani Nikula68f357c2017-03-28 17:59:05 +03003717 if (intel_dp->num_sink_rates)
3718 intel_dp->use_rate_select = true;
3719 else
3720 intel_dp_set_sink_rates(intel_dp);
3721
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003722 intel_dp_set_common_rates(intel_dp);
3723
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003724 return true;
3725}
3726
3727
3728static bool
3729intel_dp_get_dpcd(struct intel_dp *intel_dp)
3730{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003731 u8 sink_count;
3732
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003733 if (!intel_dp_read_dpcd(intel_dp))
3734 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003735
Jani Nikula68f357c2017-03-28 17:59:05 +03003736 /* Don't clobber cached eDP rates. */
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003737 if (!is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003738 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003739 intel_dp_set_common_rates(intel_dp);
3740 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003741
Jani Nikula27dbefb2017-04-06 16:44:17 +03003742 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303743 return false;
3744
3745 /*
3746 * Sink count can change between short pulse hpd hence
3747 * a member variable in intel_dp will track any changes
3748 * between short pulse interrupts.
3749 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003750 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303751
3752 /*
3753 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3754 * a dongle is present but no display. Unless we require to know
3755 * if a dongle is present or not, we don't need to update
3756 * downstream port information. So, an early return here saves
3757 * time from performing other operations which are not required.
3758 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303759 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303760 return false;
3761
Imre Deakc726ad02016-10-24 19:33:24 +03003762 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003763 return true; /* native DP sink */
3764
3765 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3766 return true; /* no per-port downstream info */
3767
Lyude9f085eb2016-04-13 10:58:33 -04003768 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3769 intel_dp->downstream_ports,
3770 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003771 return false; /* downstream port status fetch failed */
3772
3773 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003774}
3775
Dave Airlie0e32b392014-05-02 14:02:48 +10003776static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003777intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003778{
Jani Nikula010b9b32017-04-06 16:44:16 +03003779 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003780
Nathan Schulte7cc96132016-03-15 10:14:05 -05003781 if (!i915.enable_dp_mst)
3782 return false;
3783
Dave Airlie0e32b392014-05-02 14:02:48 +10003784 if (!intel_dp->can_mst)
3785 return false;
3786
3787 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3788 return false;
3789
Jani Nikula010b9b32017-04-06 16:44:16 +03003790 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003791 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003792
Jani Nikula010b9b32017-04-06 16:44:16 +03003793 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003794}
3795
3796static void
3797intel_dp_configure_mst(struct intel_dp *intel_dp)
3798{
3799 if (!i915.enable_dp_mst)
3800 return;
3801
3802 if (!intel_dp->can_mst)
3803 return;
3804
3805 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3806
3807 if (intel_dp->is_mst)
3808 DRM_DEBUG_KMS("Sink is MST capable\n");
3809 else
3810 DRM_DEBUG_KMS("Sink is not MST capable\n");
3811
3812 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3813 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003814}
3815
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003816static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003817{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003818 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003819 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003820 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003821 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003822 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003823 int count = 0;
3824 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003825
3826 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003827 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003828 ret = -EIO;
3829 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003830 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003831
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003832 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003833 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003834 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003835 ret = -EIO;
3836 goto out;
3837 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003838
Rodrigo Vivic6297842015-11-05 10:50:20 -08003839 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003840 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003841
3842 if (drm_dp_dpcd_readb(&intel_dp->aux,
3843 DP_TEST_SINK_MISC, &buf) < 0) {
3844 ret = -EIO;
3845 goto out;
3846 }
3847 count = buf & DP_TEST_COUNT_MASK;
3848 } while (--attempts && count);
3849
3850 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003851 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003852 ret = -ETIMEDOUT;
3853 }
3854
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003855 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003856 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003857 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003858}
3859
3860static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3861{
3862 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003863 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003864 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3865 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003866 int ret;
3867
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003868 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3869 return -EIO;
3870
3871 if (!(buf & DP_TEST_CRC_SUPPORTED))
3872 return -ENOTTY;
3873
3874 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3875 return -EIO;
3876
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003877 if (buf & DP_TEST_SINK_START) {
3878 ret = intel_dp_sink_crc_stop(intel_dp);
3879 if (ret)
3880 return ret;
3881 }
3882
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003883 hsw_disable_ips(intel_crtc);
3884
3885 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3886 buf | DP_TEST_SINK_START) < 0) {
3887 hsw_enable_ips(intel_crtc);
3888 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003889 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003890
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003891 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003892 return 0;
3893}
3894
3895int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3896{
3897 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003898 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003899 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3900 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003901 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003902 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003903
3904 ret = intel_dp_sink_crc_start(intel_dp);
3905 if (ret)
3906 return ret;
3907
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003908 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003909 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003910
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003911 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003912 DP_TEST_SINK_MISC, &buf) < 0) {
3913 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003914 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003915 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003916 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003917
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003918 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003919
3920 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003921 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3922 ret = -ETIMEDOUT;
3923 goto stop;
3924 }
3925
3926 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3927 ret = -EIO;
3928 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003929 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003930
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003931stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003932 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003933 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003934}
3935
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003936static bool
3937intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3938{
Jani Nikula010b9b32017-04-06 16:44:16 +03003939 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3940 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003941}
3942
Dave Airlie0e32b392014-05-02 14:02:48 +10003943static bool
3944intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3945{
3946 int ret;
3947
Lyude9f085eb2016-04-13 10:58:33 -04003948 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003949 DP_SINK_COUNT_ESI,
3950 sink_irq_vector, 14);
3951 if (ret != 14)
3952 return false;
3953
3954 return true;
3955}
3956
Todd Previtec5d5ab72015-04-15 08:38:38 -07003957static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003958{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003959 int status = 0;
3960 int min_lane_count = 1;
Manasi Navareda15f7c2017-01-24 08:16:34 -08003961 int link_rate_index, test_link_rate;
3962 uint8_t test_lane_count, test_link_bw;
3963 /* (DP CTS 1.2)
3964 * 4.3.1.11
3965 */
3966 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3967 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3968 &test_lane_count);
3969
3970 if (status <= 0) {
3971 DRM_DEBUG_KMS("Lane count read failed\n");
3972 return DP_TEST_NAK;
3973 }
3974 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3975 /* Validate the requested lane count */
3976 if (test_lane_count < min_lane_count ||
Jani Nikulae6c0c642017-04-06 16:44:12 +03003977 test_lane_count > intel_dp->max_link_lane_count)
Manasi Navareda15f7c2017-01-24 08:16:34 -08003978 return DP_TEST_NAK;
3979
3980 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3981 &test_link_bw);
3982 if (status <= 0) {
3983 DRM_DEBUG_KMS("Link Rate read failed\n");
3984 return DP_TEST_NAK;
3985 }
3986 /* Validate the requested link rate */
3987 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Jani Nikulab1810a72017-04-06 16:44:11 +03003988 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
3989 intel_dp->num_common_rates,
3990 test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08003991 if (link_rate_index < 0)
3992 return DP_TEST_NAK;
3993
3994 intel_dp->compliance.test_lane_count = test_lane_count;
3995 intel_dp->compliance.test_link_rate = test_link_rate;
3996
3997 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003998}
3999
4000static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4001{
Manasi Navare611032b2017-01-24 08:21:49 -08004002 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004003 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004004 __be16 h_width, v_height;
4005 int status = 0;
4006
4007 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004008 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4009 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004010 if (status <= 0) {
4011 DRM_DEBUG_KMS("Test pattern read failed\n");
4012 return DP_TEST_NAK;
4013 }
4014 if (test_pattern != DP_COLOR_RAMP)
4015 return DP_TEST_NAK;
4016
4017 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4018 &h_width, 2);
4019 if (status <= 0) {
4020 DRM_DEBUG_KMS("H Width read failed\n");
4021 return DP_TEST_NAK;
4022 }
4023
4024 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4025 &v_height, 2);
4026 if (status <= 0) {
4027 DRM_DEBUG_KMS("V Height read failed\n");
4028 return DP_TEST_NAK;
4029 }
4030
Jani Nikula010b9b32017-04-06 16:44:16 +03004031 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4032 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004033 if (status <= 0) {
4034 DRM_DEBUG_KMS("TEST MISC read failed\n");
4035 return DP_TEST_NAK;
4036 }
4037 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4038 return DP_TEST_NAK;
4039 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4040 return DP_TEST_NAK;
4041 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4042 case DP_TEST_BIT_DEPTH_6:
4043 intel_dp->compliance.test_data.bpc = 6;
4044 break;
4045 case DP_TEST_BIT_DEPTH_8:
4046 intel_dp->compliance.test_data.bpc = 8;
4047 break;
4048 default:
4049 return DP_TEST_NAK;
4050 }
4051
4052 intel_dp->compliance.test_data.video_pattern = test_pattern;
4053 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4054 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4055 /* Set test active flag here so userspace doesn't interrupt things */
4056 intel_dp->compliance.test_active = 1;
4057
4058 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004059}
4060
4061static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4062{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004063 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004064 struct intel_connector *intel_connector = intel_dp->attached_connector;
4065 struct drm_connector *connector = &intel_connector->base;
4066
4067 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004068 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004069 intel_dp->aux.i2c_defer_count > 6) {
4070 /* Check EDID read for NACKs, DEFERs and corruption
4071 * (DP CTS 1.2 Core r1.1)
4072 * 4.2.2.4 : Failed EDID read, I2C_NAK
4073 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4074 * 4.2.2.6 : EDID corruption detected
4075 * Use failsafe mode for all cases
4076 */
4077 if (intel_dp->aux.i2c_nack_count > 0 ||
4078 intel_dp->aux.i2c_defer_count > 0)
4079 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4080 intel_dp->aux.i2c_nack_count,
4081 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004082 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004083 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304084 struct edid *block = intel_connector->detect_edid;
4085
4086 /* We have to write the checksum
4087 * of the last block read
4088 */
4089 block += intel_connector->detect_edid->extensions;
4090
Jani Nikula010b9b32017-04-06 16:44:16 +03004091 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4092 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004093 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4094
4095 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004096 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004097 }
4098
4099 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004100 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004101
Todd Previtec5d5ab72015-04-15 08:38:38 -07004102 return test_result;
4103}
4104
4105static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4106{
4107 uint8_t test_result = DP_TEST_NAK;
4108 return test_result;
4109}
4110
4111static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4112{
4113 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004114 uint8_t request = 0;
4115 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004116
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004117 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004118 if (status <= 0) {
4119 DRM_DEBUG_KMS("Could not read test request from sink\n");
4120 goto update_status;
4121 }
4122
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004123 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004124 case DP_TEST_LINK_TRAINING:
4125 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004126 response = intel_dp_autotest_link_training(intel_dp);
4127 break;
4128 case DP_TEST_LINK_VIDEO_PATTERN:
4129 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004130 response = intel_dp_autotest_video_pattern(intel_dp);
4131 break;
4132 case DP_TEST_LINK_EDID_READ:
4133 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004134 response = intel_dp_autotest_edid(intel_dp);
4135 break;
4136 case DP_TEST_LINK_PHY_TEST_PATTERN:
4137 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004138 response = intel_dp_autotest_phy_pattern(intel_dp);
4139 break;
4140 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004141 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004142 break;
4143 }
4144
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004145 if (response & DP_TEST_ACK)
4146 intel_dp->compliance.test_type = request;
4147
Todd Previtec5d5ab72015-04-15 08:38:38 -07004148update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004149 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004150 if (status <= 0)
4151 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004152}
4153
Dave Airlie0e32b392014-05-02 14:02:48 +10004154static int
4155intel_dp_check_mst_status(struct intel_dp *intel_dp)
4156{
4157 bool bret;
4158
4159 if (intel_dp->is_mst) {
4160 u8 esi[16] = { 0 };
4161 int ret = 0;
4162 int retry;
4163 bool handled;
4164 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4165go_again:
4166 if (bret == true) {
4167
4168 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004169 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004170 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004171 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4172 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004173 intel_dp_stop_link_train(intel_dp);
4174 }
4175
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004176 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004177 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4178
4179 if (handled) {
4180 for (retry = 0; retry < 3; retry++) {
4181 int wret;
4182 wret = drm_dp_dpcd_write(&intel_dp->aux,
4183 DP_SINK_COUNT_ESI+1,
4184 &esi[1], 3);
4185 if (wret == 3) {
4186 break;
4187 }
4188 }
4189
4190 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4191 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004192 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004193 goto go_again;
4194 }
4195 } else
4196 ret = 0;
4197
4198 return ret;
4199 } else {
4200 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4201 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4202 intel_dp->is_mst = false;
4203 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4204 /* send a hotplug event */
4205 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4206 }
4207 }
4208 return -EINVAL;
4209}
4210
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304211static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004212intel_dp_retrain_link(struct intel_dp *intel_dp)
4213{
4214 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4215 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4216 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4217
4218 /* Suppress underruns caused by re-training */
4219 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4220 if (crtc->config->has_pch_encoder)
4221 intel_set_pch_fifo_underrun_reporting(dev_priv,
4222 intel_crtc_pch_transcoder(crtc), false);
4223
4224 intel_dp_start_link_train(intel_dp);
4225 intel_dp_stop_link_train(intel_dp);
4226
4227 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004228 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004229
4230 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4231 if (crtc->config->has_pch_encoder)
4232 intel_set_pch_fifo_underrun_reporting(dev_priv,
4233 intel_crtc_pch_transcoder(crtc), true);
4234}
4235
4236static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304237intel_dp_check_link_status(struct intel_dp *intel_dp)
4238{
4239 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4240 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4241 u8 link_status[DP_LINK_STATUS_SIZE];
4242
4243 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4244
4245 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4246 DRM_ERROR("Failed to get link status\n");
4247 return;
4248 }
4249
4250 if (!intel_encoder->base.crtc)
4251 return;
4252
4253 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4254 return;
4255
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004256 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004257 * readout. Currently fast link training doesn't work on boot-up. */
4258 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004259 return;
4260
Manasi Navareda15f7c2017-01-24 08:16:34 -08004261 /* Retrain if Channel EQ or CR not ok */
4262 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304263 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4264 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004265
4266 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304267 }
4268}
4269
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004270/*
4271 * According to DP spec
4272 * 5.1.2:
4273 * 1. Read DPCD
4274 * 2. Configure link according to Receiver Capabilities
4275 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4276 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304277 *
4278 * intel_dp_short_pulse - handles short pulse interrupts
4279 * when full detection is not required.
4280 * Returns %true if short pulse is handled and full detection
4281 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004282 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304283static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304284intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004285{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004286 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004287 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004288 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304289 u8 old_sink_count = intel_dp->sink_count;
4290 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004291
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304292 /*
4293 * Clearing compliance test variables to allow capturing
4294 * of values for next automated test request.
4295 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004296 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304297
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304298 /*
4299 * Now read the DPCD to see if it's actually running
4300 * If the current value of sink count doesn't match with
4301 * the value that was stored earlier or dpcd read failed
4302 * we need to do full detection
4303 */
4304 ret = intel_dp_get_dpcd(intel_dp);
4305
4306 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4307 /* No need to proceed if we are going to do full detect */
4308 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004309 }
4310
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004311 /* Try to read the source of the interrupt */
4312 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004313 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4314 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004315 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004316 drm_dp_dpcd_writeb(&intel_dp->aux,
4317 DP_DEVICE_SERVICE_IRQ_VECTOR,
4318 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004319
4320 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004321 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004322 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4323 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4324 }
4325
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304326 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4327 intel_dp_check_link_status(intel_dp);
4328 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004329 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4330 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4331 /* Send a Hotplug Uevent to userspace to start modeset */
4332 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4333 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304334
4335 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004336}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004337
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004338/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004339static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004340intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004341{
Imre Deake393d0d2017-02-22 17:10:52 +02004342 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004343 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004344 uint8_t type;
4345
Imre Deake393d0d2017-02-22 17:10:52 +02004346 if (lspcon->active)
4347 lspcon_resume(lspcon);
4348
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004349 if (!intel_dp_get_dpcd(intel_dp))
4350 return connector_status_disconnected;
4351
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304352 if (is_edp(intel_dp))
4353 return connector_status_connected;
4354
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004355 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004356 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004357 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004358
4359 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004360 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4361 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004362
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304363 return intel_dp->sink_count ?
4364 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004365 }
4366
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004367 if (intel_dp_can_mst(intel_dp))
4368 return connector_status_connected;
4369
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004370 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004371 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004372 return connector_status_connected;
4373
4374 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004375 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4376 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4377 if (type == DP_DS_PORT_TYPE_VGA ||
4378 type == DP_DS_PORT_TYPE_NON_EDID)
4379 return connector_status_unknown;
4380 } else {
4381 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4382 DP_DWN_STRM_PORT_TYPE_MASK;
4383 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4384 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4385 return connector_status_unknown;
4386 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004387
4388 /* Anything else is out of spec, warn and ignore */
4389 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004390 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004391}
4392
4393static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004394edp_detect(struct intel_dp *intel_dp)
4395{
4396 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004397 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004398 enum drm_connector_status status;
4399
Mika Kahola1650be72016-12-13 10:02:47 +02004400 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004401 if (status == connector_status_unknown)
4402 status = connector_status_connected;
4403
4404 return status;
4405}
4406
Jani Nikulab93433c2015-08-20 10:47:36 +03004407static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4408 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004409{
Jani Nikulab93433c2015-08-20 10:47:36 +03004410 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004411
Jani Nikula0df53b72015-08-20 10:47:40 +03004412 switch (port->port) {
4413 case PORT_A:
4414 return true;
4415 case PORT_B:
4416 bit = SDE_PORTB_HOTPLUG;
4417 break;
4418 case PORT_C:
4419 bit = SDE_PORTC_HOTPLUG;
4420 break;
4421 case PORT_D:
4422 bit = SDE_PORTD_HOTPLUG;
4423 break;
4424 default:
4425 MISSING_CASE(port->port);
4426 return false;
4427 }
4428
4429 return I915_READ(SDEISR) & bit;
4430}
4431
4432static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4433 struct intel_digital_port *port)
4434{
4435 u32 bit;
4436
4437 switch (port->port) {
4438 case PORT_A:
4439 return true;
4440 case PORT_B:
4441 bit = SDE_PORTB_HOTPLUG_CPT;
4442 break;
4443 case PORT_C:
4444 bit = SDE_PORTC_HOTPLUG_CPT;
4445 break;
4446 case PORT_D:
4447 bit = SDE_PORTD_HOTPLUG_CPT;
4448 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004449 case PORT_E:
4450 bit = SDE_PORTE_HOTPLUG_SPT;
4451 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004452 default:
4453 MISSING_CASE(port->port);
4454 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004455 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004456
Jani Nikulab93433c2015-08-20 10:47:36 +03004457 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004458}
4459
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004460static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004461 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004462{
Jani Nikula9642c812015-08-20 10:47:41 +03004463 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004464
Jani Nikula9642c812015-08-20 10:47:41 +03004465 switch (port->port) {
4466 case PORT_B:
4467 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4468 break;
4469 case PORT_C:
4470 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4471 break;
4472 case PORT_D:
4473 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4474 break;
4475 default:
4476 MISSING_CASE(port->port);
4477 return false;
4478 }
4479
4480 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4481}
4482
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004483static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4484 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004485{
4486 u32 bit;
4487
4488 switch (port->port) {
4489 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004490 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004491 break;
4492 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004493 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004494 break;
4495 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004496 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004497 break;
4498 default:
4499 MISSING_CASE(port->port);
4500 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004501 }
4502
Jani Nikula1d245982015-08-20 10:47:37 +03004503 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004504}
4505
Jani Nikulae464bfd2015-08-20 10:47:42 +03004506static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304507 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004508{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304509 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4510 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004511 u32 bit;
4512
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304513 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4514 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004515 case PORT_A:
4516 bit = BXT_DE_PORT_HP_DDIA;
4517 break;
4518 case PORT_B:
4519 bit = BXT_DE_PORT_HP_DDIB;
4520 break;
4521 case PORT_C:
4522 bit = BXT_DE_PORT_HP_DDIC;
4523 break;
4524 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304525 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004526 return false;
4527 }
4528
4529 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4530}
4531
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004532/*
4533 * intel_digital_port_connected - is the specified port connected?
4534 * @dev_priv: i915 private structure
4535 * @port: the port to test
4536 *
4537 * Return %true if @port is connected, %false otherwise.
4538 */
Imre Deak390b4e02017-01-27 11:39:19 +02004539bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4540 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004541{
Jani Nikula0df53b72015-08-20 10:47:40 +03004542 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004543 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004544 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004545 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004546 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004547 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004548 else if (IS_GM45(dev_priv))
4549 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004550 else
4551 return g4x_digital_port_connected(dev_priv, port);
4552}
4553
Keith Packard8c241fe2011-09-28 16:38:44 -07004554static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004555intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004556{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004557 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004558
Jani Nikula9cd300e2012-10-19 14:51:52 +03004559 /* use cached edid if we have one */
4560 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004561 /* invalid edid */
4562 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004563 return NULL;
4564
Jani Nikula55e9ede2013-10-01 10:38:54 +03004565 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004566 } else
4567 return drm_get_edid(&intel_connector->base,
4568 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004569}
4570
Chris Wilsonbeb60602014-09-02 20:04:00 +01004571static void
4572intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004573{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004574 struct intel_connector *intel_connector = intel_dp->attached_connector;
4575 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004576
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304577 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004578 edid = intel_dp_get_edid(intel_dp);
4579 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004580
Chris Wilsonbeb60602014-09-02 20:04:00 +01004581 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4582 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4583 else
4584 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4585}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004586
Chris Wilsonbeb60602014-09-02 20:04:00 +01004587static void
4588intel_dp_unset_edid(struct intel_dp *intel_dp)
4589{
4590 struct intel_connector *intel_connector = intel_dp->attached_connector;
4591
4592 kfree(intel_connector->detect_edid);
4593 intel_connector->detect_edid = NULL;
4594
4595 intel_dp->has_audio = false;
4596}
4597
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004598static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304599intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004600{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304601 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004602 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004603 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4604 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004605 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004606 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004607 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004608
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004609 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4610
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004611 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004612
Chris Wilsond410b562014-09-02 20:03:59 +01004613 /* Can't disconnect eDP, but you can close the lid... */
4614 if (is_edp(intel_dp))
4615 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004616 else if (intel_digital_port_connected(to_i915(dev),
4617 dp_to_dig_port(intel_dp)))
4618 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004619 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004620 status = connector_status_disconnected;
4621
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004622 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004623 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304624
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004625 if (intel_dp->is_mst) {
4626 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4627 intel_dp->is_mst,
4628 intel_dp->mst_mgr.mst_state);
4629 intel_dp->is_mst = false;
4630 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4631 intel_dp->is_mst);
4632 }
4633
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004634 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304635 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004636
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304637 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004638 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304639
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004640 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4641 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4642 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4643
Manasi Navared7e8ef02017-02-07 16:54:11 -08004644 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004645 /* Initial max link lane count */
4646 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004647
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004648 /* Initial max link rate */
4649 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004650
4651 intel_dp->reset_link_params = false;
4652 }
Manasi Navaref4829842016-12-05 16:27:36 -08004653
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004654 intel_dp_print_rates(intel_dp);
4655
Imre Deak7b3fc172016-10-25 16:12:39 +03004656 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004657
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004658 intel_dp_configure_mst(intel_dp);
4659
4660 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304661 /*
4662 * If we are in MST mode then this connector
4663 * won't appear connected or have anything
4664 * with EDID on it
4665 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004666 status = connector_status_disconnected;
4667 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304668 } else if (connector->status == connector_status_connected) {
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304669 intel_dp_check_link_status(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304670 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004671 }
4672
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304673 /*
4674 * Clearing NACK and defer counts to get their exact values
4675 * while reading EDID which are required by Compliance tests
4676 * 4.2.2.4 and 4.2.2.5
4677 */
4678 intel_dp->aux.i2c_nack_count = 0;
4679 intel_dp->aux.i2c_defer_count = 0;
4680
Chris Wilsonbeb60602014-09-02 20:04:00 +01004681 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004682 if (is_edp(intel_dp) || intel_connector->detect_edid)
4683 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304684 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004685
Todd Previte09b1eb12015-04-20 15:27:34 -07004686 /* Try to read the source of the interrupt */
4687 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004688 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4689 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004690 /* Clear interrupt source */
4691 drm_dp_dpcd_writeb(&intel_dp->aux,
4692 DP_DEVICE_SERVICE_IRQ_VECTOR,
4693 sink_irq_vector);
4694
4695 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4696 intel_dp_handle_test_request(intel_dp);
4697 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4698 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4699 }
4700
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004701out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004702 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304703 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304704
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004705 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004706 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304707}
4708
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004709static int
4710intel_dp_detect(struct drm_connector *connector,
4711 struct drm_modeset_acquire_ctx *ctx,
4712 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304713{
4714 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004715 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304716
4717 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4718 connector->base.id, connector->name);
4719
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304720 /* If full detect is not performed yet, do a full detect */
4721 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004722 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304723
4724 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304725
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004726 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004727}
4728
Chris Wilsonbeb60602014-09-02 20:04:00 +01004729static void
4730intel_dp_force(struct drm_connector *connector)
4731{
4732 struct intel_dp *intel_dp = intel_attached_dp(connector);
4733 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004734 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004735
4736 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4737 connector->base.id, connector->name);
4738 intel_dp_unset_edid(intel_dp);
4739
4740 if (connector->status != connector_status_connected)
4741 return;
4742
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004743 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004744
4745 intel_dp_set_edid(intel_dp);
4746
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004747 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004748
4749 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004750 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004751}
4752
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004753static int intel_dp_get_modes(struct drm_connector *connector)
4754{
Jani Nikuladd06f902012-10-19 14:51:50 +03004755 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004756 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004757
Chris Wilsonbeb60602014-09-02 20:04:00 +01004758 edid = intel_connector->detect_edid;
4759 if (edid) {
4760 int ret = intel_connector_update_modes(connector, edid);
4761 if (ret)
4762 return ret;
4763 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004764
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004765 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004766 if (is_edp(intel_attached_dp(connector)) &&
4767 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004768 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004769
4770 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004771 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004772 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004773 drm_mode_probed_add(connector, mode);
4774 return 1;
4775 }
4776 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004777
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004778 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004779}
4780
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004781static bool
4782intel_dp_detect_audio(struct drm_connector *connector)
4783{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004784 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004785 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004786
Chris Wilsonbeb60602014-09-02 20:04:00 +01004787 edid = to_intel_connector(connector)->detect_edid;
4788 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004789 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004790
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004791 return has_audio;
4792}
4793
Chris Wilsonf6849602010-09-19 09:29:33 +01004794static int
4795intel_dp_set_property(struct drm_connector *connector,
4796 struct drm_property *property,
4797 uint64_t val)
4798{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004799 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004800 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004801 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4802 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004803 int ret;
4804
Rob Clark662595d2012-10-11 20:36:04 -05004805 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004806 if (ret)
4807 return ret;
4808
Chris Wilson3f43c482011-05-12 22:17:24 +01004809 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004810 int i = val;
4811 bool has_audio;
4812
4813 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004814 return 0;
4815
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004816 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004817
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004818 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004819 has_audio = intel_dp_detect_audio(connector);
4820 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004821 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004822
4823 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004824 return 0;
4825
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004826 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004827 goto done;
4828 }
4829
Chris Wilsone953fd72011-02-21 22:23:52 +00004830 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004831 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004832 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004833
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004834 switch (val) {
4835 case INTEL_BROADCAST_RGB_AUTO:
4836 intel_dp->color_range_auto = true;
4837 break;
4838 case INTEL_BROADCAST_RGB_FULL:
4839 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004840 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004841 break;
4842 case INTEL_BROADCAST_RGB_LIMITED:
4843 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004844 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004845 break;
4846 default:
4847 return -EINVAL;
4848 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004849
4850 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004851 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004852 return 0;
4853
Chris Wilsone953fd72011-02-21 22:23:52 +00004854 goto done;
4855 }
4856
Yuly Novikov53b41832012-10-26 12:04:00 +03004857 if (is_edp(intel_dp) &&
4858 property == connector->dev->mode_config.scaling_mode_property) {
4859 if (val == DRM_MODE_SCALE_NONE) {
4860 DRM_DEBUG_KMS("no scaling not supported\n");
4861 return -EINVAL;
4862 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004863 if (HAS_GMCH_DISPLAY(dev_priv) &&
4864 val == DRM_MODE_SCALE_CENTER) {
4865 DRM_DEBUG_KMS("centering not supported\n");
4866 return -EINVAL;
4867 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004868
4869 if (intel_connector->panel.fitting_mode == val) {
4870 /* the eDP scaling property is not changed */
4871 return 0;
4872 }
4873 intel_connector->panel.fitting_mode = val;
4874
4875 goto done;
4876 }
4877
Chris Wilsonf6849602010-09-19 09:29:33 +01004878 return -EINVAL;
4879
4880done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004881 if (intel_encoder->base.crtc)
4882 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004883
4884 return 0;
4885}
4886
Chris Wilson7a418e32016-06-24 14:00:14 +01004887static int
4888intel_dp_connector_register(struct drm_connector *connector)
4889{
4890 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004891 int ret;
4892
4893 ret = intel_connector_register(connector);
4894 if (ret)
4895 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004896
4897 i915_debugfs_connector_add(connector);
4898
4899 DRM_DEBUG_KMS("registering %s bus for %s\n",
4900 intel_dp->aux.name, connector->kdev->kobj.name);
4901
4902 intel_dp->aux.dev = connector->kdev;
4903 return drm_dp_aux_register(&intel_dp->aux);
4904}
4905
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004906static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004907intel_dp_connector_unregister(struct drm_connector *connector)
4908{
4909 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4910 intel_connector_unregister(connector);
4911}
4912
4913static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004914intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004915{
Jani Nikula1d508702012-10-19 14:51:49 +03004916 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004917
Chris Wilson10e972d2014-09-04 21:43:45 +01004918 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004919
Jani Nikula9cd300e2012-10-19 14:51:52 +03004920 if (!IS_ERR_OR_NULL(intel_connector->edid))
4921 kfree(intel_connector->edid);
4922
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004923 /* Can't call is_edp() since the encoder may have been destroyed
4924 * already. */
4925 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004926 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004927
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004928 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004929 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004930}
4931
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004932void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004933{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004934 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4935 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004936
Dave Airlie0e32b392014-05-02 14:02:48 +10004937 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004938 if (is_edp(intel_dp)) {
4939 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004940 /*
4941 * vdd might still be enabled do to the delayed vdd off.
4942 * Make sure vdd is actually turned off here.
4943 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004944 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004945 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004946 pps_unlock(intel_dp);
4947
Clint Taylor01527b32014-07-07 13:01:46 -07004948 if (intel_dp->edp_notifier.notifier_call) {
4949 unregister_reboot_notifier(&intel_dp->edp_notifier);
4950 intel_dp->edp_notifier.notifier_call = NULL;
4951 }
Keith Packardbd943152011-09-18 23:09:52 -07004952 }
Chris Wilson99681882016-06-20 09:29:17 +01004953
4954 intel_dp_aux_fini(intel_dp);
4955
Imre Deakc8bd0e42014-12-12 17:57:38 +02004956 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004957 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004958}
4959
Imre Deakbf93ba62016-04-18 10:04:21 +03004960void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004961{
4962 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4963
4964 if (!is_edp(intel_dp))
4965 return;
4966
Ville Syrjälä951468f2014-09-04 14:55:31 +03004967 /*
4968 * vdd might still be enabled do to the delayed vdd off.
4969 * Make sure vdd is actually turned off here.
4970 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004971 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004972 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004973 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004974 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004975}
4976
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004977static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4978{
4979 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4980 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004981 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004982
4983 lockdep_assert_held(&dev_priv->pps_mutex);
4984
4985 if (!edp_have_panel_vdd(intel_dp))
4986 return;
4987
4988 /*
4989 * The VDD bit needs a power domain reference, so if the bit is
4990 * already enabled when we boot or resume, grab this reference and
4991 * schedule a vdd off, so we don't hold on to the reference
4992 * indefinitely.
4993 */
4994 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004995 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004996
4997 edp_panel_vdd_schedule_off(intel_dp);
4998}
4999
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005000static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5001{
5002 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5003
5004 if ((intel_dp->DP & DP_PORT_EN) == 0)
5005 return INVALID_PIPE;
5006
5007 if (IS_CHERRYVIEW(dev_priv))
5008 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5009 else
5010 return PORT_TO_PIPE(intel_dp->DP);
5011}
5012
Imre Deakbf93ba62016-04-18 10:04:21 +03005013void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005014{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005015 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005016 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5017 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005018
5019 if (!HAS_DDI(dev_priv))
5020 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005021
Imre Deakdd75f6d2016-11-21 21:15:05 +02005022 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305023 lspcon_resume(lspcon);
5024
Manasi Navared7e8ef02017-02-07 16:54:11 -08005025 intel_dp->reset_link_params = true;
5026
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005027 pps_lock(intel_dp);
5028
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005029 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5030 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5031
5032 if (is_edp(intel_dp)) {
5033 /* Reinit the power sequencer, in case BIOS did something with it. */
5034 intel_dp_pps_init(encoder->dev, intel_dp);
5035 intel_edp_panel_vdd_sanitize(intel_dp);
5036 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005037
5038 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005039}
5040
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005041static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005042 .dpms = drm_atomic_helper_connector_dpms,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005043 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005044 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005045 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005046 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005047 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005048 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005049 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005050 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005051 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005052};
5053
5054static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005055 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005056 .get_modes = intel_dp_get_modes,
5057 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005058};
5059
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005060static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005061 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005062 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005063};
5064
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005065enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005066intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5067{
5068 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005069 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005070 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005071 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005072
Takashi Iwai25400582015-11-19 12:09:56 +01005073 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5074 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005075 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005076
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005077 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5078 /*
5079 * vdd off can generate a long pulse on eDP which
5080 * would require vdd on to handle it, and thus we
5081 * would end up in an endless cycle of
5082 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5083 */
5084 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5085 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005086 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005087 }
5088
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005089 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5090 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005091 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005092
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005093 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005094 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005095 intel_dp->detect_done = false;
5096 return IRQ_NONE;
5097 }
5098
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005099 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005100
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005101 if (intel_dp->is_mst) {
5102 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5103 /*
5104 * If we were in MST mode, and device is not
5105 * there, get out of MST mode
5106 */
5107 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5108 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5109 intel_dp->is_mst = false;
5110 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5111 intel_dp->is_mst);
5112 intel_dp->detect_done = false;
5113 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005114 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005115 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005116
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005117 if (!intel_dp->is_mst) {
5118 if (!intel_dp_short_pulse(intel_dp)) {
5119 intel_dp->detect_done = false;
5120 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305121 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005122 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005123
5124 ret = IRQ_HANDLED;
5125
Imre Deak1c767b32014-08-18 14:42:42 +03005126put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005127 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005128
5129 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005130}
5131
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005132/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005133bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005134{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005135 /*
5136 * eDP not supported on g4x. so bail out early just
5137 * for a bit extra safety in case the VBT is bonkers.
5138 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005139 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005140 return false;
5141
Imre Deaka98d9c12016-12-21 12:17:24 +02005142 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005143 return true;
5144
Jani Nikula951d9ef2016-03-16 12:43:31 +02005145 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005146}
5147
Dave Airlie0e32b392014-05-02 14:02:48 +10005148void
Chris Wilsonf6849602010-09-19 09:29:33 +01005149intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5150{
Yuly Novikov53b41832012-10-26 12:04:00 +03005151 struct intel_connector *intel_connector = to_intel_connector(connector);
5152
Chris Wilson3f43c482011-05-12 22:17:24 +01005153 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005154 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005155 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005156
5157 if (is_edp(intel_dp)) {
5158 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005159 drm_object_attach_property(
5160 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005161 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005162 DRM_MODE_SCALE_ASPECT);
5163 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005164 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005165}
5166
Imre Deakdada1a92014-01-29 13:25:41 +02005167static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5168{
Abhay Kumard28d4732016-01-22 17:39:04 -08005169 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005170 intel_dp->last_power_on = jiffies;
5171 intel_dp->last_backlight_off = jiffies;
5172}
5173
Daniel Vetter67a54562012-10-20 20:57:45 +02005174static void
Imre Deak54648612016-06-16 16:37:22 +03005175intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5176 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005177{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305178 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005179 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005180
Imre Deak8e8232d2016-06-16 16:37:21 +03005181 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005182
5183 /* Workaround: Need to write PP_CONTROL with the unlock key as
5184 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305185 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005186
Imre Deak8e8232d2016-06-16 16:37:21 +03005187 pp_on = I915_READ(regs.pp_on);
5188 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005189 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005190 I915_WRITE(regs.pp_ctrl, pp_ctl);
5191 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305192 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005193
5194 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005195 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5196 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005197
Imre Deak54648612016-06-16 16:37:22 +03005198 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5199 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005200
Imre Deak54648612016-06-16 16:37:22 +03005201 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5202 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005203
Imre Deak54648612016-06-16 16:37:22 +03005204 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5205 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005206
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005207 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305208 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5209 BXT_POWER_CYCLE_DELAY_SHIFT;
5210 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005211 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305212 else
Imre Deak54648612016-06-16 16:37:22 +03005213 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305214 } else {
Imre Deak54648612016-06-16 16:37:22 +03005215 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005216 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305217 }
Imre Deak54648612016-06-16 16:37:22 +03005218}
5219
5220static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005221intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5222{
5223 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5224 state_name,
5225 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5226}
5227
5228static void
5229intel_pps_verify_state(struct drm_i915_private *dev_priv,
5230 struct intel_dp *intel_dp)
5231{
5232 struct edp_power_seq hw;
5233 struct edp_power_seq *sw = &intel_dp->pps_delays;
5234
5235 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5236
5237 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5238 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5239 DRM_ERROR("PPS state mismatch\n");
5240 intel_pps_dump_state("sw", sw);
5241 intel_pps_dump_state("hw", &hw);
5242 }
5243}
5244
5245static void
Imre Deak54648612016-06-16 16:37:22 +03005246intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5247 struct intel_dp *intel_dp)
5248{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005249 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005250 struct edp_power_seq cur, vbt, spec,
5251 *final = &intel_dp->pps_delays;
5252
5253 lockdep_assert_held(&dev_priv->pps_mutex);
5254
5255 /* already initialized? */
5256 if (final->t11_t12 != 0)
5257 return;
5258
5259 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005260
Imre Deakde9c1b62016-06-16 20:01:46 +03005261 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005262
Jani Nikula6aa23e62016-03-24 17:50:20 +02005263 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005264
5265 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5266 * our hw here, which are all in 100usec. */
5267 spec.t1_t3 = 210 * 10;
5268 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5269 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5270 spec.t10 = 500 * 10;
5271 /* This one is special and actually in units of 100ms, but zero
5272 * based in the hw (so we need to add 100 ms). But the sw vbt
5273 * table multiplies it with 1000 to make it in units of 100usec,
5274 * too. */
5275 spec.t11_t12 = (510 + 100) * 10;
5276
Imre Deakde9c1b62016-06-16 20:01:46 +03005277 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005278
5279 /* Use the max of the register settings and vbt. If both are
5280 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005281#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005282 spec.field : \
5283 max(cur.field, vbt.field))
5284 assign_final(t1_t3);
5285 assign_final(t8);
5286 assign_final(t9);
5287 assign_final(t10);
5288 assign_final(t11_t12);
5289#undef assign_final
5290
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005291#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005292 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5293 intel_dp->backlight_on_delay = get_delay(t8);
5294 intel_dp->backlight_off_delay = get_delay(t9);
5295 intel_dp->panel_power_down_delay = get_delay(t10);
5296 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5297#undef get_delay
5298
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005299 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5300 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5301 intel_dp->panel_power_cycle_delay);
5302
5303 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5304 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005305
5306 /*
5307 * We override the HW backlight delays to 1 because we do manual waits
5308 * on them. For T8, even BSpec recommends doing it. For T9, if we
5309 * don't do this, we'll end up waiting for the backlight off delay
5310 * twice: once when we do the manual sleep, and once when we disable
5311 * the panel and wait for the PP_STATUS bit to become zero.
5312 */
5313 final->t8 = 1;
5314 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005315}
5316
5317static void
5318intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005319 struct intel_dp *intel_dp,
5320 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005321{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005322 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005323 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005324 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005325 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005326 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005327 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005328
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005329 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005330
Imre Deak8e8232d2016-06-16 16:37:21 +03005331 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005332
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005333 /*
5334 * On some VLV machines the BIOS can leave the VDD
5335 * enabled even on power seqeuencers which aren't
5336 * hooked up to any port. This would mess up the
5337 * power domain tracking the first time we pick
5338 * one of these power sequencers for use since
5339 * edp_panel_vdd_on() would notice that the VDD was
5340 * already on and therefore wouldn't grab the power
5341 * domain reference. Disable VDD first to avoid this.
5342 * This also avoids spuriously turning the VDD on as
5343 * soon as the new power seqeuencer gets initialized.
5344 */
5345 if (force_disable_vdd) {
5346 u32 pp = ironlake_get_pp_control(intel_dp);
5347
5348 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5349
5350 if (pp & EDP_FORCE_VDD)
5351 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5352
5353 pp &= ~EDP_FORCE_VDD;
5354
5355 I915_WRITE(regs.pp_ctrl, pp);
5356 }
5357
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005358 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005359 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5360 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005361 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005362 /* Compute the divisor for the pp clock, simply match the Bspec
5363 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005364 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005365 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305366 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5367 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5368 << BXT_POWER_CYCLE_DELAY_SHIFT);
5369 } else {
5370 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5371 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5372 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5373 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005374
5375 /* Haswell doesn't have any port selection bits for the panel
5376 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005377 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005378 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005379 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005380 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005381 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005382 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005383 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005384 }
5385
Jesse Barnes453c5422013-03-28 09:55:41 -07005386 pp_on |= port_sel;
5387
Imre Deak8e8232d2016-06-16 16:37:21 +03005388 I915_WRITE(regs.pp_on, pp_on);
5389 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005390 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005391 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305392 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005393 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005394
Daniel Vetter67a54562012-10-20 20:57:45 +02005395 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 +03005396 I915_READ(regs.pp_on),
5397 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005398 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005399 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5400 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005401}
5402
Imre Deak335f7522016-08-10 14:07:32 +03005403static void intel_dp_pps_init(struct drm_device *dev,
5404 struct intel_dp *intel_dp)
5405{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005406 struct drm_i915_private *dev_priv = to_i915(dev);
5407
5408 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005409 vlv_initial_power_sequencer_setup(intel_dp);
5410 } else {
5411 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005412 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005413 }
5414}
5415
Vandana Kannanb33a2812015-02-13 15:33:03 +05305416/**
5417 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005418 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005419 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305420 * @refresh_rate: RR to be programmed
5421 *
5422 * This function gets called when refresh rate (RR) has to be changed from
5423 * one frequency to another. Switches can be between high and low RR
5424 * supported by the panel or to any other RR based on media playback (in
5425 * this case, RR value needs to be passed from user space).
5426 *
5427 * The caller of this function needs to take a lock on dev_priv->drrs.
5428 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005429static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5430 struct intel_crtc_state *crtc_state,
5431 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305432{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305433 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305434 struct intel_digital_port *dig_port = NULL;
5435 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005436 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305437 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305438
5439 if (refresh_rate <= 0) {
5440 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5441 return;
5442 }
5443
Vandana Kannan96178ee2015-01-10 02:25:56 +05305444 if (intel_dp == NULL) {
5445 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305446 return;
5447 }
5448
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005449 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005450 * FIXME: This needs proper synchronization with psr state for some
5451 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005452 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305453
Vandana Kannan96178ee2015-01-10 02:25:56 +05305454 dig_port = dp_to_dig_port(intel_dp);
5455 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005456 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305457
5458 if (!intel_crtc) {
5459 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5460 return;
5461 }
5462
Vandana Kannan96178ee2015-01-10 02:25:56 +05305463 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305464 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5465 return;
5466 }
5467
Vandana Kannan96178ee2015-01-10 02:25:56 +05305468 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5469 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305470 index = DRRS_LOW_RR;
5471
Vandana Kannan96178ee2015-01-10 02:25:56 +05305472 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473 DRM_DEBUG_KMS(
5474 "DRRS requested for previously set RR...ignoring\n");
5475 return;
5476 }
5477
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005478 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305479 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5480 return;
5481 }
5482
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005483 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305484 switch (index) {
5485 case DRRS_HIGH_RR:
5486 intel_dp_set_m_n(intel_crtc, M1_N1);
5487 break;
5488 case DRRS_LOW_RR:
5489 intel_dp_set_m_n(intel_crtc, M2_N2);
5490 break;
5491 case DRRS_MAX_RR:
5492 default:
5493 DRM_ERROR("Unsupported refreshrate type\n");
5494 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005495 } else if (INTEL_GEN(dev_priv) > 6) {
5496 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005497 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305498
Ville Syrjälä649636e2015-09-22 19:50:01 +03005499 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305500 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005501 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305502 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5503 else
5504 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305505 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005506 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305507 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5508 else
5509 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305510 }
5511 I915_WRITE(reg, val);
5512 }
5513
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305514 dev_priv->drrs.refresh_rate_type = index;
5515
5516 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5517}
5518
Vandana Kannanb33a2812015-02-13 15:33:03 +05305519/**
5520 * intel_edp_drrs_enable - init drrs struct if supported
5521 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005522 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305523 *
5524 * Initializes frontbuffer_bits and drrs.dp
5525 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005526void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5527 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305528{
5529 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005530 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305531
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005532 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305533 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5534 return;
5535 }
5536
5537 mutex_lock(&dev_priv->drrs.mutex);
5538 if (WARN_ON(dev_priv->drrs.dp)) {
5539 DRM_ERROR("DRRS already enabled\n");
5540 goto unlock;
5541 }
5542
5543 dev_priv->drrs.busy_frontbuffer_bits = 0;
5544
5545 dev_priv->drrs.dp = intel_dp;
5546
5547unlock:
5548 mutex_unlock(&dev_priv->drrs.mutex);
5549}
5550
Vandana Kannanb33a2812015-02-13 15:33:03 +05305551/**
5552 * intel_edp_drrs_disable - Disable DRRS
5553 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005554 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305555 *
5556 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005557void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5558 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305559{
5560 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005561 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305562
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005563 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305564 return;
5565
5566 mutex_lock(&dev_priv->drrs.mutex);
5567 if (!dev_priv->drrs.dp) {
5568 mutex_unlock(&dev_priv->drrs.mutex);
5569 return;
5570 }
5571
5572 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005573 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5574 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305575
5576 dev_priv->drrs.dp = NULL;
5577 mutex_unlock(&dev_priv->drrs.mutex);
5578
5579 cancel_delayed_work_sync(&dev_priv->drrs.work);
5580}
5581
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305582static void intel_edp_drrs_downclock_work(struct work_struct *work)
5583{
5584 struct drm_i915_private *dev_priv =
5585 container_of(work, typeof(*dev_priv), drrs.work.work);
5586 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305587
Vandana Kannan96178ee2015-01-10 02:25:56 +05305588 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305589
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305590 intel_dp = dev_priv->drrs.dp;
5591
5592 if (!intel_dp)
5593 goto unlock;
5594
5595 /*
5596 * The delayed work can race with an invalidate hence we need to
5597 * recheck.
5598 */
5599
5600 if (dev_priv->drrs.busy_frontbuffer_bits)
5601 goto unlock;
5602
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005603 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5604 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5605
5606 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5607 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5608 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305609
5610unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305611 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305612}
5613
Vandana Kannanb33a2812015-02-13 15:33:03 +05305614/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305615 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005616 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305617 * @frontbuffer_bits: frontbuffer plane tracking bits
5618 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305619 * This function gets called everytime rendering on the given planes start.
5620 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305621 *
5622 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5623 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005624void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5625 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305626{
Vandana Kannana93fad02015-01-10 02:25:59 +05305627 struct drm_crtc *crtc;
5628 enum pipe pipe;
5629
Daniel Vetter9da7d692015-04-09 16:44:15 +02005630 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305631 return;
5632
Daniel Vetter88f933a2015-04-09 16:44:16 +02005633 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305634
Vandana Kannana93fad02015-01-10 02:25:59 +05305635 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005636 if (!dev_priv->drrs.dp) {
5637 mutex_unlock(&dev_priv->drrs.mutex);
5638 return;
5639 }
5640
Vandana Kannana93fad02015-01-10 02:25:59 +05305641 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5642 pipe = to_intel_crtc(crtc)->pipe;
5643
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005644 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5645 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5646
Ramalingam C0ddfd202015-06-15 20:50:05 +05305647 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005648 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005649 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5650 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305651
Vandana Kannana93fad02015-01-10 02:25:59 +05305652 mutex_unlock(&dev_priv->drrs.mutex);
5653}
5654
Vandana Kannanb33a2812015-02-13 15:33:03 +05305655/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305656 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005657 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305658 * @frontbuffer_bits: frontbuffer plane tracking bits
5659 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305660 * This function gets called every time rendering on the given planes has
5661 * completed or flip on a crtc is completed. So DRRS should be upclocked
5662 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5663 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305664 *
5665 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5666 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005667void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5668 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305669{
Vandana Kannana93fad02015-01-10 02:25:59 +05305670 struct drm_crtc *crtc;
5671 enum pipe pipe;
5672
Daniel Vetter9da7d692015-04-09 16:44:15 +02005673 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305674 return;
5675
Daniel Vetter88f933a2015-04-09 16:44:16 +02005676 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305677
Vandana Kannana93fad02015-01-10 02:25:59 +05305678 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005679 if (!dev_priv->drrs.dp) {
5680 mutex_unlock(&dev_priv->drrs.mutex);
5681 return;
5682 }
5683
Vandana Kannana93fad02015-01-10 02:25:59 +05305684 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5685 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005686
5687 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305688 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5689
Ramalingam C0ddfd202015-06-15 20:50:05 +05305690 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005691 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005692 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5693 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305694
5695 /*
5696 * flush also means no more activity hence schedule downclock, if all
5697 * other fbs are quiescent too
5698 */
5699 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305700 schedule_delayed_work(&dev_priv->drrs.work,
5701 msecs_to_jiffies(1000));
5702 mutex_unlock(&dev_priv->drrs.mutex);
5703}
5704
Vandana Kannanb33a2812015-02-13 15:33:03 +05305705/**
5706 * DOC: Display Refresh Rate Switching (DRRS)
5707 *
5708 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5709 * which enables swtching between low and high refresh rates,
5710 * dynamically, based on the usage scenario. This feature is applicable
5711 * for internal panels.
5712 *
5713 * Indication that the panel supports DRRS is given by the panel EDID, which
5714 * would list multiple refresh rates for one resolution.
5715 *
5716 * DRRS is of 2 types - static and seamless.
5717 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5718 * (may appear as a blink on screen) and is used in dock-undock scenario.
5719 * Seamless DRRS involves changing RR without any visual effect to the user
5720 * and can be used during normal system usage. This is done by programming
5721 * certain registers.
5722 *
5723 * Support for static/seamless DRRS may be indicated in the VBT based on
5724 * inputs from the panel spec.
5725 *
5726 * DRRS saves power by switching to low RR based on usage scenarios.
5727 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005728 * The implementation is based on frontbuffer tracking implementation. When
5729 * there is a disturbance on the screen triggered by user activity or a periodic
5730 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5731 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5732 * made.
5733 *
5734 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5735 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305736 *
5737 * DRRS can be further extended to support other internal panels and also
5738 * the scenario of video playback wherein RR is set based on the rate
5739 * requested by userspace.
5740 */
5741
5742/**
5743 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5744 * @intel_connector: eDP connector
5745 * @fixed_mode: preferred mode of panel
5746 *
5747 * This function is called only once at driver load to initialize basic
5748 * DRRS stuff.
5749 *
5750 * Returns:
5751 * Downclock mode if panel supports it, else return NULL.
5752 * DRRS support is determined by the presence of downclock mode (apart
5753 * from VBT setting).
5754 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305755static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305756intel_dp_drrs_init(struct intel_connector *intel_connector,
5757 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305758{
5759 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305760 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005761 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762 struct drm_display_mode *downclock_mode = NULL;
5763
Daniel Vetter9da7d692015-04-09 16:44:15 +02005764 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5765 mutex_init(&dev_priv->drrs.mutex);
5766
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005767 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305768 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5769 return NULL;
5770 }
5771
5772 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005773 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305774 return NULL;
5775 }
5776
5777 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005778 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305779
5780 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305781 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305782 return NULL;
5783 }
5784
Vandana Kannan96178ee2015-01-10 02:25:56 +05305785 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305786
Vandana Kannan96178ee2015-01-10 02:25:56 +05305787 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005788 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305789 return downclock_mode;
5790}
5791
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005792static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005793 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005794{
5795 struct drm_connector *connector = &intel_connector->base;
5796 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005797 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5798 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005799 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005800 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305801 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005802 bool has_dpcd;
5803 struct drm_display_mode *scan;
5804 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005805 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005806
5807 if (!is_edp(intel_dp))
5808 return true;
5809
Imre Deak97a824e12016-06-21 11:51:47 +03005810 /*
5811 * On IBX/CPT we may get here with LVDS already registered. Since the
5812 * driver uses the only internal power sequencer available for both
5813 * eDP and LVDS bail out early in this case to prevent interfering
5814 * with an already powered-on LVDS power sequencer.
5815 */
5816 if (intel_get_lvds_encoder(dev)) {
5817 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5818 DRM_INFO("LVDS was detected, not registering eDP\n");
5819
5820 return false;
5821 }
5822
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005823 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005824
5825 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005826 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005827 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005828
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005829 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005830
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005831 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005832 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005833
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005834 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005835 /* if this fails, presume the device is a ghost */
5836 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005837 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005838 }
5839
Daniel Vetter060c8772014-03-21 23:22:35 +01005840 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005841 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005842 if (edid) {
5843 if (drm_add_edid_modes(connector, edid)) {
5844 drm_mode_connector_update_edid_property(connector,
5845 edid);
5846 drm_edid_to_eld(connector, edid);
5847 } else {
5848 kfree(edid);
5849 edid = ERR_PTR(-EINVAL);
5850 }
5851 } else {
5852 edid = ERR_PTR(-ENOENT);
5853 }
5854 intel_connector->edid = edid;
5855
5856 /* prefer fixed mode from EDID if available */
5857 list_for_each_entry(scan, &connector->probed_modes, head) {
5858 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5859 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305860 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305861 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005862 break;
5863 }
5864 }
5865
5866 /* fallback to VBT if available for eDP */
5867 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5868 fixed_mode = drm_mode_duplicate(dev,
5869 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005870 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005871 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005872 connector->display_info.width_mm = fixed_mode->width_mm;
5873 connector->display_info.height_mm = fixed_mode->height_mm;
5874 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005875 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005876 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005877
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005878 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005879 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5880 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005881
5882 /*
5883 * Figure out the current pipe for the initial backlight setup.
5884 * If the current pipe isn't valid, try the PPS pipe, and if that
5885 * fails just assume pipe A.
5886 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005887 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005888
5889 if (pipe != PIPE_A && pipe != PIPE_B)
5890 pipe = intel_dp->pps_pipe;
5891
5892 if (pipe != PIPE_A && pipe != PIPE_B)
5893 pipe = PIPE_A;
5894
5895 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5896 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005897 }
5898
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305899 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005900 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005901 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005902
5903 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005904
5905out_vdd_off:
5906 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5907 /*
5908 * vdd might still be enabled do to the delayed vdd off.
5909 * Make sure vdd is actually turned off here.
5910 */
5911 pps_lock(intel_dp);
5912 edp_panel_vdd_off_sync(intel_dp);
5913 pps_unlock(intel_dp);
5914
5915 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005916}
5917
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005918/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005919static void
5920intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5921{
5922 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005923 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005924
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005925 switch (intel_dig_port->port) {
5926 case PORT_A:
5927 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005928 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005929 break;
5930 case PORT_B:
5931 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005932 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005933 break;
5934 case PORT_C:
5935 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005936 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005937 break;
5938 case PORT_D:
5939 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005940 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005941 break;
5942 case PORT_E:
5943 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005944
5945 /* FIXME: Check VBT for actual wiring of PORT E */
5946 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005947 break;
5948 default:
5949 MISSING_CASE(intel_dig_port->port);
5950 }
5951}
5952
Paulo Zanoni16c25532013-06-12 17:27:25 -03005953bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005954intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5955 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005956{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005957 struct drm_connector *connector = &intel_connector->base;
5958 struct intel_dp *intel_dp = &intel_dig_port->dp;
5959 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5960 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005961 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005962 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005963 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005964
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005965 if (WARN(intel_dig_port->max_lanes < 1,
5966 "Not enough lanes (%d) for DP on port %c\n",
5967 intel_dig_port->max_lanes, port_name(port)))
5968 return false;
5969
Jani Nikula55cfc582017-03-28 17:59:04 +03005970 intel_dp_set_source_rates(intel_dp);
5971
Manasi Navared7e8ef02017-02-07 16:54:11 -08005972 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005973 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005974 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005975
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005976 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005977 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005978 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005979 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005980 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005981 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005982 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5983 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005984 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005985
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005986 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005987 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5988 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005989 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005990
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005991 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005992 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5993
Daniel Vetter07679352012-09-06 22:15:42 +02005994 /* Preserve the current hw state. */
5995 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005996 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005997
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005998 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305999 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006000 else
6001 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006002
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006003 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6004 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6005
Imre Deakf7d24902013-05-08 13:14:05 +03006006 /*
6007 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6008 * for DP the encoder type can be set by the caller to
6009 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6010 */
6011 if (type == DRM_MODE_CONNECTOR_eDP)
6012 intel_encoder->type = INTEL_OUTPUT_EDP;
6013
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006014 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006015 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006016 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006017 return false;
6018
Imre Deake7281ea2013-05-08 13:14:08 +03006019 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6020 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6021 port_name(port));
6022
Adam Jacksonb3295302010-07-16 14:46:28 -04006023 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006024 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6025
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006026 connector->interlace_allowed = true;
6027 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006028
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006029 intel_dp_init_connector_port_info(intel_dig_port);
6030
Mika Kaholab6339582016-09-09 14:10:52 +03006031 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006032
Daniel Vetter66a92782012-07-12 20:08:18 +02006033 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006034 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006035
Chris Wilsondf0e9242010-09-09 16:20:55 +01006036 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006037
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006038 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006039 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6040 else
6041 intel_connector->get_hw_state = intel_connector_get_hw_state;
6042
Dave Airlie0e32b392014-05-02 14:02:48 +10006043 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006044 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006045 (port == PORT_B || port == PORT_C || port == PORT_D))
6046 intel_dp_mst_encoder_init(intel_dig_port,
6047 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006048
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006049 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006050 intel_dp_aux_fini(intel_dp);
6051 intel_dp_mst_encoder_cleanup(intel_dig_port);
6052 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006053 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006054
Chris Wilsonf6849602010-09-19 09:29:33 +01006055 intel_dp_add_properties(intel_dp, connector);
6056
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006057 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6058 * 0xd. Failure to do so will result in spurious interrupts being
6059 * generated on the port when a cable is not attached.
6060 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006061 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006062 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6063 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6064 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006065
6066 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006067
6068fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006069 drm_connector_cleanup(connector);
6070
6071 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006072}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006073
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006074bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006075 i915_reg_t output_reg,
6076 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006077{
6078 struct intel_digital_port *intel_dig_port;
6079 struct intel_encoder *intel_encoder;
6080 struct drm_encoder *encoder;
6081 struct intel_connector *intel_connector;
6082
Daniel Vetterb14c5672013-09-19 12:18:32 +02006083 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006084 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006085 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006086
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006087 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306088 if (!intel_connector)
6089 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006090
6091 intel_encoder = &intel_dig_port->base;
6092 encoder = &intel_encoder->base;
6093
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006094 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6095 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6096 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306097 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006098
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006099 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006100 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006101 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006102 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006103 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006104 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006105 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006106 intel_encoder->pre_enable = chv_pre_enable_dp;
6107 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006108 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006109 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006110 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006111 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006112 intel_encoder->pre_enable = vlv_pre_enable_dp;
6113 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006114 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006115 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006116 intel_encoder->pre_enable = g4x_pre_enable_dp;
6117 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006118 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006119 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006120 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006121
Paulo Zanoni174edf12012-10-26 19:05:50 -02006122 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006123 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006124 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006125
Ville Syrjäläcca05022016-06-22 21:57:06 +03006126 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006127 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006128 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006129 if (port == PORT_D)
6130 intel_encoder->crtc_mask = 1 << 2;
6131 else
6132 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6133 } else {
6134 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6135 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006136 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006137 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006138
Dave Airlie13cf5502014-06-18 11:29:35 +10006139 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006140 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006141
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306142 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6143 goto err_init_connector;
6144
Chris Wilson457c52d2016-06-01 08:27:50 +01006145 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306146
6147err_init_connector:
6148 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306149err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306150 kfree(intel_connector);
6151err_connector_alloc:
6152 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006153 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006154}
Dave Airlie0e32b392014-05-02 14:02:48 +10006155
6156void intel_dp_mst_suspend(struct drm_device *dev)
6157{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006158 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006159 int i;
6160
6161 /* disable MST */
6162 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006163 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006164
6165 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006166 continue;
6167
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006168 if (intel_dig_port->dp.is_mst)
6169 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006170 }
6171}
6172
6173void intel_dp_mst_resume(struct drm_device *dev)
6174{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006175 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006176 int i;
6177
6178 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006179 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006180 int ret;
6181
6182 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006183 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006184
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006185 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6186 if (ret)
6187 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006188 }
6189}