blob: e03e79f7714a6ddd6e163344b2bdc53aefca5663 [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>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300159 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
160
161 return min(source_max, sink_max);
162}
163
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400164/*
165 * The units on the numbers in the next two are... bizarre. Examples will
166 * make it clearer; this one parallels an example in the eDP spec.
167 *
168 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
169 *
170 * 270000 * 1 * 8 / 10 == 216000
171 *
172 * The actual data capacity of that configuration is 2.16Gbit/s, so the
173 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
174 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
175 * 119000. At 18bpp that's 2142000 kilobits per second.
176 *
177 * Thus the strange-looking division by 10 in intel_dp_link_required, to
178 * get the result in decakilobits instead of kilobits.
179 */
180
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181static int
Keith Packardc8982612012-01-25 08:16:25 -0800182intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700183{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400184 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185}
186
187static int
Dave Airliefe27d532010-06-30 11:46:17 +1000188intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189{
190 return (max_link_clock * max_lanes * 8) / 10;
191}
192
Mika Kahola70ec0642016-09-09 14:10:55 +0300193static int
194intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
195{
196 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
197 struct intel_encoder *encoder = &intel_dig_port->base;
198 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
199 int max_dotclk = dev_priv->max_dotclk_freq;
200 int ds_max_dotclk;
201
202 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
203
204 if (type != DP_DS_PORT_TYPE_VGA)
205 return max_dotclk;
206
207 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
208 intel_dp->downstream_ports);
209
210 if (ds_max_dotclk != 0)
211 max_dotclk = min(max_dotclk, ds_max_dotclk);
212
213 return max_dotclk;
214}
215
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000216static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700217intel_dp_mode_valid(struct drm_connector *connector,
218 struct drm_display_mode *mode)
219{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100220 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300221 struct intel_connector *intel_connector = to_intel_connector(connector);
222 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100223 int target_clock = mode->clock;
224 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300225 int max_dotclk;
226
227 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700228
Jani Nikuladd06f902012-10-19 14:51:50 +0300229 if (is_edp(intel_dp) && fixed_mode) {
230 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100231 return MODE_PANEL;
232
Jani Nikuladd06f902012-10-19 14:51:50 +0300233 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100234 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200235
236 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100237 }
238
Ville Syrjälä50fec212015-03-12 17:10:34 +0200239 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300240 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100241
242 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
243 mode_rate = intel_dp_link_required(target_clock, 18);
244
Mika Kahola799487f2016-02-02 15:16:38 +0200245 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200246 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700247
248 if (mode->clock < 10000)
249 return MODE_CLOCK_LOW;
250
Daniel Vetter0af78a22012-05-23 11:30:55 +0200251 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
252 return MODE_H_ILLEGAL;
253
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700254 return MODE_OK;
255}
256
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800257uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700258{
259 int i;
260 uint32_t v = 0;
261
262 if (src_bytes > 4)
263 src_bytes = 4;
264 for (i = 0; i < src_bytes; i++)
265 v |= ((uint32_t) src[i]) << ((3-i) * 8);
266 return v;
267}
268
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000269static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700270{
271 int i;
272 if (dst_bytes > 4)
273 dst_bytes = 4;
274 for (i = 0; i < dst_bytes; i++)
275 dst[i] = src >> ((3-i) * 8);
276}
277
Jani Nikulabf13e812013-09-06 07:40:05 +0300278static void
279intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300280 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300281static void
282intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300283 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300284static void
285intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300286
Ville Syrjälä773538e82014-09-04 14:54:56 +0300287static void pps_lock(struct intel_dp *intel_dp)
288{
289 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
290 struct intel_encoder *encoder = &intel_dig_port->base;
291 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100292 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300293 enum intel_display_power_domain power_domain;
294
295 /*
296 * See vlv_power_sequencer_reset() why we need
297 * a power domain reference here.
298 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100299 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300300 intel_display_power_get(dev_priv, power_domain);
301
302 mutex_lock(&dev_priv->pps_mutex);
303}
304
305static void pps_unlock(struct intel_dp *intel_dp)
306{
307 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
308 struct intel_encoder *encoder = &intel_dig_port->base;
309 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100310 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300311 enum intel_display_power_domain power_domain;
312
313 mutex_unlock(&dev_priv->pps_mutex);
314
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100315 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300316 intel_display_power_put(dev_priv, power_domain);
317}
318
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300319static void
320vlv_power_sequencer_kick(struct intel_dp *intel_dp)
321{
322 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
323 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100324 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300325 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300326 bool pll_enabled, release_cl_override = false;
327 enum dpio_phy phy = DPIO_PHY(pipe);
328 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300329 uint32_t DP;
330
331 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
332 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
333 pipe_name(pipe), port_name(intel_dig_port->port)))
334 return;
335
336 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
337 pipe_name(pipe), port_name(intel_dig_port->port));
338
339 /* Preserve the BIOS-computed detected bit. This is
340 * supposed to be read-only.
341 */
342 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
343 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
344 DP |= DP_PORT_WIDTH(1);
345 DP |= DP_LINK_TRAIN_PAT_1;
346
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100347 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300348 DP |= DP_PIPE_SELECT_CHV(pipe);
349 else if (pipe == PIPE_B)
350 DP |= DP_PIPEB_SELECT;
351
Ville Syrjäläd288f652014-10-28 13:20:22 +0200352 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
353
354 /*
355 * The DPLL for the pipe must be enabled for this to work.
356 * So enable temporarily it if it's not already enabled.
357 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300358 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100359 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300360 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
361
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100362 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000363 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
364 DRM_ERROR("Failed to force on pll for pipe %c!\n",
365 pipe_name(pipe));
366 return;
367 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300368 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200369
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300370 /*
371 * Similar magic as in intel_dp_enable_port().
372 * We _must_ do this port enable + disable trick
373 * to make this power seqeuencer lock onto the port.
374 * Otherwise even VDD force bit won't work.
375 */
376 I915_WRITE(intel_dp->output_reg, DP);
377 POSTING_READ(intel_dp->output_reg);
378
379 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
380 POSTING_READ(intel_dp->output_reg);
381
382 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
383 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200384
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300385 if (!pll_enabled) {
Ville Syrjäläd288f652014-10-28 13:20:22 +0200386 vlv_force_pll_off(dev, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300387
388 if (release_cl_override)
389 chv_phy_powergate_ch(dev_priv, phy, ch, false);
390 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300391}
392
Jani Nikulabf13e812013-09-06 07:40:05 +0300393static enum pipe
394vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
395{
396 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300397 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100398 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300399 struct intel_encoder *encoder;
400 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300401 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300402
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300403 lockdep_assert_held(&dev_priv->pps_mutex);
404
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300405 /* We should never land here with regular DP ports */
406 WARN_ON(!is_edp(intel_dp));
407
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300408 if (intel_dp->pps_pipe != INVALID_PIPE)
409 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300410
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300411 /*
412 * We don't have power sequencer currently.
413 * Pick one that's not used by other ports.
414 */
Jani Nikula19c80542015-12-16 12:48:16 +0200415 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300416 struct intel_dp *tmp;
417
418 if (encoder->type != INTEL_OUTPUT_EDP)
419 continue;
420
421 tmp = enc_to_intel_dp(&encoder->base);
422
423 if (tmp->pps_pipe != INVALID_PIPE)
424 pipes &= ~(1 << tmp->pps_pipe);
425 }
426
427 /*
428 * Didn't find one. This should not happen since there
429 * are two power sequencers and up to two eDP ports.
430 */
431 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300432 pipe = PIPE_A;
433 else
434 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300435
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300436 vlv_steal_power_sequencer(dev, pipe);
437 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300438
439 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
440 pipe_name(intel_dp->pps_pipe),
441 port_name(intel_dig_port->port));
442
443 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300444 intel_dp_init_panel_power_sequencer(dev, intel_dp);
445 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300446
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300447 /*
448 * Even vdd force doesn't work until we've made
449 * the power sequencer lock in on the port.
450 */
451 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300452
453 return intel_dp->pps_pipe;
454}
455
Imre Deak78597992016-06-16 16:37:20 +0300456static int
457bxt_power_sequencer_idx(struct intel_dp *intel_dp)
458{
459 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
460 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100461 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300462
463 lockdep_assert_held(&dev_priv->pps_mutex);
464
465 /* We should never land here with regular DP ports */
466 WARN_ON(!is_edp(intel_dp));
467
468 /*
469 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
470 * mapping needs to be retrieved from VBT, for now just hard-code to
471 * use instance #0 always.
472 */
473 if (!intel_dp->pps_reset)
474 return 0;
475
476 intel_dp->pps_reset = false;
477
478 /*
479 * Only the HW needs to be reprogrammed, the SW state is fixed and
480 * has been setup during connector init.
481 */
482 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
483
484 return 0;
485}
486
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300487typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
488 enum pipe pipe);
489
490static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
491 enum pipe pipe)
492{
Imre Deak44cb7342016-08-10 14:07:29 +0300493 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300494}
495
496static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
497 enum pipe pipe)
498{
Imre Deak44cb7342016-08-10 14:07:29 +0300499 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300500}
501
502static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
503 enum pipe pipe)
504{
505 return true;
506}
507
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300508static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300509vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
510 enum port port,
511 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300512{
Jani Nikulabf13e812013-09-06 07:40:05 +0300513 enum pipe pipe;
514
Jani Nikulabf13e812013-09-06 07:40:05 +0300515 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300516 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300517 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300518
519 if (port_sel != PANEL_PORT_SELECT_VLV(port))
520 continue;
521
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300522 if (!pipe_check(dev_priv, pipe))
523 continue;
524
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300525 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300526 }
527
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300528 return INVALID_PIPE;
529}
530
531static void
532vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
533{
534 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
535 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100536 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300537 enum port port = intel_dig_port->port;
538
539 lockdep_assert_held(&dev_priv->pps_mutex);
540
541 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300542 /* first pick one where the panel is on */
543 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
544 vlv_pipe_has_pp_on);
545 /* didn't find one? pick one where vdd is on */
546 if (intel_dp->pps_pipe == INVALID_PIPE)
547 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
548 vlv_pipe_has_vdd_on);
549 /* didn't find one? pick one with just the correct port */
550 if (intel_dp->pps_pipe == INVALID_PIPE)
551 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
552 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300553
554 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
555 if (intel_dp->pps_pipe == INVALID_PIPE) {
556 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
557 port_name(port));
558 return;
559 }
560
561 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
562 port_name(port), pipe_name(intel_dp->pps_pipe));
563
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300564 intel_dp_init_panel_power_sequencer(dev, intel_dp);
565 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300566}
567
Imre Deak78597992016-06-16 16:37:20 +0300568void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300569{
Chris Wilson91c8a322016-07-05 10:40:23 +0100570 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300571 struct intel_encoder *encoder;
572
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100573 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100574 !IS_BROXTON(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300575 return;
576
577 /*
578 * We can't grab pps_mutex here due to deadlock with power_domain
579 * mutex when power_domain functions are called while holding pps_mutex.
580 * That also means that in order to use pps_pipe the code needs to
581 * hold both a power domain reference and pps_mutex, and the power domain
582 * reference get/put must be done while _not_ holding pps_mutex.
583 * pps_{lock,unlock}() do these steps in the correct order, so one
584 * should use them always.
585 */
586
Jani Nikula19c80542015-12-16 12:48:16 +0200587 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300588 struct intel_dp *intel_dp;
589
590 if (encoder->type != INTEL_OUTPUT_EDP)
591 continue;
592
593 intel_dp = enc_to_intel_dp(&encoder->base);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100594 if (IS_BROXTON(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300595 intel_dp->pps_reset = true;
596 else
597 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300598 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300599}
600
Imre Deak8e8232d2016-06-16 16:37:21 +0300601struct pps_registers {
602 i915_reg_t pp_ctrl;
603 i915_reg_t pp_stat;
604 i915_reg_t pp_on;
605 i915_reg_t pp_off;
606 i915_reg_t pp_div;
607};
608
609static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
610 struct intel_dp *intel_dp,
611 struct pps_registers *regs)
612{
Imre Deak44cb7342016-08-10 14:07:29 +0300613 int pps_idx = 0;
614
Imre Deak8e8232d2016-06-16 16:37:21 +0300615 memset(regs, 0, sizeof(*regs));
616
Imre Deak44cb7342016-08-10 14:07:29 +0300617 if (IS_BROXTON(dev_priv))
618 pps_idx = bxt_power_sequencer_idx(intel_dp);
619 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
620 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300621
Imre Deak44cb7342016-08-10 14:07:29 +0300622 regs->pp_ctrl = PP_CONTROL(pps_idx);
623 regs->pp_stat = PP_STATUS(pps_idx);
624 regs->pp_on = PP_ON_DELAYS(pps_idx);
625 regs->pp_off = PP_OFF_DELAYS(pps_idx);
626 if (!IS_BROXTON(dev_priv))
627 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300628}
629
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200630static i915_reg_t
631_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300632{
Imre Deak8e8232d2016-06-16 16:37:21 +0300633 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300634
Imre Deak8e8232d2016-06-16 16:37:21 +0300635 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
636 &regs);
637
638 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300639}
640
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200641static i915_reg_t
642_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300643{
Imre Deak8e8232d2016-06-16 16:37:21 +0300644 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300645
Imre Deak8e8232d2016-06-16 16:37:21 +0300646 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
647 &regs);
648
649 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300650}
651
Clint Taylor01527b32014-07-07 13:01:46 -0700652/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
653 This function only applicable when panel PM state is not to be tracked */
654static int edp_notify_handler(struct notifier_block *this, unsigned long code,
655 void *unused)
656{
657 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
658 edp_notifier);
659 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100660 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700661
662 if (!is_edp(intel_dp) || code != SYS_RESTART)
663 return 0;
664
Ville Syrjälä773538e82014-09-04 14:54:56 +0300665 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300666
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100667 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300668 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200669 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300670 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300671
Imre Deak44cb7342016-08-10 14:07:29 +0300672 pp_ctrl_reg = PP_CONTROL(pipe);
673 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700674 pp_div = I915_READ(pp_div_reg);
675 pp_div &= PP_REFERENCE_DIVIDER_MASK;
676
677 /* 0x1F write to PP_DIV_REG sets max cycle delay */
678 I915_WRITE(pp_div_reg, pp_div | 0x1F);
679 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
680 msleep(intel_dp->panel_power_cycle_delay);
681 }
682
Ville Syrjälä773538e82014-09-04 14:54:56 +0300683 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300684
Clint Taylor01527b32014-07-07 13:01:46 -0700685 return 0;
686}
687
Daniel Vetter4be73782014-01-17 14:39:48 +0100688static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700689{
Paulo Zanoni30add222012-10-26 19:05:45 -0200690 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100691 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700692
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300693 lockdep_assert_held(&dev_priv->pps_mutex);
694
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100695 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300696 intel_dp->pps_pipe == INVALID_PIPE)
697 return false;
698
Jani Nikulabf13e812013-09-06 07:40:05 +0300699 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700700}
701
Daniel Vetter4be73782014-01-17 14:39:48 +0100702static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700703{
Paulo Zanoni30add222012-10-26 19:05:45 -0200704 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100705 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700706
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300707 lockdep_assert_held(&dev_priv->pps_mutex);
708
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100709 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300710 intel_dp->pps_pipe == INVALID_PIPE)
711 return false;
712
Ville Syrjälä773538e82014-09-04 14:54:56 +0300713 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700714}
715
Keith Packard9b984da2011-09-19 13:54:47 -0700716static void
717intel_dp_check_edp(struct intel_dp *intel_dp)
718{
Paulo Zanoni30add222012-10-26 19:05:45 -0200719 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100720 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700721
Keith Packard9b984da2011-09-19 13:54:47 -0700722 if (!is_edp(intel_dp))
723 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700724
Daniel Vetter4be73782014-01-17 14:39:48 +0100725 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700726 WARN(1, "eDP powered off while attempting aux channel communication.\n");
727 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300728 I915_READ(_pp_stat_reg(intel_dp)),
729 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700730 }
731}
732
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100733static uint32_t
734intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
735{
736 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
737 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100738 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200739 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100740 uint32_t status;
741 bool done;
742
Daniel Vetteref04f002012-12-01 21:03:59 +0100743#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100744 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300745 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300746 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100747 else
Imre Deak713a6b662016-06-28 13:37:33 +0300748 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100749 if (!done)
750 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
751 has_aux_irq);
752#undef C
753
754 return status;
755}
756
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200757static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000758{
759 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200760 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000761
Ville Syrjäläa457f542016-03-02 17:22:17 +0200762 if (index)
763 return 0;
764
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000765 /*
766 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200767 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000768 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200769 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000770}
771
772static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
773{
774 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200775 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000776
777 if (index)
778 return 0;
779
Ville Syrjäläa457f542016-03-02 17:22:17 +0200780 /*
781 * The clock divider is based off the cdclk or PCH rawclk, and would
782 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
783 * divide by 2000 and use that
784 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200785 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200786 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200787 else
788 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000789}
790
791static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300792{
793 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200794 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300795
Ville Syrjäläa457f542016-03-02 17:22:17 +0200796 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300797 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100798 switch (index) {
799 case 0: return 63;
800 case 1: return 72;
801 default: return 0;
802 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300803 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200804
805 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300806}
807
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000808static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
809{
810 /*
811 * SKL doesn't need us to program the AUX clock divider (Hardware will
812 * derive the clock from CDCLK automatically). We still implement the
813 * get_aux_clock_divider vfunc to plug-in into the existing code.
814 */
815 return index ? 0 : 1;
816}
817
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200818static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
819 bool has_aux_irq,
820 int send_bytes,
821 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000822{
823 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100824 struct drm_i915_private *dev_priv =
825 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000826 uint32_t precharge, timeout;
827
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100828 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000829 precharge = 3;
830 else
831 precharge = 5;
832
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100833 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000834 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
835 else
836 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
837
838 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000839 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000840 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000841 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000842 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000843 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000844 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
845 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000846 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000847}
848
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000849static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
850 bool has_aux_irq,
851 int send_bytes,
852 uint32_t unused)
853{
854 return DP_AUX_CH_CTL_SEND_BUSY |
855 DP_AUX_CH_CTL_DONE |
856 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
857 DP_AUX_CH_CTL_TIME_OUT_ERROR |
858 DP_AUX_CH_CTL_TIME_OUT_1600us |
859 DP_AUX_CH_CTL_RECEIVE_ERROR |
860 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200861 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000862 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
863}
864
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700865static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100866intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200867 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700868 uint8_t *recv, int recv_size)
869{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200870 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
871 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100872 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200873 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100874 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100875 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700876 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000877 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100878 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200879 bool vdd;
880
Ville Syrjälä773538e82014-09-04 14:54:56 +0300881 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300882
Ville Syrjälä72c35002014-08-18 22:16:00 +0300883 /*
884 * We will be called with VDD already enabled for dpcd/edid/oui reads.
885 * In such cases we want to leave VDD enabled and it's up to upper layers
886 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
887 * ourselves.
888 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300889 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100890
891 /* dp aux is extremely sensitive to irq latency, hence request the
892 * lowest possible wakeup latency and so prevent the cpu from going into
893 * deep sleep states.
894 */
895 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700896
Keith Packard9b984da2011-09-19 13:54:47 -0700897 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800898
Jesse Barnes11bee432011-08-01 15:02:20 -0700899 /* Try to wait for any previous AUX channel activity */
900 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100901 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700902 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
903 break;
904 msleep(1);
905 }
906
907 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300908 static u32 last_status = -1;
909 const u32 status = I915_READ(ch_ctl);
910
911 if (status != last_status) {
912 WARN(1, "dp_aux_ch not started status 0x%08x\n",
913 status);
914 last_status = status;
915 }
916
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100917 ret = -EBUSY;
918 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100919 }
920
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300921 /* Only 5 data registers! */
922 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
923 ret = -E2BIG;
924 goto out;
925 }
926
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000927 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000928 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
929 has_aux_irq,
930 send_bytes,
931 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000932
Chris Wilsonbc866252013-07-21 16:00:03 +0100933 /* Must try at least 3 times according to DP spec */
934 for (try = 0; try < 5; try++) {
935 /* Load the send data into the aux channel data registers */
936 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200937 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800938 intel_dp_pack_aux(send + i,
939 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400940
Chris Wilsonbc866252013-07-21 16:00:03 +0100941 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000942 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100943
Chris Wilsonbc866252013-07-21 16:00:03 +0100944 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400945
Chris Wilsonbc866252013-07-21 16:00:03 +0100946 /* Clear done status and any errors */
947 I915_WRITE(ch_ctl,
948 status |
949 DP_AUX_CH_CTL_DONE |
950 DP_AUX_CH_CTL_TIME_OUT_ERROR |
951 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400952
Todd Previte74ebf292015-04-15 08:38:41 -0700953 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +0100954 continue;
Todd Previte74ebf292015-04-15 08:38:41 -0700955
956 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
957 * 400us delay required for errors and timeouts
958 * Timeout errors from the HW already meet this
959 * requirement so skip to next iteration
960 */
961 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
962 usleep_range(400, 500);
963 continue;
964 }
Chris Wilsonbc866252013-07-21 16:00:03 +0100965 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -0700966 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +0100967 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700968 }
969
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700970 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700971 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100972 ret = -EBUSY;
973 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700974 }
975
Jim Bridee058c942015-05-27 10:21:48 -0700976done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700977 /* Check for timeout or receive error.
978 * Timeouts occur when the sink is not connected
979 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700980 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700981 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100982 ret = -EIO;
983 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700984 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700985
986 /* Timeouts occur when the device isn't connected, so they're
987 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700988 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800989 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100990 ret = -ETIMEDOUT;
991 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700992 }
993
994 /* Unload any bytes sent back from the other side */
995 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
996 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -0800997
998 /*
999 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1000 * We have no idea of what happened so we return -EBUSY so
1001 * drm layer takes care for the necessary retries.
1002 */
1003 if (recv_bytes == 0 || recv_bytes > 20) {
1004 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1005 recv_bytes);
1006 /*
1007 * FIXME: This patch was created on top of a series that
1008 * organize the retries at drm level. There EBUSY should
1009 * also take care for 1ms wait before retrying.
1010 * That aux retries re-org is still needed and after that is
1011 * merged we remove this sleep from here.
1012 */
1013 usleep_range(1000, 1500);
1014 ret = -EBUSY;
1015 goto out;
1016 }
1017
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001018 if (recv_bytes > recv_size)
1019 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001020
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001021 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001022 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001023 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001024
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001025 ret = recv_bytes;
1026out:
1027 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1028
Jani Nikula884f19e2014-03-14 16:51:14 +02001029 if (vdd)
1030 edp_panel_vdd_off(intel_dp, false);
1031
Ville Syrjälä773538e82014-09-04 14:54:56 +03001032 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001033
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001034 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001035}
1036
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001037#define BARE_ADDRESS_SIZE 3
1038#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001039static ssize_t
1040intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001041{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001042 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1043 uint8_t txbuf[20], rxbuf[20];
1044 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001045 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001046
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001047 txbuf[0] = (msg->request << 4) |
1048 ((msg->address >> 16) & 0xf);
1049 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001050 txbuf[2] = msg->address & 0xff;
1051 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001052
Jani Nikula9d1a1032014-03-14 16:51:15 +02001053 switch (msg->request & ~DP_AUX_I2C_MOT) {
1054 case DP_AUX_NATIVE_WRITE:
1055 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001056 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001057 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001058 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001059
Jani Nikula9d1a1032014-03-14 16:51:15 +02001060 if (WARN_ON(txsize > 20))
1061 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001062
Ville Syrjälädd788092016-07-28 17:55:04 +03001063 WARN_ON(!msg->buffer != !msg->size);
1064
Imre Deakd81a67c2016-01-29 14:52:26 +02001065 if (msg->buffer)
1066 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001067
Jani Nikula9d1a1032014-03-14 16:51:15 +02001068 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1069 if (ret > 0) {
1070 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001071
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001072 if (ret > 1) {
1073 /* Number of bytes written in a short write. */
1074 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1075 } else {
1076 /* Return payload size. */
1077 ret = msg->size;
1078 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001079 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001080 break;
1081
1082 case DP_AUX_NATIVE_READ:
1083 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001084 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001085 rxsize = msg->size + 1;
1086
1087 if (WARN_ON(rxsize > 20))
1088 return -E2BIG;
1089
1090 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1091 if (ret > 0) {
1092 msg->reply = rxbuf[0] >> 4;
1093 /*
1094 * Assume happy day, and copy the data. The caller is
1095 * expected to check msg->reply before touching it.
1096 *
1097 * Return payload size.
1098 */
1099 ret--;
1100 memcpy(msg->buffer, rxbuf + 1, ret);
1101 }
1102 break;
1103
1104 default:
1105 ret = -EINVAL;
1106 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001107 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001108
Jani Nikula9d1a1032014-03-14 16:51:15 +02001109 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001110}
1111
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001112static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1113 enum port port)
1114{
1115 const struct ddi_vbt_port_info *info =
1116 &dev_priv->vbt.ddi_port_info[port];
1117 enum port aux_port;
1118
1119 if (!info->alternate_aux_channel) {
1120 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1121 port_name(port), port_name(port));
1122 return port;
1123 }
1124
1125 switch (info->alternate_aux_channel) {
1126 case DP_AUX_A:
1127 aux_port = PORT_A;
1128 break;
1129 case DP_AUX_B:
1130 aux_port = PORT_B;
1131 break;
1132 case DP_AUX_C:
1133 aux_port = PORT_C;
1134 break;
1135 case DP_AUX_D:
1136 aux_port = PORT_D;
1137 break;
1138 default:
1139 MISSING_CASE(info->alternate_aux_channel);
1140 aux_port = PORT_A;
1141 break;
1142 }
1143
1144 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1145 port_name(aux_port), port_name(port));
1146
1147 return aux_port;
1148}
1149
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001150static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001151 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001152{
1153 switch (port) {
1154 case PORT_B:
1155 case PORT_C:
1156 case PORT_D:
1157 return DP_AUX_CH_CTL(port);
1158 default:
1159 MISSING_CASE(port);
1160 return DP_AUX_CH_CTL(PORT_B);
1161 }
1162}
1163
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001164static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001165 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001166{
1167 switch (port) {
1168 case PORT_B:
1169 case PORT_C:
1170 case PORT_D:
1171 return DP_AUX_CH_DATA(port, index);
1172 default:
1173 MISSING_CASE(port);
1174 return DP_AUX_CH_DATA(PORT_B, index);
1175 }
1176}
1177
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001178static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001179 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001180{
1181 switch (port) {
1182 case PORT_A:
1183 return DP_AUX_CH_CTL(port);
1184 case PORT_B:
1185 case PORT_C:
1186 case PORT_D:
1187 return PCH_DP_AUX_CH_CTL(port);
1188 default:
1189 MISSING_CASE(port);
1190 return DP_AUX_CH_CTL(PORT_A);
1191 }
1192}
1193
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001194static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001195 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001196{
1197 switch (port) {
1198 case PORT_A:
1199 return DP_AUX_CH_DATA(port, index);
1200 case PORT_B:
1201 case PORT_C:
1202 case PORT_D:
1203 return PCH_DP_AUX_CH_DATA(port, index);
1204 default:
1205 MISSING_CASE(port);
1206 return DP_AUX_CH_DATA(PORT_A, index);
1207 }
1208}
1209
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001210static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001211 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001212{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001213 switch (port) {
1214 case PORT_A:
1215 case PORT_B:
1216 case PORT_C:
1217 case PORT_D:
1218 return DP_AUX_CH_CTL(port);
1219 default:
1220 MISSING_CASE(port);
1221 return DP_AUX_CH_CTL(PORT_A);
1222 }
1223}
1224
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001225static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001226 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001227{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001228 switch (port) {
1229 case PORT_A:
1230 case PORT_B:
1231 case PORT_C:
1232 case PORT_D:
1233 return DP_AUX_CH_DATA(port, index);
1234 default:
1235 MISSING_CASE(port);
1236 return DP_AUX_CH_DATA(PORT_A, index);
1237 }
1238}
1239
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001240static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001241 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001242{
1243 if (INTEL_INFO(dev_priv)->gen >= 9)
1244 return skl_aux_ctl_reg(dev_priv, port);
1245 else if (HAS_PCH_SPLIT(dev_priv))
1246 return ilk_aux_ctl_reg(dev_priv, port);
1247 else
1248 return g4x_aux_ctl_reg(dev_priv, port);
1249}
1250
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001251static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001252 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001253{
1254 if (INTEL_INFO(dev_priv)->gen >= 9)
1255 return skl_aux_data_reg(dev_priv, port, index);
1256 else if (HAS_PCH_SPLIT(dev_priv))
1257 return ilk_aux_data_reg(dev_priv, port, index);
1258 else
1259 return g4x_aux_data_reg(dev_priv, port, index);
1260}
1261
1262static void intel_aux_reg_init(struct intel_dp *intel_dp)
1263{
1264 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001265 enum port port = intel_aux_port(dev_priv,
1266 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001267 int i;
1268
1269 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1270 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1271 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1272}
1273
Jani Nikula9d1a1032014-03-14 16:51:15 +02001274static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001275intel_dp_aux_fini(struct intel_dp *intel_dp)
1276{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001277 kfree(intel_dp->aux.name);
1278}
1279
Chris Wilson7a418e32016-06-24 14:00:14 +01001280static void
Mika Kaholab6339582016-09-09 14:10:52 +03001281intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001282{
Jani Nikula33ad6622014-03-14 16:51:16 +02001283 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1284 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001285
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001286 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001287 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001288
Chris Wilson7a418e32016-06-24 14:00:14 +01001289 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001290 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001291 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001292}
1293
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301294static int
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001295intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301296{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001297 if (intel_dp->num_sink_rates) {
1298 *sink_rates = intel_dp->sink_rates;
1299 return intel_dp->num_sink_rates;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301300 }
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001301
1302 *sink_rates = default_rates;
1303
1304 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301305}
1306
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001307bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301308{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001309 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001310 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001311
Navare, Manasi D577c5432016-09-27 16:36:53 -07001312 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1313 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301314 return true;
1315 else
1316 return false;
1317}
1318
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301319static int
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001320intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301321{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001322 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001323 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301324 int size;
1325
Navare, Manasi D577c5432016-09-27 16:36:53 -07001326 if (IS_BROXTON(dev_priv)) {
Sonika Jindal64987fc2015-05-26 17:50:13 +05301327 *source_rates = bxt_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301328 size = ARRAY_SIZE(bxt_rates);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001329 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Sonika Jindal637a9c62015-05-07 09:52:08 +05301330 *source_rates = skl_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301331 size = ARRAY_SIZE(skl_rates);
1332 } else {
1333 *source_rates = default_rates;
1334 size = ARRAY_SIZE(default_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301335 }
Ville Syrjälä636280b2015-03-12 17:10:29 +02001336
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301337 /* This depends on the fact that 5.4 is last value in the array */
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001338 if (!intel_dp_source_supports_hbr2(intel_dp))
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301339 size--;
Ville Syrjälä636280b2015-03-12 17:10:29 +02001340
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301341 return size;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301342}
1343
Daniel Vetter0e503382014-07-04 11:26:04 -03001344static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001345intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001346 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001347{
1348 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001349 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001350 const struct dp_link_dpll *divisor = NULL;
1351 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001352
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001353 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001354 divisor = gen4_dpll;
1355 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001356 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001357 divisor = pch_dpll;
1358 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001359 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001360 divisor = chv_dpll;
1361 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001362 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001363 divisor = vlv_dpll;
1364 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001365 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001366
1367 if (divisor && count) {
1368 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001369 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001370 pipe_config->dpll = divisor[i].dpll;
1371 pipe_config->clock_set = true;
1372 break;
1373 }
1374 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001375 }
1376}
1377
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001378static int intersect_rates(const int *source_rates, int source_len,
1379 const int *sink_rates, int sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001380 int *common_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301381{
1382 int i = 0, j = 0, k = 0;
1383
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301384 while (i < source_len && j < sink_len) {
1385 if (source_rates[i] == sink_rates[j]) {
Ville Syrjäläe6bda3e2015-03-12 17:10:37 +02001386 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
1387 return k;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001388 common_rates[k] = source_rates[i];
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301389 ++k;
1390 ++i;
1391 ++j;
1392 } else if (source_rates[i] < sink_rates[j]) {
1393 ++i;
1394 } else {
1395 ++j;
1396 }
1397 }
1398 return k;
1399}
1400
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001401static int intel_dp_common_rates(struct intel_dp *intel_dp,
1402 int *common_rates)
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001403{
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001404 const int *source_rates, *sink_rates;
1405 int source_len, sink_len;
1406
1407 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001408 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001409
1410 return intersect_rates(source_rates, source_len,
1411 sink_rates, sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001412 common_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001413}
1414
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001415static void snprintf_int_array(char *str, size_t len,
1416 const int *array, int nelem)
1417{
1418 int i;
1419
1420 str[0] = '\0';
1421
1422 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001423 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001424 if (r >= len)
1425 return;
1426 str += r;
1427 len -= r;
1428 }
1429}
1430
1431static void intel_dp_print_rates(struct intel_dp *intel_dp)
1432{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001433 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001434 int source_len, sink_len, common_len;
1435 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001436 char str[128]; /* FIXME: too big for stack? */
1437
1438 if ((drm_debug & DRM_UT_KMS) == 0)
1439 return;
1440
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001441 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001442 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1443 DRM_DEBUG_KMS("source rates: %s\n", str);
1444
1445 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1446 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1447 DRM_DEBUG_KMS("sink rates: %s\n", str);
1448
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001449 common_len = intel_dp_common_rates(intel_dp, common_rates);
1450 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1451 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001452}
1453
Mika Kahola0e390a32016-09-09 14:10:53 +03001454static void intel_dp_print_hw_revision(struct intel_dp *intel_dp)
1455{
1456 uint8_t rev;
1457 int len;
1458
1459 if ((drm_debug & DRM_UT_KMS) == 0)
1460 return;
1461
1462 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1463 DP_DWN_STRM_PORT_PRESENT))
1464 return;
1465
1466 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_HW_REV, &rev, 1);
1467 if (len < 0)
1468 return;
1469
1470 DRM_DEBUG_KMS("sink hw revision: %d.%d\n", (rev & 0xf0) >> 4, rev & 0xf);
1471}
1472
Mika Kahola1a2724f2016-09-09 14:10:54 +03001473static void intel_dp_print_sw_revision(struct intel_dp *intel_dp)
1474{
1475 uint8_t rev[2];
1476 int len;
1477
1478 if ((drm_debug & DRM_UT_KMS) == 0)
1479 return;
1480
1481 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1482 DP_DWN_STRM_PORT_PRESENT))
1483 return;
1484
1485 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_SW_REV, &rev, 2);
1486 if (len < 0)
1487 return;
1488
1489 DRM_DEBUG_KMS("sink sw revision: %d.%d\n", rev[0], rev[1]);
1490}
1491
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001492static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301493{
1494 int i = 0;
1495
1496 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1497 if (find == rates[i])
1498 break;
1499
1500 return i;
1501}
1502
Ville Syrjälä50fec212015-03-12 17:10:34 +02001503int
1504intel_dp_max_link_rate(struct intel_dp *intel_dp)
1505{
1506 int rates[DP_MAX_SUPPORTED_RATES] = {};
1507 int len;
1508
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001509 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001510 if (WARN_ON(len <= 0))
1511 return 162000;
1512
Ville Syrjälä1354f732016-07-28 17:50:45 +03001513 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001514}
1515
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001516int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1517{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001518 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001519}
1520
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001521void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1522 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001523{
1524 if (intel_dp->num_sink_rates) {
1525 *link_bw = 0;
1526 *rate_select =
1527 intel_dp_rate_select(intel_dp, port_clock);
1528 } else {
1529 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1530 *rate_select = 0;
1531 }
1532}
1533
Jani Nikulaf580bea2016-09-15 16:28:52 +03001534static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1535 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001536{
1537 int bpp, bpc;
1538
1539 bpp = pipe_config->pipe_bpp;
1540 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1541
1542 if (bpc > 0)
1543 bpp = min(bpp, 3*bpc);
1544
1545 return bpp;
1546}
1547
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001548bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001549intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001550 struct intel_crtc_state *pipe_config,
1551 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001552{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001553 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001554 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001555 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001556 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001557 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001558 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001559 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001560 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001561 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001562 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001563 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001564 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301565 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001566 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001567 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001568 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1569 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001570 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301571
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001572 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301573
1574 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001575 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301576
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001577 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001578
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001579 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001580 pipe_config->has_pch_encoder = true;
1581
Vandana Kannanf769cd22014-08-05 07:51:22 -07001582 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001583 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001584
Jani Nikuladd06f902012-10-19 14:51:50 +03001585 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1586 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1587 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001588
1589 if (INTEL_INFO(dev)->gen >= 9) {
1590 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001591 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001592 if (ret)
1593 return ret;
1594 }
1595
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001596 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001597 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1598 intel_connector->panel.fitting_mode);
1599 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001600 intel_pch_panel_fitting(intel_crtc, pipe_config,
1601 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001602 }
1603
Daniel Vettercb1793c2012-06-04 18:39:21 +02001604 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001605 return false;
1606
Daniel Vetter083f9562012-04-20 20:23:49 +02001607 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301608 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001609 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001610 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001611
Daniel Vetter36008362013-03-27 00:44:59 +01001612 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1613 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001614 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001615 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301616
1617 /* Get bpp from vbt only for panels that dont have bpp in edid */
1618 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001619 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001620 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001621 dev_priv->vbt.edp.bpp);
1622 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001623 }
1624
Jani Nikula344c5bb2014-09-09 11:25:13 +03001625 /*
1626 * Use the maximum clock and number of lanes the eDP panel
1627 * advertizes being capable of. The panels are generally
1628 * designed to support only a single clock and lane
1629 * configuration, and typically these values correspond to the
1630 * native resolution of the panel.
1631 */
1632 min_lane_count = max_lane_count;
1633 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001634 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001635
Daniel Vetter36008362013-03-27 00:44:59 +01001636 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001637 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1638 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001639
Dave Airliec6930992014-07-14 11:04:39 +10001640 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301641 for (lane_count = min_lane_count;
1642 lane_count <= max_lane_count;
1643 lane_count <<= 1) {
1644
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001645 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001646 link_avail = intel_dp_max_data_rate(link_clock,
1647 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001648
Daniel Vetter36008362013-03-27 00:44:59 +01001649 if (mode_rate <= link_avail) {
1650 goto found;
1651 }
1652 }
1653 }
1654 }
1655
1656 return false;
1657
1658found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001659 if (intel_dp->color_range_auto) {
1660 /*
1661 * See:
1662 * CEA-861-E - 5.1 Default Encoding Parameters
1663 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1664 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001665 pipe_config->limited_color_range =
1666 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1667 } else {
1668 pipe_config->limited_color_range =
1669 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001670 }
1671
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001672 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301673
Daniel Vetter657445f2013-05-04 10:09:18 +02001674 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001675 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001676
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001677 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1678 &link_bw, &rate_select);
1679
1680 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1681 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001682 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001683 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1684 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001685
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001686 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001687 adjusted_mode->crtc_clock,
1688 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001689 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001690
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301691 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301692 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001693 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301694 intel_link_compute_m_n(bpp, lane_count,
1695 intel_connector->panel.downclock_mode->clock,
1696 pipe_config->port_clock,
1697 &pipe_config->dp_m2_n2);
1698 }
1699
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001700 /*
1701 * DPLL0 VCO may need to be adjusted to get the correct
1702 * clock for eDP. This will affect cdclk as well.
1703 */
1704 if (is_edp(intel_dp) &&
1705 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1706 int vco;
1707
1708 switch (pipe_config->port_clock / 2) {
1709 case 108000:
1710 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001711 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001712 break;
1713 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001714 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001715 break;
1716 }
1717
1718 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1719 }
1720
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001721 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001722 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001723
Daniel Vetter36008362013-03-27 00:44:59 +01001724 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001725}
1726
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001727void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001728 int link_rate, uint8_t lane_count,
1729 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001730{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001731 intel_dp->link_rate = link_rate;
1732 intel_dp->lane_count = lane_count;
1733 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001734}
1735
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001736static void intel_dp_prepare(struct intel_encoder *encoder,
1737 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001738{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001739 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001740 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001741 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001742 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001743 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001744 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001745
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001746 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1747 pipe_config->lane_count,
1748 intel_crtc_has_type(pipe_config,
1749 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001750
Keith Packard417e8222011-11-01 19:54:11 -07001751 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001752 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001753 *
1754 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001755 * SNB CPU
1756 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001757 * CPT PCH
1758 *
1759 * IBX PCH and CPU are the same for almost everything,
1760 * except that the CPU DP PLL is configured in this
1761 * register
1762 *
1763 * CPT PCH is quite different, having many bits moved
1764 * to the TRANS_DP_CTL register instead. That
1765 * configuration happens (oddly) in ironlake_pch_enable
1766 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001767
Keith Packard417e8222011-11-01 19:54:11 -07001768 /* Preserve the BIOS-computed detected bit. This is
1769 * supposed to be read-only.
1770 */
1771 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001772
Keith Packard417e8222011-11-01 19:54:11 -07001773 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001774 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001775 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001776
Keith Packard417e8222011-11-01 19:54:11 -07001777 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001778
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001779 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001780 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1781 intel_dp->DP |= DP_SYNC_HS_HIGH;
1782 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1783 intel_dp->DP |= DP_SYNC_VS_HIGH;
1784 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1785
Jani Nikula6aba5b62013-10-04 15:08:10 +03001786 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001787 intel_dp->DP |= DP_ENHANCED_FRAMING;
1788
Daniel Vetter7c62a162013-06-01 17:16:20 +02001789 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001790 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001791 u32 trans_dp;
1792
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001793 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001794
1795 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1796 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1797 trans_dp |= TRANS_DP_ENH_FRAMING;
1798 else
1799 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1800 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001801 } else {
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001802 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001803 !IS_CHERRYVIEW(dev_priv) &&
1804 pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001805 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001806
1807 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1808 intel_dp->DP |= DP_SYNC_HS_HIGH;
1809 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1810 intel_dp->DP |= DP_SYNC_VS_HIGH;
1811 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1812
Jani Nikula6aba5b62013-10-04 15:08:10 +03001813 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001814 intel_dp->DP |= DP_ENHANCED_FRAMING;
1815
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001816 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001817 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001818 else if (crtc->pipe == PIPE_B)
1819 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001820 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001821}
1822
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001823#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1824#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001825
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001826#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1827#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001828
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001829#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1830#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001831
Imre Deakde9c1b62016-06-16 20:01:46 +03001832static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1833 struct intel_dp *intel_dp);
1834
Daniel Vetter4be73782014-01-17 14:39:48 +01001835static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001836 u32 mask,
1837 u32 value)
1838{
Paulo Zanoni30add222012-10-26 19:05:45 -02001839 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001840 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001841 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001842
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001843 lockdep_assert_held(&dev_priv->pps_mutex);
1844
Imre Deakde9c1b62016-06-16 20:01:46 +03001845 intel_pps_verify_state(dev_priv, intel_dp);
1846
Jani Nikulabf13e812013-09-06 07:40:05 +03001847 pp_stat_reg = _pp_stat_reg(intel_dp);
1848 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001849
1850 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001851 mask, value,
1852 I915_READ(pp_stat_reg),
1853 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001854
Chris Wilson9036ff02016-06-30 15:33:09 +01001855 if (intel_wait_for_register(dev_priv,
1856 pp_stat_reg, mask, value,
1857 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001858 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001859 I915_READ(pp_stat_reg),
1860 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001861
1862 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001863}
1864
Daniel Vetter4be73782014-01-17 14:39:48 +01001865static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001866{
1867 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001868 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001869}
1870
Daniel Vetter4be73782014-01-17 14:39:48 +01001871static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001872{
Keith Packardbd943152011-09-18 23:09:52 -07001873 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001874 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001875}
Keith Packardbd943152011-09-18 23:09:52 -07001876
Daniel Vetter4be73782014-01-17 14:39:48 +01001877static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001878{
Abhay Kumard28d4732016-01-22 17:39:04 -08001879 ktime_t panel_power_on_time;
1880 s64 panel_power_off_duration;
1881
Keith Packard99ea7122011-11-01 19:57:50 -07001882 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001883
Abhay Kumard28d4732016-01-22 17:39:04 -08001884 /* take the difference of currrent time and panel power off time
1885 * and then make panel wait for t11_t12 if needed. */
1886 panel_power_on_time = ktime_get_boottime();
1887 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1888
Paulo Zanonidce56b32013-12-19 14:29:40 -02001889 /* When we disable the VDD override bit last we have to do the manual
1890 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001891 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1892 wait_remaining_ms_from_jiffies(jiffies,
1893 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001894
Daniel Vetter4be73782014-01-17 14:39:48 +01001895 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001896}
Keith Packardbd943152011-09-18 23:09:52 -07001897
Daniel Vetter4be73782014-01-17 14:39:48 +01001898static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001899{
1900 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1901 intel_dp->backlight_on_delay);
1902}
1903
Daniel Vetter4be73782014-01-17 14:39:48 +01001904static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001905{
1906 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1907 intel_dp->backlight_off_delay);
1908}
Keith Packard99ea7122011-11-01 19:57:50 -07001909
Keith Packard832dd3c2011-11-01 19:34:06 -07001910/* Read the current pp_control value, unlocking the register if it
1911 * is locked
1912 */
1913
Jesse Barnes453c5422013-03-28 09:55:41 -07001914static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001915{
Jesse Barnes453c5422013-03-28 09:55:41 -07001916 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001917 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001918 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001919
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001920 lockdep_assert_held(&dev_priv->pps_mutex);
1921
Jani Nikulabf13e812013-09-06 07:40:05 +03001922 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001923 if (WARN_ON(!HAS_DDI(dev_priv) &&
1924 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301925 control &= ~PANEL_UNLOCK_MASK;
1926 control |= PANEL_UNLOCK_REGS;
1927 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001928 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001929}
1930
Ville Syrjälä951468f2014-09-04 14:55:31 +03001931/*
1932 * Must be paired with edp_panel_vdd_off().
1933 * Must hold pps_mutex around the whole on/off sequence.
1934 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1935 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001936static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001937{
Paulo Zanoni30add222012-10-26 19:05:45 -02001938 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001939 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1940 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001941 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001942 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001943 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001944 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001945 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001946
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001947 lockdep_assert_held(&dev_priv->pps_mutex);
1948
Keith Packard97af61f572011-09-28 16:23:51 -07001949 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001950 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001951
Egbert Eich2c623c12014-11-25 12:54:57 +01001952 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001953 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001954
Daniel Vetter4be73782014-01-17 14:39:48 +01001955 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001956 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001957
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001958 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001959 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001960
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001961 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1962 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001963
Daniel Vetter4be73782014-01-17 14:39:48 +01001964 if (!edp_have_panel_power(intel_dp))
1965 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001966
Jesse Barnes453c5422013-03-28 09:55:41 -07001967 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001968 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001969
Jani Nikulabf13e812013-09-06 07:40:05 +03001970 pp_stat_reg = _pp_stat_reg(intel_dp);
1971 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001972
1973 I915_WRITE(pp_ctrl_reg, pp);
1974 POSTING_READ(pp_ctrl_reg);
1975 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1976 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001977 /*
1978 * If the panel wasn't on, delay before accessing aux channel
1979 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001980 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001981 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1982 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001983 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001984 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001985
1986 return need_to_disable;
1987}
1988
Ville Syrjälä951468f2014-09-04 14:55:31 +03001989/*
1990 * Must be paired with intel_edp_panel_vdd_off() or
1991 * intel_edp_panel_off().
1992 * Nested calls to these functions are not allowed since
1993 * we drop the lock. Caller must use some higher level
1994 * locking to prevent nested calls from other threads.
1995 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001996void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001997{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001998 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001999
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002000 if (!is_edp(intel_dp))
2001 return;
2002
Ville Syrjälä773538e82014-09-04 14:54:56 +03002003 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002004 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002005 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002006
Rob Clarke2c719b2014-12-15 13:56:32 -05002007 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002008 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002009}
2010
Daniel Vetter4be73782014-01-17 14:39:48 +01002011static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002012{
Paulo Zanoni30add222012-10-26 19:05:45 -02002013 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002014 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002015 struct intel_digital_port *intel_dig_port =
2016 dp_to_dig_port(intel_dp);
2017 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2018 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002019 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002020 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002021
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002022 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002023
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002024 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002025
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002026 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002027 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002028
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002029 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2030 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002031
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002032 pp = ironlake_get_pp_control(intel_dp);
2033 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002034
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002035 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2036 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002037
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002038 I915_WRITE(pp_ctrl_reg, pp);
2039 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002040
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002041 /* Make sure sequencer is idle before allowing subsequent activity */
2042 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2043 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002044
Imre Deak5a162e22016-08-10 14:07:30 +03002045 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002046 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002047
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002048 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002049 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002050}
2051
Daniel Vetter4be73782014-01-17 14:39:48 +01002052static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002053{
2054 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2055 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002056
Ville Syrjälä773538e82014-09-04 14:54:56 +03002057 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002058 if (!intel_dp->want_panel_vdd)
2059 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002060 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002061}
2062
Imre Deakaba86892014-07-30 15:57:31 +03002063static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2064{
2065 unsigned long delay;
2066
2067 /*
2068 * Queue the timer to fire a long time from now (relative to the power
2069 * down delay) to keep the panel power up across a sequence of
2070 * operations.
2071 */
2072 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2073 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2074}
2075
Ville Syrjälä951468f2014-09-04 14:55:31 +03002076/*
2077 * Must be paired with edp_panel_vdd_on().
2078 * Must hold pps_mutex around the whole on/off sequence.
2079 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2080 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002081static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002082{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002083 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002084
2085 lockdep_assert_held(&dev_priv->pps_mutex);
2086
Keith Packard97af61f572011-09-28 16:23:51 -07002087 if (!is_edp(intel_dp))
2088 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002089
Rob Clarke2c719b2014-12-15 13:56:32 -05002090 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002091 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002092
Keith Packardbd943152011-09-18 23:09:52 -07002093 intel_dp->want_panel_vdd = false;
2094
Imre Deakaba86892014-07-30 15:57:31 +03002095 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002096 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002097 else
2098 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002099}
2100
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002101static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002102{
Paulo Zanoni30add222012-10-26 19:05:45 -02002103 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002104 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002105 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002106 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002107
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002108 lockdep_assert_held(&dev_priv->pps_mutex);
2109
Keith Packard97af61f572011-09-28 16:23:51 -07002110 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002111 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002112
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002113 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2114 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002115
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002116 if (WARN(edp_have_panel_power(intel_dp),
2117 "eDP port %c panel power already on\n",
2118 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002119 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002120
Daniel Vetter4be73782014-01-17 14:39:48 +01002121 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002122
Jani Nikulabf13e812013-09-06 07:40:05 +03002123 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002124 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002125 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002126 /* ILK workaround: disable reset around power sequence */
2127 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002128 I915_WRITE(pp_ctrl_reg, pp);
2129 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002130 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002131
Imre Deak5a162e22016-08-10 14:07:30 +03002132 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002133 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002134 pp |= PANEL_POWER_RESET;
2135
Jesse Barnes453c5422013-03-28 09:55:41 -07002136 I915_WRITE(pp_ctrl_reg, pp);
2137 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002138
Daniel Vetter4be73782014-01-17 14:39:48 +01002139 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002140 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002141
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002142 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002143 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002144 I915_WRITE(pp_ctrl_reg, pp);
2145 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002146 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002147}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002148
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002149void intel_edp_panel_on(struct intel_dp *intel_dp)
2150{
2151 if (!is_edp(intel_dp))
2152 return;
2153
2154 pps_lock(intel_dp);
2155 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002156 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002157}
2158
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002159
2160static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002161{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002162 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2163 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002164 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002165 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002166 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002167 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002168 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002169
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002170 lockdep_assert_held(&dev_priv->pps_mutex);
2171
Keith Packard97af61f572011-09-28 16:23:51 -07002172 if (!is_edp(intel_dp))
2173 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002174
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002175 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2176 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002177
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002178 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2179 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002180
Jesse Barnes453c5422013-03-28 09:55:41 -07002181 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002182 /* We need to switch off panel power _and_ force vdd, for otherwise some
2183 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002184 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002185 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002186
Jani Nikulabf13e812013-09-06 07:40:05 +03002187 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002188
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002189 intel_dp->want_panel_vdd = false;
2190
Jesse Barnes453c5422013-03-28 09:55:41 -07002191 I915_WRITE(pp_ctrl_reg, pp);
2192 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002193
Abhay Kumard28d4732016-01-22 17:39:04 -08002194 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002195 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002196
2197 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002198 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002199 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002200}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002201
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002202void intel_edp_panel_off(struct intel_dp *intel_dp)
2203{
2204 if (!is_edp(intel_dp))
2205 return;
2206
2207 pps_lock(intel_dp);
2208 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002209 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002210}
2211
Jani Nikula1250d102014-08-12 17:11:39 +03002212/* Enable backlight in the panel power control. */
2213static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002214{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002215 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2216 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002217 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002218 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002219 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002220
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002221 /*
2222 * If we enable the backlight right away following a panel power
2223 * on, we may see slight flicker as the panel syncs with the eDP
2224 * link. So delay a bit to make sure the image is solid before
2225 * allowing it to appear.
2226 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002227 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002228
Ville Syrjälä773538e82014-09-04 14:54:56 +03002229 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002230
Jesse Barnes453c5422013-03-28 09:55:41 -07002231 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002232 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002233
Jani Nikulabf13e812013-09-06 07:40:05 +03002234 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002235
2236 I915_WRITE(pp_ctrl_reg, pp);
2237 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002238
Ville Syrjälä773538e82014-09-04 14:54:56 +03002239 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002240}
2241
Jani Nikula1250d102014-08-12 17:11:39 +03002242/* Enable backlight PWM and backlight PP control. */
2243void intel_edp_backlight_on(struct intel_dp *intel_dp)
2244{
2245 if (!is_edp(intel_dp))
2246 return;
2247
2248 DRM_DEBUG_KMS("\n");
2249
2250 intel_panel_enable_backlight(intel_dp->attached_connector);
2251 _intel_edp_backlight_on(intel_dp);
2252}
2253
2254/* Disable backlight in the panel power control. */
2255static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002256{
Paulo Zanoni30add222012-10-26 19:05:45 -02002257 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002258 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002259 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002260 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002261
Keith Packardf01eca22011-09-28 16:48:10 -07002262 if (!is_edp(intel_dp))
2263 return;
2264
Ville Syrjälä773538e82014-09-04 14:54:56 +03002265 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002266
Jesse Barnes453c5422013-03-28 09:55:41 -07002267 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002268 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002269
Jani Nikulabf13e812013-09-06 07:40:05 +03002270 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002271
2272 I915_WRITE(pp_ctrl_reg, pp);
2273 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002274
Ville Syrjälä773538e82014-09-04 14:54:56 +03002275 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002276
Paulo Zanonidce56b32013-12-19 14:29:40 -02002277 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002278 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002279}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002280
Jani Nikula1250d102014-08-12 17:11:39 +03002281/* Disable backlight PP control and backlight PWM. */
2282void intel_edp_backlight_off(struct intel_dp *intel_dp)
2283{
2284 if (!is_edp(intel_dp))
2285 return;
2286
2287 DRM_DEBUG_KMS("\n");
2288
2289 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002290 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002291}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002292
Jani Nikula73580fb72014-08-12 17:11:41 +03002293/*
2294 * Hook for controlling the panel power control backlight through the bl_power
2295 * sysfs attribute. Take care to handle multiple calls.
2296 */
2297static void intel_edp_backlight_power(struct intel_connector *connector,
2298 bool enable)
2299{
2300 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002301 bool is_enabled;
2302
Ville Syrjälä773538e82014-09-04 14:54:56 +03002303 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002304 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002305 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002306
2307 if (is_enabled == enable)
2308 return;
2309
Jani Nikula23ba9372014-08-27 14:08:43 +03002310 DRM_DEBUG_KMS("panel power control backlight %s\n",
2311 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002312
2313 if (enable)
2314 _intel_edp_backlight_on(intel_dp);
2315 else
2316 _intel_edp_backlight_off(intel_dp);
2317}
2318
Ville Syrjälä64e10772015-10-29 21:26:01 +02002319static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2320{
2321 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2322 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2323 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2324
2325 I915_STATE_WARN(cur_state != state,
2326 "DP port %c state assertion failure (expected %s, current %s)\n",
2327 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002328 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002329}
2330#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2331
2332static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2333{
2334 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2335
2336 I915_STATE_WARN(cur_state != state,
2337 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002338 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002339}
2340#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2341#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2342
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002343static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2344 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002345{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002346 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002347 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002348
Ville Syrjälä64e10772015-10-29 21:26:01 +02002349 assert_pipe_disabled(dev_priv, crtc->pipe);
2350 assert_dp_port_disabled(intel_dp);
2351 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002352
Ville Syrjäläabfce942015-10-29 21:26:03 +02002353 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002354 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002355
2356 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2357
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002358 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002359 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2360 else
2361 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2362
2363 I915_WRITE(DP_A, intel_dp->DP);
2364 POSTING_READ(DP_A);
2365 udelay(500);
2366
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002367 /*
2368 * [DevILK] Work around required when enabling DP PLL
2369 * while a pipe is enabled going to FDI:
2370 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2371 * 2. Program DP PLL enable
2372 */
2373 if (IS_GEN5(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +01002374 intel_wait_for_vblank_if_active(&dev_priv->drm, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002375
Daniel Vetter07679352012-09-06 22:15:42 +02002376 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002377
Daniel Vetter07679352012-09-06 22:15:42 +02002378 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002379 POSTING_READ(DP_A);
2380 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002381}
2382
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002383static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002384{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002385 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002386 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2387 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002388
Ville Syrjälä64e10772015-10-29 21:26:01 +02002389 assert_pipe_disabled(dev_priv, crtc->pipe);
2390 assert_dp_port_disabled(intel_dp);
2391 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002392
Ville Syrjäläabfce942015-10-29 21:26:03 +02002393 DRM_DEBUG_KMS("disabling eDP PLL\n");
2394
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002395 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002396
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002397 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002398 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002399 udelay(200);
2400}
2401
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002402/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002403void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002404{
2405 int ret, i;
2406
2407 /* Should have a valid DPCD by this point */
2408 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2409 return;
2410
2411 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002412 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2413 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002414 } else {
2415 /*
2416 * When turning on, we need to retry for 1ms to give the sink
2417 * time to wake up.
2418 */
2419 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002420 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2421 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002422 if (ret == 1)
2423 break;
2424 msleep(1);
2425 }
2426 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002427
2428 if (ret != 1)
2429 DRM_DEBUG_KMS("failed to %s sink power state\n",
2430 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002431}
2432
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002433static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2434 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002435{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002436 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002437 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002438 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002439 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002440 enum intel_display_power_domain power_domain;
2441 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002442 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002443
2444 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002445 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002446 return false;
2447
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002448 ret = false;
2449
Imre Deak6d129be2014-03-05 16:20:54 +02002450 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002451
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002452 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002453 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002454
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002455 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002456 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002457 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002458 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002459
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002460 for_each_pipe(dev_priv, p) {
2461 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2462 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2463 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002464 ret = true;
2465
2466 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002467 }
2468 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002469
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002470 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002471 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002472 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002473 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2474 } else {
2475 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002476 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002477
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002478 ret = true;
2479
2480out:
2481 intel_display_power_put(dev_priv, power_domain);
2482
2483 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002484}
2485
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002486static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002487 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002488{
2489 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002490 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002491 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002492 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002493 enum port port = dp_to_dig_port(intel_dp)->port;
2494 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002495
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002496 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002497
2498 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002499
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002500 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002501 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2502
2503 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002504 flags |= DRM_MODE_FLAG_PHSYNC;
2505 else
2506 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002507
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002508 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002509 flags |= DRM_MODE_FLAG_PVSYNC;
2510 else
2511 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002512 } else {
2513 if (tmp & DP_SYNC_HS_HIGH)
2514 flags |= DRM_MODE_FLAG_PHSYNC;
2515 else
2516 flags |= DRM_MODE_FLAG_NHSYNC;
2517
2518 if (tmp & DP_SYNC_VS_HIGH)
2519 flags |= DRM_MODE_FLAG_PVSYNC;
2520 else
2521 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002522 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002523
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002524 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002525
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002526 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
2527 !IS_CHERRYVIEW(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002528 pipe_config->limited_color_range = true;
2529
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002530 pipe_config->lane_count =
2531 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2532
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002533 intel_dp_get_m_n(crtc, pipe_config);
2534
Ville Syrjälä18442d02013-09-13 16:00:08 +03002535 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002536 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002537 pipe_config->port_clock = 162000;
2538 else
2539 pipe_config->port_clock = 270000;
2540 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002541
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002542 pipe_config->base.adjusted_mode.crtc_clock =
2543 intel_dotclock_calculate(pipe_config->port_clock,
2544 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002545
Jani Nikula6aa23e62016-03-24 17:50:20 +02002546 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2547 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002548 /*
2549 * This is a big fat ugly hack.
2550 *
2551 * Some machines in UEFI boot mode provide us a VBT that has 18
2552 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2553 * unknown we fail to light up. Yet the same BIOS boots up with
2554 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2555 * max, not what it tells us to use.
2556 *
2557 * Note: This will still be broken if the eDP panel is not lit
2558 * up by the BIOS, and thus we can't get the mode at module
2559 * load.
2560 */
2561 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002562 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2563 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002564 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002565}
2566
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002567static void intel_disable_dp(struct intel_encoder *encoder,
2568 struct intel_crtc_state *old_crtc_state,
2569 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002570{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002571 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002572 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002573
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002574 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002575 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002576
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002577 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002578 intel_psr_disable(intel_dp);
2579
Daniel Vetter6cb49832012-05-20 17:14:50 +02002580 /* Make sure the panel is off before trying to change the mode. But also
2581 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002582 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002583 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002584 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002585 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002586
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002587 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002588 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002589 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002590}
2591
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002592static void ilk_post_disable_dp(struct intel_encoder *encoder,
2593 struct intel_crtc_state *old_crtc_state,
2594 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002595{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002596 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002597 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002598
Ville Syrjälä49277c32014-03-31 18:21:26 +03002599 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002600
2601 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002602 if (port == PORT_A)
2603 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002604}
2605
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002606static void vlv_post_disable_dp(struct intel_encoder *encoder,
2607 struct intel_crtc_state *old_crtc_state,
2608 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002609{
2610 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2611
2612 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002613}
2614
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002615static void chv_post_disable_dp(struct intel_encoder *encoder,
2616 struct intel_crtc_state *old_crtc_state,
2617 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002618{
2619 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002620 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002621 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002622
2623 intel_dp_link_down(intel_dp);
2624
Ville Syrjäläa5805162015-05-26 20:42:30 +03002625 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002626
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002627 /* Assert data lane reset */
2628 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002629
Ville Syrjäläa5805162015-05-26 20:42:30 +03002630 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002631}
2632
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002633static void
2634_intel_dp_set_link_train(struct intel_dp *intel_dp,
2635 uint32_t *DP,
2636 uint8_t dp_train_pat)
2637{
2638 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2639 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002640 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002641 enum port port = intel_dig_port->port;
2642
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002643 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2644 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2645 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2646
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002647 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002648 uint32_t temp = I915_READ(DP_TP_CTL(port));
2649
2650 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2651 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2652 else
2653 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2654
2655 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2656 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2657 case DP_TRAINING_PATTERN_DISABLE:
2658 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2659
2660 break;
2661 case DP_TRAINING_PATTERN_1:
2662 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2663 break;
2664 case DP_TRAINING_PATTERN_2:
2665 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2666 break;
2667 case DP_TRAINING_PATTERN_3:
2668 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2669 break;
2670 }
2671 I915_WRITE(DP_TP_CTL(port), temp);
2672
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002673 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002674 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002675 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2676
2677 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2678 case DP_TRAINING_PATTERN_DISABLE:
2679 *DP |= DP_LINK_TRAIN_OFF_CPT;
2680 break;
2681 case DP_TRAINING_PATTERN_1:
2682 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2683 break;
2684 case DP_TRAINING_PATTERN_2:
2685 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2686 break;
2687 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002688 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002689 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2690 break;
2691 }
2692
2693 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002694 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002695 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2696 else
2697 *DP &= ~DP_LINK_TRAIN_MASK;
2698
2699 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2700 case DP_TRAINING_PATTERN_DISABLE:
2701 *DP |= DP_LINK_TRAIN_OFF;
2702 break;
2703 case DP_TRAINING_PATTERN_1:
2704 *DP |= DP_LINK_TRAIN_PAT_1;
2705 break;
2706 case DP_TRAINING_PATTERN_2:
2707 *DP |= DP_LINK_TRAIN_PAT_2;
2708 break;
2709 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002710 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002711 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2712 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002713 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002714 *DP |= DP_LINK_TRAIN_PAT_2;
2715 }
2716 break;
2717 }
2718 }
2719}
2720
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002721static void intel_dp_enable_port(struct intel_dp *intel_dp,
2722 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002723{
2724 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002725 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002726
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002727 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002728
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002729 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002730
2731 /*
2732 * Magic for VLV/CHV. We _must_ first set up the register
2733 * without actually enabling the port, and then do another
2734 * write to enable the port. Otherwise link training will
2735 * fail when the power sequencer is freshly used for this port.
2736 */
2737 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002738 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002739 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002740
2741 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2742 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002743}
2744
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002745static void intel_enable_dp(struct intel_encoder *encoder,
2746 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002747{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002748 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2749 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002750 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002751 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002752 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002753 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002754
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002755 if (WARN_ON(dp_reg & DP_PORT_EN))
2756 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002757
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002758 pps_lock(intel_dp);
2759
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002760 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002761 vlv_init_panel_power_sequencer(intel_dp);
2762
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002763 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002764
2765 edp_panel_vdd_on(intel_dp);
2766 edp_panel_on(intel_dp);
2767 edp_panel_vdd_off(intel_dp, true);
2768
2769 pps_unlock(intel_dp);
2770
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002771 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002772 unsigned int lane_mask = 0x0;
2773
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002774 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002775 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002776
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002777 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2778 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002779 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002780
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002781 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2782 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002783 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002784
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002785 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002786 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002787 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002788 intel_audio_codec_enable(encoder);
2789 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002790}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002791
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002792static void g4x_enable_dp(struct intel_encoder *encoder,
2793 struct intel_crtc_state *pipe_config,
2794 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002795{
Jani Nikula828f5c62013-09-05 16:44:45 +03002796 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2797
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002798 intel_enable_dp(encoder, pipe_config);
Daniel Vetter4be73782014-01-17 14:39:48 +01002799 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002800}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002801
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002802static void vlv_enable_dp(struct intel_encoder *encoder,
2803 struct intel_crtc_state *pipe_config,
2804 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002805{
Jani Nikula828f5c62013-09-05 16:44:45 +03002806 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2807
Daniel Vetter4be73782014-01-17 14:39:48 +01002808 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002809 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002810}
2811
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002812static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2813 struct intel_crtc_state *pipe_config,
2814 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002815{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002816 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002817 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002818
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002819 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002820
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002821 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002822 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002823 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002824}
2825
Ville Syrjälä83b84592014-10-16 21:29:51 +03002826static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2827{
2828 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002829 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002830 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002831 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002832
2833 edp_panel_vdd_off_sync(intel_dp);
2834
2835 /*
2836 * VLV seems to get confused when multiple power seqeuencers
2837 * have the same port selected (even if only one has power/vdd
2838 * enabled). The failure manifests as vlv_wait_port_ready() failing
2839 * CHV on the other hand doesn't seem to mind having the same port
2840 * selected in multiple power seqeuencers, but let's clear the
2841 * port select always when logically disconnecting a power sequencer
2842 * from a port.
2843 */
2844 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2845 pipe_name(pipe), port_name(intel_dig_port->port));
2846 I915_WRITE(pp_on_reg, 0);
2847 POSTING_READ(pp_on_reg);
2848
2849 intel_dp->pps_pipe = INVALID_PIPE;
2850}
2851
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002852static void vlv_steal_power_sequencer(struct drm_device *dev,
2853 enum pipe pipe)
2854{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002855 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002856 struct intel_encoder *encoder;
2857
2858 lockdep_assert_held(&dev_priv->pps_mutex);
2859
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002860 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2861 return;
2862
Jani Nikula19c80542015-12-16 12:48:16 +02002863 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002864 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002865 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002866
2867 if (encoder->type != INTEL_OUTPUT_EDP)
2868 continue;
2869
2870 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002871 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002872
2873 if (intel_dp->pps_pipe != pipe)
2874 continue;
2875
2876 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002877 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002878
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002879 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002880 "stealing pipe %c power sequencer from active eDP port %c\n",
2881 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002882
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002883 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002884 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002885 }
2886}
2887
2888static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2889{
2890 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2891 struct intel_encoder *encoder = &intel_dig_port->base;
2892 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002893 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002894 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002895
2896 lockdep_assert_held(&dev_priv->pps_mutex);
2897
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002898 if (!is_edp(intel_dp))
2899 return;
2900
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002901 if (intel_dp->pps_pipe == crtc->pipe)
2902 return;
2903
2904 /*
2905 * If another power sequencer was being used on this
2906 * port previously make sure to turn off vdd there while
2907 * we still have control of it.
2908 */
2909 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002910 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002911
2912 /*
2913 * We may be stealing the power
2914 * sequencer from another port.
2915 */
2916 vlv_steal_power_sequencer(dev, crtc->pipe);
2917
2918 /* now it's all ours */
2919 intel_dp->pps_pipe = crtc->pipe;
2920
2921 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2922 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2923
2924 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002925 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2926 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002927}
2928
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002929static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2930 struct intel_crtc_state *pipe_config,
2931 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002932{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002933 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002934
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002935 intel_enable_dp(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002936}
2937
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002938static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2939 struct intel_crtc_state *pipe_config,
2940 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002941{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002942 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002943
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002944 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002945}
2946
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002947static void chv_pre_enable_dp(struct intel_encoder *encoder,
2948 struct intel_crtc_state *pipe_config,
2949 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002950{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002951 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002952
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002953 intel_enable_dp(encoder, pipe_config);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002954
2955 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002956 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002957}
2958
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002959static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2960 struct intel_crtc_state *pipe_config,
2961 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002962{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002963 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002964
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002965 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002966}
2967
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002968static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2969 struct intel_crtc_state *pipe_config,
2970 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002971{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002972 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002973}
2974
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002975/*
2976 * Fetch AUX CH registers 0x202 - 0x207 which contain
2977 * link status information
2978 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002979bool
Keith Packard93f62da2011-11-01 19:45:03 -07002980intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002981{
Lyude9f085eb2016-04-13 10:58:33 -04002982 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2983 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002984}
2985
Paulo Zanoni11002442014-06-13 18:45:41 -03002986/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002987uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002988intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002989{
Paulo Zanoni30add222012-10-26 19:05:45 -02002990 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002991 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002992 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002993
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002994 if (IS_BROXTON(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05302995 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2996 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002997 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302998 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002999 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003000 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303001 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003002 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303003 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003004 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303005 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003006 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303007 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003008}
3009
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003010uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003011intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3012{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003013 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003014 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003015
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003016 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003017 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3018 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3019 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3020 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3021 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3022 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3023 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303024 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3025 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003026 default:
3027 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3028 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003029 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003030 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303031 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3032 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3033 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3034 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3035 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3036 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3037 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003038 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303039 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003040 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003041 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003042 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303043 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3044 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3045 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3046 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3047 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3048 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3049 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003050 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303051 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003052 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003053 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003054 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303055 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3056 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3057 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3058 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3059 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003060 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303061 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003062 }
3063 } else {
3064 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303065 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3066 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3067 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3068 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3069 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3070 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3071 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003072 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303073 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003074 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003075 }
3076}
3077
Daniel Vetter5829975c2015-04-16 11:36:52 +02003078static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003079{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003080 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003081 unsigned long demph_reg_value, preemph_reg_value,
3082 uniqtranscale_reg_value;
3083 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003084
3085 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303086 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003087 preemph_reg_value = 0x0004000;
3088 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303089 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003090 demph_reg_value = 0x2B405555;
3091 uniqtranscale_reg_value = 0x552AB83A;
3092 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303093 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003094 demph_reg_value = 0x2B404040;
3095 uniqtranscale_reg_value = 0x5548B83A;
3096 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303097 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003098 demph_reg_value = 0x2B245555;
3099 uniqtranscale_reg_value = 0x5560B83A;
3100 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303101 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003102 demph_reg_value = 0x2B405555;
3103 uniqtranscale_reg_value = 0x5598DA3A;
3104 break;
3105 default:
3106 return 0;
3107 }
3108 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303109 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003110 preemph_reg_value = 0x0002000;
3111 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303112 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003113 demph_reg_value = 0x2B404040;
3114 uniqtranscale_reg_value = 0x5552B83A;
3115 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303116 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003117 demph_reg_value = 0x2B404848;
3118 uniqtranscale_reg_value = 0x5580B83A;
3119 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303120 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003121 demph_reg_value = 0x2B404040;
3122 uniqtranscale_reg_value = 0x55ADDA3A;
3123 break;
3124 default:
3125 return 0;
3126 }
3127 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303128 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003129 preemph_reg_value = 0x0000000;
3130 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303131 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003132 demph_reg_value = 0x2B305555;
3133 uniqtranscale_reg_value = 0x5570B83A;
3134 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303135 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003136 demph_reg_value = 0x2B2B4040;
3137 uniqtranscale_reg_value = 0x55ADDA3A;
3138 break;
3139 default:
3140 return 0;
3141 }
3142 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303143 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003144 preemph_reg_value = 0x0006000;
3145 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303146 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003147 demph_reg_value = 0x1B405555;
3148 uniqtranscale_reg_value = 0x55ADDA3A;
3149 break;
3150 default:
3151 return 0;
3152 }
3153 break;
3154 default:
3155 return 0;
3156 }
3157
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003158 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3159 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003160
3161 return 0;
3162}
3163
Daniel Vetter5829975c2015-04-16 11:36:52 +02003164static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003165{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003166 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3167 u32 deemph_reg_value, margin_reg_value;
3168 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003169 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003170
3171 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303172 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003173 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303174 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003175 deemph_reg_value = 128;
3176 margin_reg_value = 52;
3177 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303178 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003179 deemph_reg_value = 128;
3180 margin_reg_value = 77;
3181 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303182 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003183 deemph_reg_value = 128;
3184 margin_reg_value = 102;
3185 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303186 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003187 deemph_reg_value = 128;
3188 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003189 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003190 break;
3191 default:
3192 return 0;
3193 }
3194 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003196 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003198 deemph_reg_value = 85;
3199 margin_reg_value = 78;
3200 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303201 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003202 deemph_reg_value = 85;
3203 margin_reg_value = 116;
3204 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003206 deemph_reg_value = 85;
3207 margin_reg_value = 154;
3208 break;
3209 default:
3210 return 0;
3211 }
3212 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303213 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003214 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003216 deemph_reg_value = 64;
3217 margin_reg_value = 104;
3218 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003220 deemph_reg_value = 64;
3221 margin_reg_value = 154;
3222 break;
3223 default:
3224 return 0;
3225 }
3226 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303227 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003228 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003230 deemph_reg_value = 43;
3231 margin_reg_value = 154;
3232 break;
3233 default:
3234 return 0;
3235 }
3236 break;
3237 default:
3238 return 0;
3239 }
3240
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003241 chv_set_phy_signal_level(encoder, deemph_reg_value,
3242 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003243
3244 return 0;
3245}
3246
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003247static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003248gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003249{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003250 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003251
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003252 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003254 default:
3255 signal_levels |= DP_VOLTAGE_0_4;
3256 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003258 signal_levels |= DP_VOLTAGE_0_6;
3259 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303260 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003261 signal_levels |= DP_VOLTAGE_0_8;
3262 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303263 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003264 signal_levels |= DP_VOLTAGE_1_2;
3265 break;
3266 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003267 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003269 default:
3270 signal_levels |= DP_PRE_EMPHASIS_0;
3271 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303272 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003273 signal_levels |= DP_PRE_EMPHASIS_3_5;
3274 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003276 signal_levels |= DP_PRE_EMPHASIS_6;
3277 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303278 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003279 signal_levels |= DP_PRE_EMPHASIS_9_5;
3280 break;
3281 }
3282 return signal_levels;
3283}
3284
Zhenyu Wange3421a12010-04-08 09:43:27 +08003285/* Gen6's DP voltage swing and pre-emphasis control */
3286static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003287gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003288{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003289 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3290 DP_TRAIN_PRE_EMPHASIS_MASK);
3291 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303292 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003294 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003296 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303297 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3298 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003299 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303300 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3301 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003302 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3304 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003305 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003306 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003307 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3308 "0x%x\n", signal_levels);
3309 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003310 }
3311}
3312
Keith Packard1a2eb462011-11-16 16:26:07 -08003313/* Gen7's DP voltage swing and pre-emphasis control */
3314static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003315gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003316{
3317 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3318 DP_TRAIN_PRE_EMPHASIS_MASK);
3319 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003321 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003323 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003325 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3326
Sonika Jindalbd600182014-08-08 16:23:41 +05303327 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003328 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003330 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3331
Sonika Jindalbd600182014-08-08 16:23:41 +05303332 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003333 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303334 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003335 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3336
3337 default:
3338 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3339 "0x%x\n", signal_levels);
3340 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3341 }
3342}
3343
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003344void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003345intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003346{
3347 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003348 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003349 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003350 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003351 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003352 uint8_t train_set = intel_dp->train_set[0];
3353
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003354 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003355 signal_levels = ddi_signal_levels(intel_dp);
3356
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003357 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003358 signal_levels = 0;
3359 else
3360 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003361 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003362 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003363 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003364 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003365 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003366 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003367 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003368 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003369 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003370 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3371 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003372 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003373 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3374 }
3375
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303376 if (mask)
3377 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3378
3379 DRM_DEBUG_KMS("Using vswing level %d\n",
3380 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3381 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3382 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3383 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003384
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003385 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003386
3387 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3388 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003389}
3390
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003391void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003392intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3393 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003394{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003395 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003396 struct drm_i915_private *dev_priv =
3397 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003398
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003399 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003400
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003401 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003402 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003403}
3404
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003405void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003406{
3407 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3408 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003409 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003410 enum port port = intel_dig_port->port;
3411 uint32_t val;
3412
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003413 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003414 return;
3415
3416 val = I915_READ(DP_TP_CTL(port));
3417 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3418 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3419 I915_WRITE(DP_TP_CTL(port), val);
3420
3421 /*
3422 * On PORT_A we can have only eDP in SST mode. There the only reason
3423 * we need to set idle transmission mode is to work around a HW issue
3424 * where we enable the pipe while not in idle link-training mode.
3425 * In this case there is requirement to wait for a minimum number of
3426 * idle patterns to be sent.
3427 */
3428 if (port == PORT_A)
3429 return;
3430
Chris Wilsona7670172016-06-30 15:33:10 +01003431 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3432 DP_TP_STATUS_IDLE_DONE,
3433 DP_TP_STATUS_IDLE_DONE,
3434 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003435 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3436}
3437
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003438static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003439intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003440{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003441 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003442 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003443 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003444 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003445 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003446 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003447
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003448 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003449 return;
3450
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003451 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003452 return;
3453
Zhao Yakui28c97732009-10-09 11:39:41 +08003454 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003455
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003456 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003457 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003458 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003459 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003460 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003461 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003462 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3463 else
3464 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003465 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003466 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003467 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003468 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003469
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003470 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3471 I915_WRITE(intel_dp->output_reg, DP);
3472 POSTING_READ(intel_dp->output_reg);
3473
3474 /*
3475 * HW workaround for IBX, we need to move the port
3476 * to transcoder A after disabling it to allow the
3477 * matching HDMI port to be enabled on transcoder A.
3478 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003479 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003480 /*
3481 * We get CPU/PCH FIFO underruns on the other pipe when
3482 * doing the workaround. Sweep them under the rug.
3483 */
3484 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3485 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3486
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003487 /* always enable with pattern 1 (as per spec) */
3488 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3489 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3490 I915_WRITE(intel_dp->output_reg, DP);
3491 POSTING_READ(intel_dp->output_reg);
3492
3493 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003494 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003495 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003496
Chris Wilson91c8a322016-07-05 10:40:23 +01003497 intel_wait_for_vblank_if_active(&dev_priv->drm, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003498 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3499 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003500 }
3501
Keith Packardf01eca22011-09-28 16:48:10 -07003502 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003503
3504 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003505}
3506
Keith Packard26d61aa2011-07-25 20:01:09 -07003507static bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003508intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003509{
Lyude9f085eb2016-04-13 10:58:33 -04003510 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3511 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003512 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003513
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003514 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003515
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003516 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3517}
3518
3519static bool
3520intel_edp_init_dpcd(struct intel_dp *intel_dp)
3521{
3522 struct drm_i915_private *dev_priv =
3523 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3524
3525 /* this function is meant to be called only once */
3526 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3527
3528 if (!intel_dp_read_dpcd(intel_dp))
3529 return false;
3530
3531 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3532 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3533 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3534
3535 /* Check if the panel supports PSR */
3536 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3537 intel_dp->psr_dpcd,
3538 sizeof(intel_dp->psr_dpcd));
3539 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3540 dev_priv->psr.sink_support = true;
3541 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3542 }
3543
3544 if (INTEL_GEN(dev_priv) >= 9 &&
3545 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3546 uint8_t frame_sync_cap;
3547
3548 dev_priv->psr.sink_support = true;
3549 drm_dp_dpcd_read(&intel_dp->aux,
3550 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3551 &frame_sync_cap, 1);
3552 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3553 /* PSR2 needs frame sync as well */
3554 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3555 DRM_DEBUG_KMS("PSR2 %s on sink",
3556 dev_priv->psr.psr2_support ? "supported" : "not supported");
3557 }
3558
3559 /* Read the eDP Display control capabilities registers */
3560 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3561 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003562 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3563 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003564 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3565 intel_dp->edp_dpcd);
3566
3567 /* Intermediate frequency support */
3568 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3569 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3570 int i;
3571
3572 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3573 sink_rates, sizeof(sink_rates));
3574
3575 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3576 int val = le16_to_cpu(sink_rates[i]);
3577
3578 if (val == 0)
3579 break;
3580
3581 /* Value read is in kHz while drm clock is saved in deca-kHz */
3582 intel_dp->sink_rates[i] = (val * 200) / 10;
3583 }
3584 intel_dp->num_sink_rates = i;
3585 }
3586
3587 return true;
3588}
3589
3590
3591static bool
3592intel_dp_get_dpcd(struct intel_dp *intel_dp)
3593{
3594 if (!intel_dp_read_dpcd(intel_dp))
3595 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003596
Lyude9f085eb2016-04-13 10:58:33 -04003597 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3598 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303599 return false;
3600
3601 /*
3602 * Sink count can change between short pulse hpd hence
3603 * a member variable in intel_dp will track any changes
3604 * between short pulse interrupts.
3605 */
3606 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3607
3608 /*
3609 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3610 * a dongle is present but no display. Unless we require to know
3611 * if a dongle is present or not, we don't need to update
3612 * downstream port information. So, an early return here saves
3613 * time from performing other operations which are not required.
3614 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303615 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303616 return false;
3617
Adam Jacksonedb39242012-09-18 10:58:49 -04003618 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3619 DP_DWN_STRM_PORT_PRESENT))
3620 return true; /* native DP sink */
3621
3622 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3623 return true; /* no per-port downstream info */
3624
Lyude9f085eb2016-04-13 10:58:33 -04003625 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3626 intel_dp->downstream_ports,
3627 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003628 return false; /* downstream port status fetch failed */
3629
3630 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003631}
3632
Adam Jackson0d198322012-05-14 16:05:47 -04003633static void
3634intel_dp_probe_oui(struct intel_dp *intel_dp)
3635{
3636 u8 buf[3];
3637
3638 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3639 return;
3640
Lyude9f085eb2016-04-13 10:58:33 -04003641 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003642 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3643 buf[0], buf[1], buf[2]);
3644
Lyude9f085eb2016-04-13 10:58:33 -04003645 if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003646 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3647 buf[0], buf[1], buf[2]);
3648}
3649
Dave Airlie0e32b392014-05-02 14:02:48 +10003650static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003651intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003652{
3653 u8 buf[1];
3654
Nathan Schulte7cc96132016-03-15 10:14:05 -05003655 if (!i915.enable_dp_mst)
3656 return false;
3657
Dave Airlie0e32b392014-05-02 14:02:48 +10003658 if (!intel_dp->can_mst)
3659 return false;
3660
3661 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3662 return false;
3663
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003664 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3665 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003666
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003667 return buf[0] & DP_MST_CAP;
3668}
3669
3670static void
3671intel_dp_configure_mst(struct intel_dp *intel_dp)
3672{
3673 if (!i915.enable_dp_mst)
3674 return;
3675
3676 if (!intel_dp->can_mst)
3677 return;
3678
3679 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3680
3681 if (intel_dp->is_mst)
3682 DRM_DEBUG_KMS("Sink is MST capable\n");
3683 else
3684 DRM_DEBUG_KMS("Sink is not MST capable\n");
3685
3686 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3687 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003688}
3689
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003690static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003691{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003692 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003693 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003694 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003695 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003696 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003697 int count = 0;
3698 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003699
3700 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003701 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003702 ret = -EIO;
3703 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003704 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003705
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003706 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003707 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003708 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003709 ret = -EIO;
3710 goto out;
3711 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003712
Rodrigo Vivic6297842015-11-05 10:50:20 -08003713 do {
3714 intel_wait_for_vblank(dev, intel_crtc->pipe);
3715
3716 if (drm_dp_dpcd_readb(&intel_dp->aux,
3717 DP_TEST_SINK_MISC, &buf) < 0) {
3718 ret = -EIO;
3719 goto out;
3720 }
3721 count = buf & DP_TEST_COUNT_MASK;
3722 } while (--attempts && count);
3723
3724 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003725 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003726 ret = -ETIMEDOUT;
3727 }
3728
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003729 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003730 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003731 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003732}
3733
3734static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3735{
3736 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003737 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003738 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3739 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003740 int ret;
3741
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003742 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3743 return -EIO;
3744
3745 if (!(buf & DP_TEST_CRC_SUPPORTED))
3746 return -ENOTTY;
3747
3748 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3749 return -EIO;
3750
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003751 if (buf & DP_TEST_SINK_START) {
3752 ret = intel_dp_sink_crc_stop(intel_dp);
3753 if (ret)
3754 return ret;
3755 }
3756
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003757 hsw_disable_ips(intel_crtc);
3758
3759 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3760 buf | DP_TEST_SINK_START) < 0) {
3761 hsw_enable_ips(intel_crtc);
3762 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003763 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003764
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003765 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003766 return 0;
3767}
3768
3769int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3770{
3771 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3772 struct drm_device *dev = dig_port->base.base.dev;
3773 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3774 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003775 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003776 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003777
3778 ret = intel_dp_sink_crc_start(intel_dp);
3779 if (ret)
3780 return ret;
3781
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003782 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003783 intel_wait_for_vblank(dev, intel_crtc->pipe);
3784
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003785 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003786 DP_TEST_SINK_MISC, &buf) < 0) {
3787 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003788 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003789 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003790 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003791
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003792 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003793
3794 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003795 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3796 ret = -ETIMEDOUT;
3797 goto stop;
3798 }
3799
3800 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3801 ret = -EIO;
3802 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003803 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003804
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003805stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003806 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003807 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003808}
3809
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003810static bool
3811intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3812{
Lyude9f085eb2016-04-13 10:58:33 -04003813 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003814 DP_DEVICE_SERVICE_IRQ_VECTOR,
3815 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003816}
3817
Dave Airlie0e32b392014-05-02 14:02:48 +10003818static bool
3819intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3820{
3821 int ret;
3822
Lyude9f085eb2016-04-13 10:58:33 -04003823 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003824 DP_SINK_COUNT_ESI,
3825 sink_irq_vector, 14);
3826 if (ret != 14)
3827 return false;
3828
3829 return true;
3830}
3831
Todd Previtec5d5ab72015-04-15 08:38:38 -07003832static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003833{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003834 uint8_t test_result = DP_TEST_ACK;
3835 return test_result;
3836}
3837
3838static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3839{
3840 uint8_t test_result = DP_TEST_NAK;
3841 return test_result;
3842}
3843
3844static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3845{
3846 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003847 struct intel_connector *intel_connector = intel_dp->attached_connector;
3848 struct drm_connector *connector = &intel_connector->base;
3849
3850 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003851 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003852 intel_dp->aux.i2c_defer_count > 6) {
3853 /* Check EDID read for NACKs, DEFERs and corruption
3854 * (DP CTS 1.2 Core r1.1)
3855 * 4.2.2.4 : Failed EDID read, I2C_NAK
3856 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3857 * 4.2.2.6 : EDID corruption detected
3858 * Use failsafe mode for all cases
3859 */
3860 if (intel_dp->aux.i2c_nack_count > 0 ||
3861 intel_dp->aux.i2c_defer_count > 0)
3862 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3863 intel_dp->aux.i2c_nack_count,
3864 intel_dp->aux.i2c_defer_count);
3865 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3866 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303867 struct edid *block = intel_connector->detect_edid;
3868
3869 /* We have to write the checksum
3870 * of the last block read
3871 */
3872 block += intel_connector->detect_edid->extensions;
3873
Todd Previte559be302015-05-04 07:48:20 -07003874 if (!drm_dp_dpcd_write(&intel_dp->aux,
3875 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303876 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003877 1))
Todd Previte559be302015-05-04 07:48:20 -07003878 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3879
3880 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3881 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3882 }
3883
3884 /* Set test active flag here so userspace doesn't interrupt things */
3885 intel_dp->compliance_test_active = 1;
3886
Todd Previtec5d5ab72015-04-15 08:38:38 -07003887 return test_result;
3888}
3889
3890static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3891{
3892 uint8_t test_result = DP_TEST_NAK;
3893 return test_result;
3894}
3895
3896static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3897{
3898 uint8_t response = DP_TEST_NAK;
3899 uint8_t rxdata = 0;
3900 int status = 0;
3901
Todd Previtec5d5ab72015-04-15 08:38:38 -07003902 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3903 if (status <= 0) {
3904 DRM_DEBUG_KMS("Could not read test request from sink\n");
3905 goto update_status;
3906 }
3907
3908 switch (rxdata) {
3909 case DP_TEST_LINK_TRAINING:
3910 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3911 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3912 response = intel_dp_autotest_link_training(intel_dp);
3913 break;
3914 case DP_TEST_LINK_VIDEO_PATTERN:
3915 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3916 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3917 response = intel_dp_autotest_video_pattern(intel_dp);
3918 break;
3919 case DP_TEST_LINK_EDID_READ:
3920 DRM_DEBUG_KMS("EDID test requested\n");
3921 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3922 response = intel_dp_autotest_edid(intel_dp);
3923 break;
3924 case DP_TEST_LINK_PHY_TEST_PATTERN:
3925 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3926 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3927 response = intel_dp_autotest_phy_pattern(intel_dp);
3928 break;
3929 default:
3930 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3931 break;
3932 }
3933
3934update_status:
3935 status = drm_dp_dpcd_write(&intel_dp->aux,
3936 DP_TEST_RESPONSE,
3937 &response, 1);
3938 if (status <= 0)
3939 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003940}
3941
Dave Airlie0e32b392014-05-02 14:02:48 +10003942static int
3943intel_dp_check_mst_status(struct intel_dp *intel_dp)
3944{
3945 bool bret;
3946
3947 if (intel_dp->is_mst) {
3948 u8 esi[16] = { 0 };
3949 int ret = 0;
3950 int retry;
3951 bool handled;
3952 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3953go_again:
3954 if (bret == true) {
3955
3956 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003957 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003958 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003959 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3960 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003961 intel_dp_stop_link_train(intel_dp);
3962 }
3963
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003964 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003965 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3966
3967 if (handled) {
3968 for (retry = 0; retry < 3; retry++) {
3969 int wret;
3970 wret = drm_dp_dpcd_write(&intel_dp->aux,
3971 DP_SINK_COUNT_ESI+1,
3972 &esi[1], 3);
3973 if (wret == 3) {
3974 break;
3975 }
3976 }
3977
3978 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3979 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003980 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003981 goto go_again;
3982 }
3983 } else
3984 ret = 0;
3985
3986 return ret;
3987 } else {
3988 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3989 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3990 intel_dp->is_mst = false;
3991 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3992 /* send a hotplug event */
3993 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3994 }
3995 }
3996 return -EINVAL;
3997}
3998
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303999static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004000intel_dp_retrain_link(struct intel_dp *intel_dp)
4001{
4002 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4003 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4004 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4005
4006 /* Suppress underruns caused by re-training */
4007 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4008 if (crtc->config->has_pch_encoder)
4009 intel_set_pch_fifo_underrun_reporting(dev_priv,
4010 intel_crtc_pch_transcoder(crtc), false);
4011
4012 intel_dp_start_link_train(intel_dp);
4013 intel_dp_stop_link_train(intel_dp);
4014
4015 /* Keep underrun reporting disabled until things are stable */
4016 intel_wait_for_vblank(&dev_priv->drm, crtc->pipe);
4017
4018 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4019 if (crtc->config->has_pch_encoder)
4020 intel_set_pch_fifo_underrun_reporting(dev_priv,
4021 intel_crtc_pch_transcoder(crtc), true);
4022}
4023
4024static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304025intel_dp_check_link_status(struct intel_dp *intel_dp)
4026{
4027 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4028 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4029 u8 link_status[DP_LINK_STATUS_SIZE];
4030
4031 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4032
4033 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4034 DRM_ERROR("Failed to get link status\n");
4035 return;
4036 }
4037
4038 if (!intel_encoder->base.crtc)
4039 return;
4040
4041 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4042 return;
4043
4044 /* if link training is requested we should perform it always */
4045 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
4046 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4047 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4048 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004049
4050 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304051 }
4052}
4053
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004054/*
4055 * According to DP spec
4056 * 5.1.2:
4057 * 1. Read DPCD
4058 * 2. Configure link according to Receiver Capabilities
4059 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4060 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304061 *
4062 * intel_dp_short_pulse - handles short pulse interrupts
4063 * when full detection is not required.
4064 * Returns %true if short pulse is handled and full detection
4065 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004066 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304067static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304068intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004069{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004070 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004071 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304072 u8 old_sink_count = intel_dp->sink_count;
4073 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004074
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304075 /*
4076 * Clearing compliance test variables to allow capturing
4077 * of values for next automated test request.
4078 */
4079 intel_dp->compliance_test_active = 0;
4080 intel_dp->compliance_test_type = 0;
4081 intel_dp->compliance_test_data = 0;
4082
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304083 /*
4084 * Now read the DPCD to see if it's actually running
4085 * If the current value of sink count doesn't match with
4086 * the value that was stored earlier or dpcd read failed
4087 * we need to do full detection
4088 */
4089 ret = intel_dp_get_dpcd(intel_dp);
4090
4091 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4092 /* No need to proceed if we are going to do full detect */
4093 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004094 }
4095
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004096 /* Try to read the source of the interrupt */
4097 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004098 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4099 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004100 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004101 drm_dp_dpcd_writeb(&intel_dp->aux,
4102 DP_DEVICE_SERVICE_IRQ_VECTOR,
4103 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004104
4105 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004106 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004107 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4108 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4109 }
4110
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304111 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4112 intel_dp_check_link_status(intel_dp);
4113 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304114
4115 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004116}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004117
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004118/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004119static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004120intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004121{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004122 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004123 uint8_t type;
4124
4125 if (!intel_dp_get_dpcd(intel_dp))
4126 return connector_status_disconnected;
4127
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304128 if (is_edp(intel_dp))
4129 return connector_status_connected;
4130
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004131 /* if there's no downstream port, we're done */
4132 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07004133 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004134
4135 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004136 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4137 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004138
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304139 return intel_dp->sink_count ?
4140 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004141 }
4142
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004143 if (intel_dp_can_mst(intel_dp))
4144 return connector_status_connected;
4145
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004146 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004147 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004148 return connector_status_connected;
4149
4150 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004151 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4152 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4153 if (type == DP_DS_PORT_TYPE_VGA ||
4154 type == DP_DS_PORT_TYPE_NON_EDID)
4155 return connector_status_unknown;
4156 } else {
4157 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4158 DP_DWN_STRM_PORT_TYPE_MASK;
4159 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4160 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4161 return connector_status_unknown;
4162 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004163
4164 /* Anything else is out of spec, warn and ignore */
4165 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004166 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004167}
4168
4169static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004170edp_detect(struct intel_dp *intel_dp)
4171{
4172 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4173 enum drm_connector_status status;
4174
4175 status = intel_panel_detect(dev);
4176 if (status == connector_status_unknown)
4177 status = connector_status_connected;
4178
4179 return status;
4180}
4181
Jani Nikulab93433c2015-08-20 10:47:36 +03004182static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4183 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004184{
Jani Nikulab93433c2015-08-20 10:47:36 +03004185 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004186
Jani Nikula0df53b72015-08-20 10:47:40 +03004187 switch (port->port) {
4188 case PORT_A:
4189 return true;
4190 case PORT_B:
4191 bit = SDE_PORTB_HOTPLUG;
4192 break;
4193 case PORT_C:
4194 bit = SDE_PORTC_HOTPLUG;
4195 break;
4196 case PORT_D:
4197 bit = SDE_PORTD_HOTPLUG;
4198 break;
4199 default:
4200 MISSING_CASE(port->port);
4201 return false;
4202 }
4203
4204 return I915_READ(SDEISR) & bit;
4205}
4206
4207static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4208 struct intel_digital_port *port)
4209{
4210 u32 bit;
4211
4212 switch (port->port) {
4213 case PORT_A:
4214 return true;
4215 case PORT_B:
4216 bit = SDE_PORTB_HOTPLUG_CPT;
4217 break;
4218 case PORT_C:
4219 bit = SDE_PORTC_HOTPLUG_CPT;
4220 break;
4221 case PORT_D:
4222 bit = SDE_PORTD_HOTPLUG_CPT;
4223 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004224 case PORT_E:
4225 bit = SDE_PORTE_HOTPLUG_SPT;
4226 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004227 default:
4228 MISSING_CASE(port->port);
4229 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004230 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004231
Jani Nikulab93433c2015-08-20 10:47:36 +03004232 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004233}
4234
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004235static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004236 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004237{
Jani Nikula9642c812015-08-20 10:47:41 +03004238 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004239
Jani Nikula9642c812015-08-20 10:47:41 +03004240 switch (port->port) {
4241 case PORT_B:
4242 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4243 break;
4244 case PORT_C:
4245 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4246 break;
4247 case PORT_D:
4248 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4249 break;
4250 default:
4251 MISSING_CASE(port->port);
4252 return false;
4253 }
4254
4255 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4256}
4257
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004258static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4259 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004260{
4261 u32 bit;
4262
4263 switch (port->port) {
4264 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004265 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004266 break;
4267 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004268 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004269 break;
4270 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004271 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004272 break;
4273 default:
4274 MISSING_CASE(port->port);
4275 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004276 }
4277
Jani Nikula1d245982015-08-20 10:47:37 +03004278 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004279}
4280
Jani Nikulae464bfd2015-08-20 10:47:42 +03004281static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304282 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004283{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304284 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4285 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004286 u32 bit;
4287
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304288 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4289 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004290 case PORT_A:
4291 bit = BXT_DE_PORT_HP_DDIA;
4292 break;
4293 case PORT_B:
4294 bit = BXT_DE_PORT_HP_DDIB;
4295 break;
4296 case PORT_C:
4297 bit = BXT_DE_PORT_HP_DDIC;
4298 break;
4299 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304300 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004301 return false;
4302 }
4303
4304 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4305}
4306
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004307/*
4308 * intel_digital_port_connected - is the specified port connected?
4309 * @dev_priv: i915 private structure
4310 * @port: the port to test
4311 *
4312 * Return %true if @port is connected, %false otherwise.
4313 */
David Weinehall23f889b2016-08-17 15:47:48 +03004314static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004315 struct intel_digital_port *port)
4316{
Jani Nikula0df53b72015-08-20 10:47:40 +03004317 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004318 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004319 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004320 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004321 else if (IS_BROXTON(dev_priv))
4322 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004323 else if (IS_GM45(dev_priv))
4324 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004325 else
4326 return g4x_digital_port_connected(dev_priv, port);
4327}
4328
Keith Packard8c241fe2011-09-28 16:38:44 -07004329static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004330intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004331{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004332 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004333
Jani Nikula9cd300e2012-10-19 14:51:52 +03004334 /* use cached edid if we have one */
4335 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004336 /* invalid edid */
4337 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004338 return NULL;
4339
Jani Nikula55e9ede2013-10-01 10:38:54 +03004340 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004341 } else
4342 return drm_get_edid(&intel_connector->base,
4343 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004344}
4345
Chris Wilsonbeb60602014-09-02 20:04:00 +01004346static void
4347intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004348{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004349 struct intel_connector *intel_connector = intel_dp->attached_connector;
4350 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004351
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304352 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004353 edid = intel_dp_get_edid(intel_dp);
4354 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004355
Chris Wilsonbeb60602014-09-02 20:04:00 +01004356 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4357 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4358 else
4359 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4360}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004361
Chris Wilsonbeb60602014-09-02 20:04:00 +01004362static void
4363intel_dp_unset_edid(struct intel_dp *intel_dp)
4364{
4365 struct intel_connector *intel_connector = intel_dp->attached_connector;
4366
4367 kfree(intel_connector->detect_edid);
4368 intel_connector->detect_edid = NULL;
4369
4370 intel_dp->has_audio = false;
4371}
4372
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004373static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304374intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004375{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304376 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004377 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004378 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4379 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004380 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004381 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004382 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004383 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004384
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004385 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4386 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004387
Chris Wilsond410b562014-09-02 20:03:59 +01004388 /* Can't disconnect eDP, but you can close the lid... */
4389 if (is_edp(intel_dp))
4390 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004391 else if (intel_digital_port_connected(to_i915(dev),
4392 dp_to_dig_port(intel_dp)))
4393 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004394 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004395 status = connector_status_disconnected;
4396
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004397 if (status == connector_status_disconnected) {
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304398 intel_dp->compliance_test_active = 0;
4399 intel_dp->compliance_test_type = 0;
4400 intel_dp->compliance_test_data = 0;
4401
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004402 if (intel_dp->is_mst) {
4403 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4404 intel_dp->is_mst,
4405 intel_dp->mst_mgr.mst_state);
4406 intel_dp->is_mst = false;
4407 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4408 intel_dp->is_mst);
4409 }
4410
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004411 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304412 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004413
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304414 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004415 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304416
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004417 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4418 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4419 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4420
4421 intel_dp_print_rates(intel_dp);
4422
Adam Jackson0d198322012-05-14 16:05:47 -04004423 intel_dp_probe_oui(intel_dp);
4424
Mika Kahola0e390a32016-09-09 14:10:53 +03004425 intel_dp_print_hw_revision(intel_dp);
Mika Kahola1a2724f2016-09-09 14:10:54 +03004426 intel_dp_print_sw_revision(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004427
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004428 intel_dp_configure_mst(intel_dp);
4429
4430 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304431 /*
4432 * If we are in MST mode then this connector
4433 * won't appear connected or have anything
4434 * with EDID on it
4435 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004436 status = connector_status_disconnected;
4437 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304438 } else if (connector->status == connector_status_connected) {
4439 /*
4440 * If display was connected already and is still connected
4441 * check links status, there has been known issues of
4442 * link loss triggerring long pulse!!!!
4443 */
4444 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4445 intel_dp_check_link_status(intel_dp);
4446 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4447 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004448 }
4449
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304450 /*
4451 * Clearing NACK and defer counts to get their exact values
4452 * while reading EDID which are required by Compliance tests
4453 * 4.2.2.4 and 4.2.2.5
4454 */
4455 intel_dp->aux.i2c_nack_count = 0;
4456 intel_dp->aux.i2c_defer_count = 0;
4457
Chris Wilsonbeb60602014-09-02 20:04:00 +01004458 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004459 if (is_edp(intel_dp) || intel_connector->detect_edid)
4460 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304461 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004462
Todd Previte09b1eb12015-04-20 15:27:34 -07004463 /* Try to read the source of the interrupt */
4464 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004465 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4466 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004467 /* Clear interrupt source */
4468 drm_dp_dpcd_writeb(&intel_dp->aux,
4469 DP_DEVICE_SERVICE_IRQ_VECTOR,
4470 sink_irq_vector);
4471
4472 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4473 intel_dp_handle_test_request(intel_dp);
4474 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4475 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4476 }
4477
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004478out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004479 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304480 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304481
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004482 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004483 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304484}
4485
4486static enum drm_connector_status
4487intel_dp_detect(struct drm_connector *connector, bool force)
4488{
4489 struct intel_dp *intel_dp = intel_attached_dp(connector);
4490 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4491 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004492 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304493
4494 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4495 connector->base.id, connector->name);
4496
4497 if (intel_dp->is_mst) {
4498 /* MST devices are disconnected from a monitor POV */
4499 intel_dp_unset_edid(intel_dp);
4500 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004501 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304502 return connector_status_disconnected;
4503 }
4504
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304505 /* If full detect is not performed yet, do a full detect */
4506 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004507 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304508
4509 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304510
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004511 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004512}
4513
Chris Wilsonbeb60602014-09-02 20:04:00 +01004514static void
4515intel_dp_force(struct drm_connector *connector)
4516{
4517 struct intel_dp *intel_dp = intel_attached_dp(connector);
4518 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004519 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004520 enum intel_display_power_domain power_domain;
4521
4522 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4523 connector->base.id, connector->name);
4524 intel_dp_unset_edid(intel_dp);
4525
4526 if (connector->status != connector_status_connected)
4527 return;
4528
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004529 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4530 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004531
4532 intel_dp_set_edid(intel_dp);
4533
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004534 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004535
4536 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004537 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004538}
4539
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004540static int intel_dp_get_modes(struct drm_connector *connector)
4541{
Jani Nikuladd06f902012-10-19 14:51:50 +03004542 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004543 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004544
Chris Wilsonbeb60602014-09-02 20:04:00 +01004545 edid = intel_connector->detect_edid;
4546 if (edid) {
4547 int ret = intel_connector_update_modes(connector, edid);
4548 if (ret)
4549 return ret;
4550 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004551
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004552 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004553 if (is_edp(intel_attached_dp(connector)) &&
4554 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004555 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004556
4557 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004558 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004559 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004560 drm_mode_probed_add(connector, mode);
4561 return 1;
4562 }
4563 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004564
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004565 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004566}
4567
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004568static bool
4569intel_dp_detect_audio(struct drm_connector *connector)
4570{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004571 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004572 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004573
Chris Wilsonbeb60602014-09-02 20:04:00 +01004574 edid = to_intel_connector(connector)->detect_edid;
4575 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004576 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004577
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004578 return has_audio;
4579}
4580
Chris Wilsonf6849602010-09-19 09:29:33 +01004581static int
4582intel_dp_set_property(struct drm_connector *connector,
4583 struct drm_property *property,
4584 uint64_t val)
4585{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004586 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004587 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004588 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4589 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004590 int ret;
4591
Rob Clark662595d2012-10-11 20:36:04 -05004592 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004593 if (ret)
4594 return ret;
4595
Chris Wilson3f43c482011-05-12 22:17:24 +01004596 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004597 int i = val;
4598 bool has_audio;
4599
4600 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004601 return 0;
4602
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004603 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004604
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004605 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004606 has_audio = intel_dp_detect_audio(connector);
4607 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004608 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004609
4610 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004611 return 0;
4612
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004613 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004614 goto done;
4615 }
4616
Chris Wilsone953fd72011-02-21 22:23:52 +00004617 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004618 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004619 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004620
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004621 switch (val) {
4622 case INTEL_BROADCAST_RGB_AUTO:
4623 intel_dp->color_range_auto = true;
4624 break;
4625 case INTEL_BROADCAST_RGB_FULL:
4626 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004627 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004628 break;
4629 case INTEL_BROADCAST_RGB_LIMITED:
4630 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004631 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004632 break;
4633 default:
4634 return -EINVAL;
4635 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004636
4637 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004638 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004639 return 0;
4640
Chris Wilsone953fd72011-02-21 22:23:52 +00004641 goto done;
4642 }
4643
Yuly Novikov53b41832012-10-26 12:04:00 +03004644 if (is_edp(intel_dp) &&
4645 property == connector->dev->mode_config.scaling_mode_property) {
4646 if (val == DRM_MODE_SCALE_NONE) {
4647 DRM_DEBUG_KMS("no scaling not supported\n");
4648 return -EINVAL;
4649 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004650 if (HAS_GMCH_DISPLAY(dev_priv) &&
4651 val == DRM_MODE_SCALE_CENTER) {
4652 DRM_DEBUG_KMS("centering not supported\n");
4653 return -EINVAL;
4654 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004655
4656 if (intel_connector->panel.fitting_mode == val) {
4657 /* the eDP scaling property is not changed */
4658 return 0;
4659 }
4660 intel_connector->panel.fitting_mode = val;
4661
4662 goto done;
4663 }
4664
Chris Wilsonf6849602010-09-19 09:29:33 +01004665 return -EINVAL;
4666
4667done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004668 if (intel_encoder->base.crtc)
4669 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004670
4671 return 0;
4672}
4673
Chris Wilson7a418e32016-06-24 14:00:14 +01004674static int
4675intel_dp_connector_register(struct drm_connector *connector)
4676{
4677 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004678 int ret;
4679
4680 ret = intel_connector_register(connector);
4681 if (ret)
4682 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004683
4684 i915_debugfs_connector_add(connector);
4685
4686 DRM_DEBUG_KMS("registering %s bus for %s\n",
4687 intel_dp->aux.name, connector->kdev->kobj.name);
4688
4689 intel_dp->aux.dev = connector->kdev;
4690 return drm_dp_aux_register(&intel_dp->aux);
4691}
4692
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004693static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004694intel_dp_connector_unregister(struct drm_connector *connector)
4695{
4696 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4697 intel_connector_unregister(connector);
4698}
4699
4700static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004701intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004702{
Jani Nikula1d508702012-10-19 14:51:49 +03004703 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004704
Chris Wilson10e972d2014-09-04 21:43:45 +01004705 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004706
Jani Nikula9cd300e2012-10-19 14:51:52 +03004707 if (!IS_ERR_OR_NULL(intel_connector->edid))
4708 kfree(intel_connector->edid);
4709
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004710 /* Can't call is_edp() since the encoder may have been destroyed
4711 * already. */
4712 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004713 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004714
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004715 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004716 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004717}
4718
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004719void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004720{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004721 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4722 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004723
Dave Airlie0e32b392014-05-02 14:02:48 +10004724 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004725 if (is_edp(intel_dp)) {
4726 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004727 /*
4728 * vdd might still be enabled do to the delayed vdd off.
4729 * Make sure vdd is actually turned off here.
4730 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004731 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004732 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004733 pps_unlock(intel_dp);
4734
Clint Taylor01527b32014-07-07 13:01:46 -07004735 if (intel_dp->edp_notifier.notifier_call) {
4736 unregister_reboot_notifier(&intel_dp->edp_notifier);
4737 intel_dp->edp_notifier.notifier_call = NULL;
4738 }
Keith Packardbd943152011-09-18 23:09:52 -07004739 }
Chris Wilson99681882016-06-20 09:29:17 +01004740
4741 intel_dp_aux_fini(intel_dp);
4742
Imre Deakc8bd0e42014-12-12 17:57:38 +02004743 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004744 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004745}
4746
Imre Deakbf93ba62016-04-18 10:04:21 +03004747void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004748{
4749 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4750
4751 if (!is_edp(intel_dp))
4752 return;
4753
Ville Syrjälä951468f2014-09-04 14:55:31 +03004754 /*
4755 * vdd might still be enabled do to the delayed vdd off.
4756 * Make sure vdd is actually turned off here.
4757 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004758 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004759 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004760 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004761 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004762}
4763
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004764static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4765{
4766 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4767 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004768 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004769 enum intel_display_power_domain power_domain;
4770
4771 lockdep_assert_held(&dev_priv->pps_mutex);
4772
4773 if (!edp_have_panel_vdd(intel_dp))
4774 return;
4775
4776 /*
4777 * The VDD bit needs a power domain reference, so if the bit is
4778 * already enabled when we boot or resume, grab this reference and
4779 * schedule a vdd off, so we don't hold on to the reference
4780 * indefinitely.
4781 */
4782 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004783 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004784 intel_display_power_get(dev_priv, power_domain);
4785
4786 edp_panel_vdd_schedule_off(intel_dp);
4787}
4788
Imre Deakbf93ba62016-04-18 10:04:21 +03004789void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004790{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004791 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Shashank Sharma910530c2016-10-14 19:56:52 +05304792 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4793 struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
4794 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004795
4796 if (!HAS_DDI(dev_priv))
4797 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004798
Shashank Sharma910530c2016-10-14 19:56:52 +05304799 if (IS_GEN9(dev_priv) && lspcon->active)
4800 lspcon_resume(lspcon);
4801
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004802 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4803 return;
4804
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004805 pps_lock(intel_dp);
4806
Imre Deak335f7522016-08-10 14:07:32 +03004807 /* Reinit the power sequencer, in case BIOS did something with it. */
4808 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004809 intel_edp_panel_vdd_sanitize(intel_dp);
4810
4811 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004812}
4813
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004814static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004815 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004816 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004817 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004818 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004819 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004820 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004821 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004822 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004823 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004824 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004825 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004826};
4827
4828static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4829 .get_modes = intel_dp_get_modes,
4830 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004831};
4832
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004833static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004834 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004835 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004836};
4837
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004838enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004839intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4840{
4841 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004842 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004843 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004844 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004845 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004846 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004847
Takashi Iwai25400582015-11-19 12:09:56 +01004848 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4849 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004850 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004851
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004852 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4853 /*
4854 * vdd off can generate a long pulse on eDP which
4855 * would require vdd on to handle it, and thus we
4856 * would end up in an endless cycle of
4857 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4858 */
4859 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4860 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02004861 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004862 }
4863
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004864 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4865 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004866 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004867
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004868 if (long_hpd) {
4869 intel_dp->detect_done = false;
4870 return IRQ_NONE;
4871 }
4872
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004873 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004874 intel_display_power_get(dev_priv, power_domain);
4875
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004876 if (intel_dp->is_mst) {
4877 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4878 /*
4879 * If we were in MST mode, and device is not
4880 * there, get out of MST mode
4881 */
4882 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4883 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4884 intel_dp->is_mst = false;
4885 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4886 intel_dp->is_mst);
4887 intel_dp->detect_done = false;
4888 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004889 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004890 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004891
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004892 if (!intel_dp->is_mst) {
4893 if (!intel_dp_short_pulse(intel_dp)) {
4894 intel_dp->detect_done = false;
4895 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304896 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004897 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004898
4899 ret = IRQ_HANDLED;
4900
Imre Deak1c767b32014-08-18 14:42:42 +03004901put_power:
4902 intel_display_power_put(dev_priv, power_domain);
4903
4904 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004905}
4906
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004907/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004908bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004909{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004910 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004911
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004912 /*
4913 * eDP not supported on g4x. so bail out early just
4914 * for a bit extra safety in case the VBT is bonkers.
4915 */
4916 if (INTEL_INFO(dev)->gen < 5)
4917 return false;
4918
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004919 if (port == PORT_A)
4920 return true;
4921
Jani Nikula951d9ef2016-03-16 12:43:31 +02004922 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004923}
4924
Dave Airlie0e32b392014-05-02 14:02:48 +10004925void
Chris Wilsonf6849602010-09-19 09:29:33 +01004926intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4927{
Yuly Novikov53b41832012-10-26 12:04:00 +03004928 struct intel_connector *intel_connector = to_intel_connector(connector);
4929
Chris Wilson3f43c482011-05-12 22:17:24 +01004930 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004931 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004932 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004933
4934 if (is_edp(intel_dp)) {
4935 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004936 drm_object_attach_property(
4937 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004938 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004939 DRM_MODE_SCALE_ASPECT);
4940 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004941 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004942}
4943
Imre Deakdada1a92014-01-29 13:25:41 +02004944static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4945{
Abhay Kumard28d4732016-01-22 17:39:04 -08004946 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004947 intel_dp->last_power_on = jiffies;
4948 intel_dp->last_backlight_off = jiffies;
4949}
4950
Daniel Vetter67a54562012-10-20 20:57:45 +02004951static void
Imre Deak54648612016-06-16 16:37:22 +03004952intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4953 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004954{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304955 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004956 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004957
Imre Deak8e8232d2016-06-16 16:37:21 +03004958 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004959
4960 /* Workaround: Need to write PP_CONTROL with the unlock key as
4961 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304962 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004963
Imre Deak8e8232d2016-06-16 16:37:21 +03004964 pp_on = I915_READ(regs.pp_on);
4965 pp_off = I915_READ(regs.pp_off);
Imre Deak54648612016-06-16 16:37:22 +03004966 if (!IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004967 I915_WRITE(regs.pp_ctrl, pp_ctl);
4968 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304969 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004970
4971 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004972 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4973 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004974
Imre Deak54648612016-06-16 16:37:22 +03004975 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4976 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004977
Imre Deak54648612016-06-16 16:37:22 +03004978 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4979 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004980
Imre Deak54648612016-06-16 16:37:22 +03004981 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4982 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004983
Imre Deak54648612016-06-16 16:37:22 +03004984 if (IS_BROXTON(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304985 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4986 BXT_POWER_CYCLE_DELAY_SHIFT;
4987 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004988 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304989 else
Imre Deak54648612016-06-16 16:37:22 +03004990 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304991 } else {
Imre Deak54648612016-06-16 16:37:22 +03004992 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004993 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304994 }
Imre Deak54648612016-06-16 16:37:22 +03004995}
4996
4997static void
Imre Deakde9c1b62016-06-16 20:01:46 +03004998intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
4999{
5000 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5001 state_name,
5002 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5003}
5004
5005static void
5006intel_pps_verify_state(struct drm_i915_private *dev_priv,
5007 struct intel_dp *intel_dp)
5008{
5009 struct edp_power_seq hw;
5010 struct edp_power_seq *sw = &intel_dp->pps_delays;
5011
5012 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5013
5014 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5015 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5016 DRM_ERROR("PPS state mismatch\n");
5017 intel_pps_dump_state("sw", sw);
5018 intel_pps_dump_state("hw", &hw);
5019 }
5020}
5021
5022static void
Imre Deak54648612016-06-16 16:37:22 +03005023intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5024 struct intel_dp *intel_dp)
5025{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005026 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005027 struct edp_power_seq cur, vbt, spec,
5028 *final = &intel_dp->pps_delays;
5029
5030 lockdep_assert_held(&dev_priv->pps_mutex);
5031
5032 /* already initialized? */
5033 if (final->t11_t12 != 0)
5034 return;
5035
5036 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005037
Imre Deakde9c1b62016-06-16 20:01:46 +03005038 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005039
Jani Nikula6aa23e62016-03-24 17:50:20 +02005040 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005041
5042 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5043 * our hw here, which are all in 100usec. */
5044 spec.t1_t3 = 210 * 10;
5045 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5046 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5047 spec.t10 = 500 * 10;
5048 /* This one is special and actually in units of 100ms, but zero
5049 * based in the hw (so we need to add 100 ms). But the sw vbt
5050 * table multiplies it with 1000 to make it in units of 100usec,
5051 * too. */
5052 spec.t11_t12 = (510 + 100) * 10;
5053
Imre Deakde9c1b62016-06-16 20:01:46 +03005054 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005055
5056 /* Use the max of the register settings and vbt. If both are
5057 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005058#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005059 spec.field : \
5060 max(cur.field, vbt.field))
5061 assign_final(t1_t3);
5062 assign_final(t8);
5063 assign_final(t9);
5064 assign_final(t10);
5065 assign_final(t11_t12);
5066#undef assign_final
5067
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005068#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005069 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5070 intel_dp->backlight_on_delay = get_delay(t8);
5071 intel_dp->backlight_off_delay = get_delay(t9);
5072 intel_dp->panel_power_down_delay = get_delay(t10);
5073 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5074#undef get_delay
5075
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005076 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5077 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5078 intel_dp->panel_power_cycle_delay);
5079
5080 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5081 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005082
5083 /*
5084 * We override the HW backlight delays to 1 because we do manual waits
5085 * on them. For T8, even BSpec recommends doing it. For T9, if we
5086 * don't do this, we'll end up waiting for the backlight off delay
5087 * twice: once when we do the manual sleep, and once when we disable
5088 * the panel and wait for the PP_STATUS bit to become zero.
5089 */
5090 final->t8 = 1;
5091 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005092}
5093
5094static void
5095intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005096 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005097{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005098 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005099 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005100 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005101 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005102 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005103 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005104
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005105 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005106
Imre Deak8e8232d2016-06-16 16:37:21 +03005107 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005108
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005109 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005110 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5111 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005112 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005113 /* Compute the divisor for the pp clock, simply match the Bspec
5114 * formula. */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005115 if (IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005116 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305117 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5118 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5119 << BXT_POWER_CYCLE_DELAY_SHIFT);
5120 } else {
5121 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5122 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5123 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5124 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005125
5126 /* Haswell doesn't have any port selection bits for the panel
5127 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005128 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005129 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005130 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005131 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005132 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005133 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005134 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005135 }
5136
Jesse Barnes453c5422013-03-28 09:55:41 -07005137 pp_on |= port_sel;
5138
Imre Deak8e8232d2016-06-16 16:37:21 +03005139 I915_WRITE(regs.pp_on, pp_on);
5140 I915_WRITE(regs.pp_off, pp_off);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005141 if (IS_BROXTON(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005142 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305143 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005144 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005145
Daniel Vetter67a54562012-10-20 20:57:45 +02005146 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 +03005147 I915_READ(regs.pp_on),
5148 I915_READ(regs.pp_off),
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005149 IS_BROXTON(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005150 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5151 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005152}
5153
Imre Deak335f7522016-08-10 14:07:32 +03005154static void intel_dp_pps_init(struct drm_device *dev,
5155 struct intel_dp *intel_dp)
5156{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005157 struct drm_i915_private *dev_priv = to_i915(dev);
5158
5159 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005160 vlv_initial_power_sequencer_setup(intel_dp);
5161 } else {
5162 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5163 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5164 }
5165}
5166
Vandana Kannanb33a2812015-02-13 15:33:03 +05305167/**
5168 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005169 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005170 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305171 * @refresh_rate: RR to be programmed
5172 *
5173 * This function gets called when refresh rate (RR) has to be changed from
5174 * one frequency to another. Switches can be between high and low RR
5175 * supported by the panel or to any other RR based on media playback (in
5176 * this case, RR value needs to be passed from user space).
5177 *
5178 * The caller of this function needs to take a lock on dev_priv->drrs.
5179 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005180static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5181 struct intel_crtc_state *crtc_state,
5182 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305183{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305184 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305185 struct intel_digital_port *dig_port = NULL;
5186 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005187 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305188 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305189
5190 if (refresh_rate <= 0) {
5191 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5192 return;
5193 }
5194
Vandana Kannan96178ee2015-01-10 02:25:56 +05305195 if (intel_dp == NULL) {
5196 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305197 return;
5198 }
5199
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005200 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005201 * FIXME: This needs proper synchronization with psr state for some
5202 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005203 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305204
Vandana Kannan96178ee2015-01-10 02:25:56 +05305205 dig_port = dp_to_dig_port(intel_dp);
5206 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005207 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305208
5209 if (!intel_crtc) {
5210 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5211 return;
5212 }
5213
Vandana Kannan96178ee2015-01-10 02:25:56 +05305214 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305215 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5216 return;
5217 }
5218
Vandana Kannan96178ee2015-01-10 02:25:56 +05305219 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5220 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305221 index = DRRS_LOW_RR;
5222
Vandana Kannan96178ee2015-01-10 02:25:56 +05305223 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305224 DRM_DEBUG_KMS(
5225 "DRRS requested for previously set RR...ignoring\n");
5226 return;
5227 }
5228
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005229 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305230 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5231 return;
5232 }
5233
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005234 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305235 switch (index) {
5236 case DRRS_HIGH_RR:
5237 intel_dp_set_m_n(intel_crtc, M1_N1);
5238 break;
5239 case DRRS_LOW_RR:
5240 intel_dp_set_m_n(intel_crtc, M2_N2);
5241 break;
5242 case DRRS_MAX_RR:
5243 default:
5244 DRM_ERROR("Unsupported refreshrate type\n");
5245 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005246 } else if (INTEL_GEN(dev_priv) > 6) {
5247 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005248 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305249
Ville Syrjälä649636e2015-09-22 19:50:01 +03005250 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305251 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005252 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305253 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5254 else
5255 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305256 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005257 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305258 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5259 else
5260 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305261 }
5262 I915_WRITE(reg, val);
5263 }
5264
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305265 dev_priv->drrs.refresh_rate_type = index;
5266
5267 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5268}
5269
Vandana Kannanb33a2812015-02-13 15:33:03 +05305270/**
5271 * intel_edp_drrs_enable - init drrs struct if supported
5272 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005273 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305274 *
5275 * Initializes frontbuffer_bits and drrs.dp
5276 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005277void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5278 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305279{
5280 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005281 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305282
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005283 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305284 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5285 return;
5286 }
5287
5288 mutex_lock(&dev_priv->drrs.mutex);
5289 if (WARN_ON(dev_priv->drrs.dp)) {
5290 DRM_ERROR("DRRS already enabled\n");
5291 goto unlock;
5292 }
5293
5294 dev_priv->drrs.busy_frontbuffer_bits = 0;
5295
5296 dev_priv->drrs.dp = intel_dp;
5297
5298unlock:
5299 mutex_unlock(&dev_priv->drrs.mutex);
5300}
5301
Vandana Kannanb33a2812015-02-13 15:33:03 +05305302/**
5303 * intel_edp_drrs_disable - Disable DRRS
5304 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005305 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305306 *
5307 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005308void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5309 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305310{
5311 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005312 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305313
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005314 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305315 return;
5316
5317 mutex_lock(&dev_priv->drrs.mutex);
5318 if (!dev_priv->drrs.dp) {
5319 mutex_unlock(&dev_priv->drrs.mutex);
5320 return;
5321 }
5322
5323 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005324 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5325 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305326
5327 dev_priv->drrs.dp = NULL;
5328 mutex_unlock(&dev_priv->drrs.mutex);
5329
5330 cancel_delayed_work_sync(&dev_priv->drrs.work);
5331}
5332
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305333static void intel_edp_drrs_downclock_work(struct work_struct *work)
5334{
5335 struct drm_i915_private *dev_priv =
5336 container_of(work, typeof(*dev_priv), drrs.work.work);
5337 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305338
Vandana Kannan96178ee2015-01-10 02:25:56 +05305339 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305340
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305341 intel_dp = dev_priv->drrs.dp;
5342
5343 if (!intel_dp)
5344 goto unlock;
5345
5346 /*
5347 * The delayed work can race with an invalidate hence we need to
5348 * recheck.
5349 */
5350
5351 if (dev_priv->drrs.busy_frontbuffer_bits)
5352 goto unlock;
5353
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005354 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5355 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5356
5357 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5358 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5359 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305360
5361unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305362 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305363}
5364
Vandana Kannanb33a2812015-02-13 15:33:03 +05305365/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305366 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005367 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305368 * @frontbuffer_bits: frontbuffer plane tracking bits
5369 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305370 * This function gets called everytime rendering on the given planes start.
5371 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305372 *
5373 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5374 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005375void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5376 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305377{
Vandana Kannana93fad02015-01-10 02:25:59 +05305378 struct drm_crtc *crtc;
5379 enum pipe pipe;
5380
Daniel Vetter9da7d692015-04-09 16:44:15 +02005381 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305382 return;
5383
Daniel Vetter88f933a2015-04-09 16:44:16 +02005384 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305385
Vandana Kannana93fad02015-01-10 02:25:59 +05305386 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005387 if (!dev_priv->drrs.dp) {
5388 mutex_unlock(&dev_priv->drrs.mutex);
5389 return;
5390 }
5391
Vandana Kannana93fad02015-01-10 02:25:59 +05305392 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5393 pipe = to_intel_crtc(crtc)->pipe;
5394
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005395 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5396 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5397
Ramalingam C0ddfd202015-06-15 20:50:05 +05305398 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005399 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005400 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5401 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305402
Vandana Kannana93fad02015-01-10 02:25:59 +05305403 mutex_unlock(&dev_priv->drrs.mutex);
5404}
5405
Vandana Kannanb33a2812015-02-13 15:33:03 +05305406/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305407 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005408 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305409 * @frontbuffer_bits: frontbuffer plane tracking bits
5410 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305411 * This function gets called every time rendering on the given planes has
5412 * completed or flip on a crtc is completed. So DRRS should be upclocked
5413 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5414 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305415 *
5416 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5417 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005418void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5419 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305420{
Vandana Kannana93fad02015-01-10 02:25:59 +05305421 struct drm_crtc *crtc;
5422 enum pipe pipe;
5423
Daniel Vetter9da7d692015-04-09 16:44:15 +02005424 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305425 return;
5426
Daniel Vetter88f933a2015-04-09 16:44:16 +02005427 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305428
Vandana Kannana93fad02015-01-10 02:25:59 +05305429 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005430 if (!dev_priv->drrs.dp) {
5431 mutex_unlock(&dev_priv->drrs.mutex);
5432 return;
5433 }
5434
Vandana Kannana93fad02015-01-10 02:25:59 +05305435 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5436 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005437
5438 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305439 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5440
Ramalingam C0ddfd202015-06-15 20:50:05 +05305441 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005442 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005443 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5444 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305445
5446 /*
5447 * flush also means no more activity hence schedule downclock, if all
5448 * other fbs are quiescent too
5449 */
5450 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305451 schedule_delayed_work(&dev_priv->drrs.work,
5452 msecs_to_jiffies(1000));
5453 mutex_unlock(&dev_priv->drrs.mutex);
5454}
5455
Vandana Kannanb33a2812015-02-13 15:33:03 +05305456/**
5457 * DOC: Display Refresh Rate Switching (DRRS)
5458 *
5459 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5460 * which enables swtching between low and high refresh rates,
5461 * dynamically, based on the usage scenario. This feature is applicable
5462 * for internal panels.
5463 *
5464 * Indication that the panel supports DRRS is given by the panel EDID, which
5465 * would list multiple refresh rates for one resolution.
5466 *
5467 * DRRS is of 2 types - static and seamless.
5468 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5469 * (may appear as a blink on screen) and is used in dock-undock scenario.
5470 * Seamless DRRS involves changing RR without any visual effect to the user
5471 * and can be used during normal system usage. This is done by programming
5472 * certain registers.
5473 *
5474 * Support for static/seamless DRRS may be indicated in the VBT based on
5475 * inputs from the panel spec.
5476 *
5477 * DRRS saves power by switching to low RR based on usage scenarios.
5478 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005479 * The implementation is based on frontbuffer tracking implementation. When
5480 * there is a disturbance on the screen triggered by user activity or a periodic
5481 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5482 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5483 * made.
5484 *
5485 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5486 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305487 *
5488 * DRRS can be further extended to support other internal panels and also
5489 * the scenario of video playback wherein RR is set based on the rate
5490 * requested by userspace.
5491 */
5492
5493/**
5494 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5495 * @intel_connector: eDP connector
5496 * @fixed_mode: preferred mode of panel
5497 *
5498 * This function is called only once at driver load to initialize basic
5499 * DRRS stuff.
5500 *
5501 * Returns:
5502 * Downclock mode if panel supports it, else return NULL.
5503 * DRRS support is determined by the presence of downclock mode (apart
5504 * from VBT setting).
5505 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305506static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305507intel_dp_drrs_init(struct intel_connector *intel_connector,
5508 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305509{
5510 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305511 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005512 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305513 struct drm_display_mode *downclock_mode = NULL;
5514
Daniel Vetter9da7d692015-04-09 16:44:15 +02005515 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5516 mutex_init(&dev_priv->drrs.mutex);
5517
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305518 if (INTEL_INFO(dev)->gen <= 6) {
5519 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5520 return NULL;
5521 }
5522
5523 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005524 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305525 return NULL;
5526 }
5527
5528 downclock_mode = intel_find_panel_downclock
5529 (dev, fixed_mode, connector);
5530
5531 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305532 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305533 return NULL;
5534 }
5535
Vandana Kannan96178ee2015-01-10 02:25:56 +05305536 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305537
Vandana Kannan96178ee2015-01-10 02:25:56 +05305538 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005539 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305540 return downclock_mode;
5541}
5542
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005543static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005544 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005545{
5546 struct drm_connector *connector = &intel_connector->base;
5547 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005548 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5549 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005550 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005551 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305552 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005553 bool has_dpcd;
5554 struct drm_display_mode *scan;
5555 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005556 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005557
5558 if (!is_edp(intel_dp))
5559 return true;
5560
Imre Deak97a824e12016-06-21 11:51:47 +03005561 /*
5562 * On IBX/CPT we may get here with LVDS already registered. Since the
5563 * driver uses the only internal power sequencer available for both
5564 * eDP and LVDS bail out early in this case to prevent interfering
5565 * with an already powered-on LVDS power sequencer.
5566 */
5567 if (intel_get_lvds_encoder(dev)) {
5568 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5569 DRM_INFO("LVDS was detected, not registering eDP\n");
5570
5571 return false;
5572 }
5573
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005574 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005575
5576 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005577 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005578 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005579
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005580 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005581
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005582 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005583 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005584
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005585 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005586 /* if this fails, presume the device is a ghost */
5587 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005588 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005589 }
5590
Daniel Vetter060c8772014-03-21 23:22:35 +01005591 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005592 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005593 if (edid) {
5594 if (drm_add_edid_modes(connector, edid)) {
5595 drm_mode_connector_update_edid_property(connector,
5596 edid);
5597 drm_edid_to_eld(connector, edid);
5598 } else {
5599 kfree(edid);
5600 edid = ERR_PTR(-EINVAL);
5601 }
5602 } else {
5603 edid = ERR_PTR(-ENOENT);
5604 }
5605 intel_connector->edid = edid;
5606
5607 /* prefer fixed mode from EDID if available */
5608 list_for_each_entry(scan, &connector->probed_modes, head) {
5609 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5610 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305611 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305612 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005613 break;
5614 }
5615 }
5616
5617 /* fallback to VBT if available for eDP */
5618 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5619 fixed_mode = drm_mode_duplicate(dev,
5620 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005621 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005622 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005623 connector->display_info.width_mm = fixed_mode->width_mm;
5624 connector->display_info.height_mm = fixed_mode->height_mm;
5625 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005626 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005627 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005628
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005629 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005630 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5631 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005632
5633 /*
5634 * Figure out the current pipe for the initial backlight setup.
5635 * If the current pipe isn't valid, try the PPS pipe, and if that
5636 * fails just assume pipe A.
5637 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005638 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6517d272014-11-07 11:16:02 +02005639 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5640 else
5641 pipe = PORT_TO_PIPE(intel_dp->DP);
5642
5643 if (pipe != PIPE_A && pipe != PIPE_B)
5644 pipe = intel_dp->pps_pipe;
5645
5646 if (pipe != PIPE_A && pipe != PIPE_B)
5647 pipe = PIPE_A;
5648
5649 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5650 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005651 }
5652
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305653 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005654 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005655 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005656
5657 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005658
5659out_vdd_off:
5660 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5661 /*
5662 * vdd might still be enabled do to the delayed vdd off.
5663 * Make sure vdd is actually turned off here.
5664 */
5665 pps_lock(intel_dp);
5666 edp_panel_vdd_off_sync(intel_dp);
5667 pps_unlock(intel_dp);
5668
5669 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005670}
5671
Paulo Zanoni16c25532013-06-12 17:27:25 -03005672bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005673intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5674 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005675{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005676 struct drm_connector *connector = &intel_connector->base;
5677 struct intel_dp *intel_dp = &intel_dig_port->dp;
5678 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5679 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005680 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005681 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005682 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005683
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005684 if (WARN(intel_dig_port->max_lanes < 1,
5685 "Not enough lanes (%d) for DP on port %c\n",
5686 intel_dig_port->max_lanes, port_name(port)))
5687 return false;
5688
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005689 intel_dp->pps_pipe = INVALID_PIPE;
5690
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005691 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005692 if (INTEL_INFO(dev)->gen >= 9)
5693 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005694 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005695 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005696 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005697 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5698 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005699 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005700
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005701 if (INTEL_INFO(dev)->gen >= 9)
5702 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5703 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005704 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005705
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005706 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005707 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5708
Daniel Vetter07679352012-09-06 22:15:42 +02005709 /* Preserve the current hw state. */
5710 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005711 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005712
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005713 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305714 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005715 else
5716 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005717
Imre Deakf7d24902013-05-08 13:14:05 +03005718 /*
5719 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5720 * for DP the encoder type can be set by the caller to
5721 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5722 */
5723 if (type == DRM_MODE_CONNECTOR_eDP)
5724 intel_encoder->type = INTEL_OUTPUT_EDP;
5725
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005726 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005727 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005728 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005729 return false;
5730
Imre Deake7281ea2013-05-08 13:14:08 +03005731 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5732 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5733 port_name(port));
5734
Adam Jacksonb3295302010-07-16 14:46:28 -04005735 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005736 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5737
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005738 connector->interlace_allowed = true;
5739 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005740
Mika Kaholab6339582016-09-09 14:10:52 +03005741 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005742
Daniel Vetter66a92782012-07-12 20:08:18 +02005743 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005744 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005745
Chris Wilsondf0e9242010-09-09 16:20:55 +01005746 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005747
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005748 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005749 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5750 else
5751 intel_connector->get_hw_state = intel_connector_get_hw_state;
5752
Jani Nikula0b998362014-03-14 16:51:17 +02005753 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005754 switch (port) {
5755 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005756 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005757 break;
5758 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005759 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005760 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305761 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005762 break;
5763 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005764 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005765 break;
5766 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005767 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005768 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005769 case PORT_E:
5770 intel_encoder->hpd_pin = HPD_PORT_E;
5771 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005772 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005773 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005774 }
5775
Dave Airlie0e32b392014-05-02 14:02:48 +10005776 /* init MST on ports that can support it */
Ville Syrjäläf8e58dd2016-06-22 21:56:59 +03005777 if (HAS_DP_MST(dev) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005778 (port == PORT_B || port == PORT_C || port == PORT_D))
5779 intel_dp_mst_encoder_init(intel_dig_port,
5780 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005781
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005782 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005783 intel_dp_aux_fini(intel_dp);
5784 intel_dp_mst_encoder_cleanup(intel_dig_port);
5785 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005786 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005787
Chris Wilsonf6849602010-09-19 09:29:33 +01005788 intel_dp_add_properties(intel_dp, connector);
5789
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005790 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5791 * 0xd. Failure to do so will result in spurious interrupts being
5792 * generated on the port when a cable is not attached.
5793 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005794 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005795 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5796 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5797 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005798
5799 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005800
5801fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005802 drm_connector_cleanup(connector);
5803
5804 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005805}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005806
Chris Wilson457c52d2016-06-01 08:27:50 +01005807bool intel_dp_init(struct drm_device *dev,
5808 i915_reg_t output_reg,
5809 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005810{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005811 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005812 struct intel_digital_port *intel_dig_port;
5813 struct intel_encoder *intel_encoder;
5814 struct drm_encoder *encoder;
5815 struct intel_connector *intel_connector;
5816
Daniel Vetterb14c5672013-09-19 12:18:32 +02005817 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005818 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005819 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005820
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005821 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305822 if (!intel_connector)
5823 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005824
5825 intel_encoder = &intel_dig_port->base;
5826 encoder = &intel_encoder->base;
5827
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305828 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005829 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305830 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005831
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005832 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005833 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005834 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005835 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005836 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005837 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005838 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005839 intel_encoder->pre_enable = chv_pre_enable_dp;
5840 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005841 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005842 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005843 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005844 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005845 intel_encoder->pre_enable = vlv_pre_enable_dp;
5846 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005847 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005848 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005849 intel_encoder->pre_enable = g4x_pre_enable_dp;
5850 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005851 if (INTEL_INFO(dev)->gen >= 5)
5852 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005853 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005854
Paulo Zanoni174edf12012-10-26 19:05:50 -02005855 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005856 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005857 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005858
Ville Syrjäläcca05022016-06-22 21:57:06 +03005859 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005860 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005861 if (port == PORT_D)
5862 intel_encoder->crtc_mask = 1 << 2;
5863 else
5864 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5865 } else {
5866 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5867 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005868 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005869 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005870
Dave Airlie13cf5502014-06-18 11:29:35 +10005871 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005872 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005873
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305874 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5875 goto err_init_connector;
5876
Chris Wilson457c52d2016-06-01 08:27:50 +01005877 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305878
5879err_init_connector:
5880 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305881err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305882 kfree(intel_connector);
5883err_connector_alloc:
5884 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005885 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005886}
Dave Airlie0e32b392014-05-02 14:02:48 +10005887
5888void intel_dp_mst_suspend(struct drm_device *dev)
5889{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005890 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005891 int i;
5892
5893 /* disable MST */
5894 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005895 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005896
5897 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005898 continue;
5899
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005900 if (intel_dig_port->dp.is_mst)
5901 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005902 }
5903}
5904
5905void intel_dp_mst_resume(struct drm_device *dev)
5906{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005907 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005908 int i;
5909
5910 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005911 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005912 int ret;
5913
5914 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005915 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005916
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005917 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5918 if (ret)
5919 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005920 }
5921}