blob: 63bf500edbbd0eba9ed52a9d78f996ac5187ce17 [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
347 if (IS_CHERRYVIEW(dev))
348 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) {
359 release_cl_override = IS_CHERRYVIEW(dev) &&
360 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
361
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000362 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
363 &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
Imre Deak78597992016-06-16 16:37:20 +0300573 if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
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
Wayne Boyer666a4532015-12-09 12:29:35 -0800667 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
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
Wayne Boyer666a4532015-12-09 12:29:35 -0800695 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
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
Wayne Boyer666a4532015-12-09 12:29:35 -0800709 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
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äf0f59a02015-11-18 15:33:26 +02001112static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1113 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001114{
1115 switch (port) {
1116 case PORT_B:
1117 case PORT_C:
1118 case PORT_D:
1119 return DP_AUX_CH_CTL(port);
1120 default:
1121 MISSING_CASE(port);
1122 return DP_AUX_CH_CTL(PORT_B);
1123 }
1124}
1125
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001126static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1127 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001128{
1129 switch (port) {
1130 case PORT_B:
1131 case PORT_C:
1132 case PORT_D:
1133 return DP_AUX_CH_DATA(port, index);
1134 default:
1135 MISSING_CASE(port);
1136 return DP_AUX_CH_DATA(PORT_B, index);
1137 }
1138}
1139
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001140static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1141 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001142{
1143 switch (port) {
1144 case PORT_A:
1145 return DP_AUX_CH_CTL(port);
1146 case PORT_B:
1147 case PORT_C:
1148 case PORT_D:
1149 return PCH_DP_AUX_CH_CTL(port);
1150 default:
1151 MISSING_CASE(port);
1152 return DP_AUX_CH_CTL(PORT_A);
1153 }
1154}
1155
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001156static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1157 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001158{
1159 switch (port) {
1160 case PORT_A:
1161 return DP_AUX_CH_DATA(port, index);
1162 case PORT_B:
1163 case PORT_C:
1164 case PORT_D:
1165 return PCH_DP_AUX_CH_DATA(port, index);
1166 default:
1167 MISSING_CASE(port);
1168 return DP_AUX_CH_DATA(PORT_A, index);
1169 }
1170}
1171
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001172/*
1173 * On SKL we don't have Aux for port E so we rely
1174 * on VBT to set a proper alternate aux channel.
1175 */
1176static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
1177{
1178 const struct ddi_vbt_port_info *info =
1179 &dev_priv->vbt.ddi_port_info[PORT_E];
1180
1181 switch (info->alternate_aux_channel) {
1182 case DP_AUX_A:
1183 return PORT_A;
1184 case DP_AUX_B:
1185 return PORT_B;
1186 case DP_AUX_C:
1187 return PORT_C;
1188 case DP_AUX_D:
1189 return PORT_D;
1190 default:
1191 MISSING_CASE(info->alternate_aux_channel);
1192 return PORT_A;
1193 }
1194}
1195
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001196static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1197 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001198{
1199 if (port == PORT_E)
1200 port = skl_porte_aux_port(dev_priv);
1201
1202 switch (port) {
1203 case PORT_A:
1204 case PORT_B:
1205 case PORT_C:
1206 case PORT_D:
1207 return DP_AUX_CH_CTL(port);
1208 default:
1209 MISSING_CASE(port);
1210 return DP_AUX_CH_CTL(PORT_A);
1211 }
1212}
1213
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001214static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1215 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001216{
1217 if (port == PORT_E)
1218 port = skl_porte_aux_port(dev_priv);
1219
1220 switch (port) {
1221 case PORT_A:
1222 case PORT_B:
1223 case PORT_C:
1224 case PORT_D:
1225 return DP_AUX_CH_DATA(port, index);
1226 default:
1227 MISSING_CASE(port);
1228 return DP_AUX_CH_DATA(PORT_A, index);
1229 }
1230}
1231
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001232static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1233 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001234{
1235 if (INTEL_INFO(dev_priv)->gen >= 9)
1236 return skl_aux_ctl_reg(dev_priv, port);
1237 else if (HAS_PCH_SPLIT(dev_priv))
1238 return ilk_aux_ctl_reg(dev_priv, port);
1239 else
1240 return g4x_aux_ctl_reg(dev_priv, port);
1241}
1242
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001243static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1244 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001245{
1246 if (INTEL_INFO(dev_priv)->gen >= 9)
1247 return skl_aux_data_reg(dev_priv, port, index);
1248 else if (HAS_PCH_SPLIT(dev_priv))
1249 return ilk_aux_data_reg(dev_priv, port, index);
1250 else
1251 return g4x_aux_data_reg(dev_priv, port, index);
1252}
1253
1254static void intel_aux_reg_init(struct intel_dp *intel_dp)
1255{
1256 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1257 enum port port = dp_to_dig_port(intel_dp)->port;
1258 int i;
1259
1260 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1261 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1262 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1263}
1264
Jani Nikula9d1a1032014-03-14 16:51:15 +02001265static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001266intel_dp_aux_fini(struct intel_dp *intel_dp)
1267{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001268 kfree(intel_dp->aux.name);
1269}
1270
Chris Wilson7a418e32016-06-24 14:00:14 +01001271static void
Mika Kaholab6339582016-09-09 14:10:52 +03001272intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001273{
Jani Nikula33ad6622014-03-14 16:51:16 +02001274 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1275 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001276
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001277 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001278 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001279
Chris Wilson7a418e32016-06-24 14:00:14 +01001280 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001281 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001282 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001283}
1284
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301285static int
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001286intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301287{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001288 if (intel_dp->num_sink_rates) {
1289 *sink_rates = intel_dp->sink_rates;
1290 return intel_dp->num_sink_rates;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301291 }
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001292
1293 *sink_rates = default_rates;
1294
1295 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301296}
1297
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001298bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301299{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001300 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001301 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001302
Navare, Manasi D577c5432016-09-27 16:36:53 -07001303 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1304 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301305 return true;
1306 else
1307 return false;
1308}
1309
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301310static int
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001311intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301312{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001313 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001314 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301315 int size;
1316
Navare, Manasi D577c5432016-09-27 16:36:53 -07001317 if (IS_BROXTON(dev_priv)) {
Sonika Jindal64987fc2015-05-26 17:50:13 +05301318 *source_rates = bxt_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301319 size = ARRAY_SIZE(bxt_rates);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001320 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Sonika Jindal637a9c62015-05-07 09:52:08 +05301321 *source_rates = skl_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301322 size = ARRAY_SIZE(skl_rates);
1323 } else {
1324 *source_rates = default_rates;
1325 size = ARRAY_SIZE(default_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301326 }
Ville Syrjälä636280b2015-03-12 17:10:29 +02001327
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301328 /* This depends on the fact that 5.4 is last value in the array */
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001329 if (!intel_dp_source_supports_hbr2(intel_dp))
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301330 size--;
Ville Syrjälä636280b2015-03-12 17:10:29 +02001331
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301332 return size;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301333}
1334
Daniel Vetter0e503382014-07-04 11:26:04 -03001335static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001336intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001337 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001338{
1339 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001340 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001341 const struct dp_link_dpll *divisor = NULL;
1342 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001343
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001344 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001345 divisor = gen4_dpll;
1346 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001347 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001348 divisor = pch_dpll;
1349 count = ARRAY_SIZE(pch_dpll);
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001350 } else if (IS_CHERRYVIEW(dev)) {
1351 divisor = chv_dpll;
1352 count = ARRAY_SIZE(chv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001353 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001354 divisor = vlv_dpll;
1355 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001356 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001357
1358 if (divisor && count) {
1359 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001360 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001361 pipe_config->dpll = divisor[i].dpll;
1362 pipe_config->clock_set = true;
1363 break;
1364 }
1365 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001366 }
1367}
1368
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001369static int intersect_rates(const int *source_rates, int source_len,
1370 const int *sink_rates, int sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001371 int *common_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301372{
1373 int i = 0, j = 0, k = 0;
1374
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301375 while (i < source_len && j < sink_len) {
1376 if (source_rates[i] == sink_rates[j]) {
Ville Syrjäläe6bda3e2015-03-12 17:10:37 +02001377 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
1378 return k;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001379 common_rates[k] = source_rates[i];
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301380 ++k;
1381 ++i;
1382 ++j;
1383 } else if (source_rates[i] < sink_rates[j]) {
1384 ++i;
1385 } else {
1386 ++j;
1387 }
1388 }
1389 return k;
1390}
1391
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001392static int intel_dp_common_rates(struct intel_dp *intel_dp,
1393 int *common_rates)
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001394{
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001395 const int *source_rates, *sink_rates;
1396 int source_len, sink_len;
1397
1398 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001399 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001400
1401 return intersect_rates(source_rates, source_len,
1402 sink_rates, sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001403 common_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001404}
1405
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001406static void snprintf_int_array(char *str, size_t len,
1407 const int *array, int nelem)
1408{
1409 int i;
1410
1411 str[0] = '\0';
1412
1413 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001414 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001415 if (r >= len)
1416 return;
1417 str += r;
1418 len -= r;
1419 }
1420}
1421
1422static void intel_dp_print_rates(struct intel_dp *intel_dp)
1423{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001424 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001425 int source_len, sink_len, common_len;
1426 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001427 char str[128]; /* FIXME: too big for stack? */
1428
1429 if ((drm_debug & DRM_UT_KMS) == 0)
1430 return;
1431
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001432 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001433 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1434 DRM_DEBUG_KMS("source rates: %s\n", str);
1435
1436 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1437 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1438 DRM_DEBUG_KMS("sink rates: %s\n", str);
1439
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001440 common_len = intel_dp_common_rates(intel_dp, common_rates);
1441 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1442 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001443}
1444
Mika Kahola0e390a32016-09-09 14:10:53 +03001445static void intel_dp_print_hw_revision(struct intel_dp *intel_dp)
1446{
1447 uint8_t rev;
1448 int len;
1449
1450 if ((drm_debug & DRM_UT_KMS) == 0)
1451 return;
1452
1453 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1454 DP_DWN_STRM_PORT_PRESENT))
1455 return;
1456
1457 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_HW_REV, &rev, 1);
1458 if (len < 0)
1459 return;
1460
1461 DRM_DEBUG_KMS("sink hw revision: %d.%d\n", (rev & 0xf0) >> 4, rev & 0xf);
1462}
1463
Mika Kahola1a2724f2016-09-09 14:10:54 +03001464static void intel_dp_print_sw_revision(struct intel_dp *intel_dp)
1465{
1466 uint8_t rev[2];
1467 int len;
1468
1469 if ((drm_debug & DRM_UT_KMS) == 0)
1470 return;
1471
1472 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1473 DP_DWN_STRM_PORT_PRESENT))
1474 return;
1475
1476 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_SW_REV, &rev, 2);
1477 if (len < 0)
1478 return;
1479
1480 DRM_DEBUG_KMS("sink sw revision: %d.%d\n", rev[0], rev[1]);
1481}
1482
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001483static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301484{
1485 int i = 0;
1486
1487 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1488 if (find == rates[i])
1489 break;
1490
1491 return i;
1492}
1493
Ville Syrjälä50fec212015-03-12 17:10:34 +02001494int
1495intel_dp_max_link_rate(struct intel_dp *intel_dp)
1496{
1497 int rates[DP_MAX_SUPPORTED_RATES] = {};
1498 int len;
1499
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001500 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001501 if (WARN_ON(len <= 0))
1502 return 162000;
1503
Ville Syrjälä1354f732016-07-28 17:50:45 +03001504 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001505}
1506
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001507int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1508{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001509 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001510}
1511
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001512void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1513 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001514{
1515 if (intel_dp->num_sink_rates) {
1516 *link_bw = 0;
1517 *rate_select =
1518 intel_dp_rate_select(intel_dp, port_clock);
1519 } else {
1520 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1521 *rate_select = 0;
1522 }
1523}
1524
Jani Nikulaf580bea2016-09-15 16:28:52 +03001525static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1526 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001527{
1528 int bpp, bpc;
1529
1530 bpp = pipe_config->pipe_bpp;
1531 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1532
1533 if (bpc > 0)
1534 bpp = min(bpp, 3*bpc);
1535
1536 return bpp;
1537}
1538
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001539bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001540intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001541 struct intel_crtc_state *pipe_config,
1542 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001543{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001544 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001545 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001546 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001547 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001548 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001549 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001550 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001551 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001552 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001553 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001554 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001555 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301556 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001557 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001558 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001559 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1560 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001561 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301562
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001563 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301564
1565 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001566 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301567
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001568 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001569
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001570 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001571 pipe_config->has_pch_encoder = true;
1572
Vandana Kannanf769cd22014-08-05 07:51:22 -07001573 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001574 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001575
Jani Nikuladd06f902012-10-19 14:51:50 +03001576 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1577 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1578 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001579
1580 if (INTEL_INFO(dev)->gen >= 9) {
1581 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001582 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001583 if (ret)
1584 return ret;
1585 }
1586
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001587 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001588 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1589 intel_connector->panel.fitting_mode);
1590 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001591 intel_pch_panel_fitting(intel_crtc, pipe_config,
1592 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001593 }
1594
Daniel Vettercb1793c2012-06-04 18:39:21 +02001595 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001596 return false;
1597
Daniel Vetter083f9562012-04-20 20:23:49 +02001598 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301599 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001600 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001601 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001602
Daniel Vetter36008362013-03-27 00:44:59 +01001603 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1604 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001605 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001606 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301607
1608 /* Get bpp from vbt only for panels that dont have bpp in edid */
1609 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001610 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001611 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001612 dev_priv->vbt.edp.bpp);
1613 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001614 }
1615
Jani Nikula344c5bb2014-09-09 11:25:13 +03001616 /*
1617 * Use the maximum clock and number of lanes the eDP panel
1618 * advertizes being capable of. The panels are generally
1619 * designed to support only a single clock and lane
1620 * configuration, and typically these values correspond to the
1621 * native resolution of the panel.
1622 */
1623 min_lane_count = max_lane_count;
1624 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001625 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001626
Daniel Vetter36008362013-03-27 00:44:59 +01001627 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001628 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1629 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001630
Dave Airliec6930992014-07-14 11:04:39 +10001631 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301632 for (lane_count = min_lane_count;
1633 lane_count <= max_lane_count;
1634 lane_count <<= 1) {
1635
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001636 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001637 link_avail = intel_dp_max_data_rate(link_clock,
1638 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001639
Daniel Vetter36008362013-03-27 00:44:59 +01001640 if (mode_rate <= link_avail) {
1641 goto found;
1642 }
1643 }
1644 }
1645 }
1646
1647 return false;
1648
1649found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001650 if (intel_dp->color_range_auto) {
1651 /*
1652 * See:
1653 * CEA-861-E - 5.1 Default Encoding Parameters
1654 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1655 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001656 pipe_config->limited_color_range =
1657 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1658 } else {
1659 pipe_config->limited_color_range =
1660 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001661 }
1662
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001663 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301664
Daniel Vetter657445f2013-05-04 10:09:18 +02001665 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001666 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001667
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001668 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1669 &link_bw, &rate_select);
1670
1671 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1672 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001673 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001674 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1675 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001676
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001677 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001678 adjusted_mode->crtc_clock,
1679 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001680 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001681
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301682 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301683 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001684 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301685 intel_link_compute_m_n(bpp, lane_count,
1686 intel_connector->panel.downclock_mode->clock,
1687 pipe_config->port_clock,
1688 &pipe_config->dp_m2_n2);
1689 }
1690
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001691 /*
1692 * DPLL0 VCO may need to be adjusted to get the correct
1693 * clock for eDP. This will affect cdclk as well.
1694 */
1695 if (is_edp(intel_dp) &&
1696 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1697 int vco;
1698
1699 switch (pipe_config->port_clock / 2) {
1700 case 108000:
1701 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001702 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001703 break;
1704 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001705 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001706 break;
1707 }
1708
1709 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1710 }
1711
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001712 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001713 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001714
Daniel Vetter36008362013-03-27 00:44:59 +01001715 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001716}
1717
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001718void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001719 int link_rate, uint8_t lane_count,
1720 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001721{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001722 intel_dp->link_rate = link_rate;
1723 intel_dp->lane_count = lane_count;
1724 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001725}
1726
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001727static void intel_dp_prepare(struct intel_encoder *encoder,
1728 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001729{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001730 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001731 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001732 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001733 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001734 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001735 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001736
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001737 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1738 pipe_config->lane_count,
1739 intel_crtc_has_type(pipe_config,
1740 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001741
Keith Packard417e8222011-11-01 19:54:11 -07001742 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001743 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001744 *
1745 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001746 * SNB CPU
1747 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001748 * CPT PCH
1749 *
1750 * IBX PCH and CPU are the same for almost everything,
1751 * except that the CPU DP PLL is configured in this
1752 * register
1753 *
1754 * CPT PCH is quite different, having many bits moved
1755 * to the TRANS_DP_CTL register instead. That
1756 * configuration happens (oddly) in ironlake_pch_enable
1757 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001758
Keith Packard417e8222011-11-01 19:54:11 -07001759 /* Preserve the BIOS-computed detected bit. This is
1760 * supposed to be read-only.
1761 */
1762 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001763
Keith Packard417e8222011-11-01 19:54:11 -07001764 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001765 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001766 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001767
Keith Packard417e8222011-11-01 19:54:11 -07001768 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001769
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001770 if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001771 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1772 intel_dp->DP |= DP_SYNC_HS_HIGH;
1773 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1774 intel_dp->DP |= DP_SYNC_VS_HIGH;
1775 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1776
Jani Nikula6aba5b62013-10-04 15:08:10 +03001777 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001778 intel_dp->DP |= DP_ENHANCED_FRAMING;
1779
Daniel Vetter7c62a162013-06-01 17:16:20 +02001780 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001781 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001782 u32 trans_dp;
1783
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001784 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001785
1786 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1787 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1788 trans_dp |= TRANS_DP_ENH_FRAMING;
1789 else
1790 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1791 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001792 } else {
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001793 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev) &&
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001794 !IS_CHERRYVIEW(dev) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001795 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001796
1797 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1798 intel_dp->DP |= DP_SYNC_HS_HIGH;
1799 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1800 intel_dp->DP |= DP_SYNC_VS_HIGH;
1801 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1802
Jani Nikula6aba5b62013-10-04 15:08:10 +03001803 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001804 intel_dp->DP |= DP_ENHANCED_FRAMING;
1805
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001806 if (IS_CHERRYVIEW(dev))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001807 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001808 else if (crtc->pipe == PIPE_B)
1809 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001810 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001811}
1812
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001813#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1814#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001815
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001816#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1817#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001818
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001819#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1820#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001821
Imre Deakde9c1b62016-06-16 20:01:46 +03001822static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1823 struct intel_dp *intel_dp);
1824
Daniel Vetter4be73782014-01-17 14:39:48 +01001825static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001826 u32 mask,
1827 u32 value)
1828{
Paulo Zanoni30add222012-10-26 19:05:45 -02001829 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001830 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001831 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001832
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001833 lockdep_assert_held(&dev_priv->pps_mutex);
1834
Imre Deakde9c1b62016-06-16 20:01:46 +03001835 intel_pps_verify_state(dev_priv, intel_dp);
1836
Jani Nikulabf13e812013-09-06 07:40:05 +03001837 pp_stat_reg = _pp_stat_reg(intel_dp);
1838 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001839
1840 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001841 mask, value,
1842 I915_READ(pp_stat_reg),
1843 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001844
Chris Wilson9036ff02016-06-30 15:33:09 +01001845 if (intel_wait_for_register(dev_priv,
1846 pp_stat_reg, mask, value,
1847 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001848 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001849 I915_READ(pp_stat_reg),
1850 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001851
1852 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001853}
1854
Daniel Vetter4be73782014-01-17 14:39:48 +01001855static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001856{
1857 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001858 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001859}
1860
Daniel Vetter4be73782014-01-17 14:39:48 +01001861static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001862{
Keith Packardbd943152011-09-18 23:09:52 -07001863 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001864 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001865}
Keith Packardbd943152011-09-18 23:09:52 -07001866
Daniel Vetter4be73782014-01-17 14:39:48 +01001867static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001868{
Abhay Kumard28d4732016-01-22 17:39:04 -08001869 ktime_t panel_power_on_time;
1870 s64 panel_power_off_duration;
1871
Keith Packard99ea7122011-11-01 19:57:50 -07001872 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001873
Abhay Kumard28d4732016-01-22 17:39:04 -08001874 /* take the difference of currrent time and panel power off time
1875 * and then make panel wait for t11_t12 if needed. */
1876 panel_power_on_time = ktime_get_boottime();
1877 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1878
Paulo Zanonidce56b32013-12-19 14:29:40 -02001879 /* When we disable the VDD override bit last we have to do the manual
1880 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001881 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1882 wait_remaining_ms_from_jiffies(jiffies,
1883 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001884
Daniel Vetter4be73782014-01-17 14:39:48 +01001885 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001886}
Keith Packardbd943152011-09-18 23:09:52 -07001887
Daniel Vetter4be73782014-01-17 14:39:48 +01001888static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001889{
1890 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1891 intel_dp->backlight_on_delay);
1892}
1893
Daniel Vetter4be73782014-01-17 14:39:48 +01001894static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001895{
1896 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1897 intel_dp->backlight_off_delay);
1898}
Keith Packard99ea7122011-11-01 19:57:50 -07001899
Keith Packard832dd3c2011-11-01 19:34:06 -07001900/* Read the current pp_control value, unlocking the register if it
1901 * is locked
1902 */
1903
Jesse Barnes453c5422013-03-28 09:55:41 -07001904static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001905{
Jesse Barnes453c5422013-03-28 09:55:41 -07001906 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001907 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001908 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001909
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001910 lockdep_assert_held(&dev_priv->pps_mutex);
1911
Jani Nikulabf13e812013-09-06 07:40:05 +03001912 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001913 if (WARN_ON(!HAS_DDI(dev_priv) &&
1914 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301915 control &= ~PANEL_UNLOCK_MASK;
1916 control |= PANEL_UNLOCK_REGS;
1917 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001918 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001919}
1920
Ville Syrjälä951468f2014-09-04 14:55:31 +03001921/*
1922 * Must be paired with edp_panel_vdd_off().
1923 * Must hold pps_mutex around the whole on/off sequence.
1924 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1925 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001926static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001927{
Paulo Zanoni30add222012-10-26 19:05:45 -02001928 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001929 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1930 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001931 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001932 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001933 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001934 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001935 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001936
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001937 lockdep_assert_held(&dev_priv->pps_mutex);
1938
Keith Packard97af61f572011-09-28 16:23:51 -07001939 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001940 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001941
Egbert Eich2c623c12014-11-25 12:54:57 +01001942 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001943 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001944
Daniel Vetter4be73782014-01-17 14:39:48 +01001945 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001946 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001947
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001948 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001949 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001950
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001951 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1952 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001953
Daniel Vetter4be73782014-01-17 14:39:48 +01001954 if (!edp_have_panel_power(intel_dp))
1955 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001956
Jesse Barnes453c5422013-03-28 09:55:41 -07001957 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001958 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001959
Jani Nikulabf13e812013-09-06 07:40:05 +03001960 pp_stat_reg = _pp_stat_reg(intel_dp);
1961 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001962
1963 I915_WRITE(pp_ctrl_reg, pp);
1964 POSTING_READ(pp_ctrl_reg);
1965 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1966 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001967 /*
1968 * If the panel wasn't on, delay before accessing aux channel
1969 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001970 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001971 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1972 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001973 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001974 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001975
1976 return need_to_disable;
1977}
1978
Ville Syrjälä951468f2014-09-04 14:55:31 +03001979/*
1980 * Must be paired with intel_edp_panel_vdd_off() or
1981 * intel_edp_panel_off().
1982 * Nested calls to these functions are not allowed since
1983 * we drop the lock. Caller must use some higher level
1984 * locking to prevent nested calls from other threads.
1985 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001986void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001987{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001988 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001989
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001990 if (!is_edp(intel_dp))
1991 return;
1992
Ville Syrjälä773538e82014-09-04 14:54:56 +03001993 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001994 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001995 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001996
Rob Clarke2c719b2014-12-15 13:56:32 -05001997 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001998 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08001999}
2000
Daniel Vetter4be73782014-01-17 14:39:48 +01002001static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002002{
Paulo Zanoni30add222012-10-26 19:05:45 -02002003 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002004 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002005 struct intel_digital_port *intel_dig_port =
2006 dp_to_dig_port(intel_dp);
2007 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2008 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002009 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002010 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002011
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002012 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002013
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002014 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002015
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002016 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002017 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002018
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002019 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2020 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002021
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002022 pp = ironlake_get_pp_control(intel_dp);
2023 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002024
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002025 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2026 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002027
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002028 I915_WRITE(pp_ctrl_reg, pp);
2029 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002030
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002031 /* Make sure sequencer is idle before allowing subsequent activity */
2032 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2033 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002034
Imre Deak5a162e22016-08-10 14:07:30 +03002035 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002036 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002037
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002038 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002039 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002040}
2041
Daniel Vetter4be73782014-01-17 14:39:48 +01002042static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002043{
2044 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2045 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002046
Ville Syrjälä773538e82014-09-04 14:54:56 +03002047 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002048 if (!intel_dp->want_panel_vdd)
2049 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002050 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002051}
2052
Imre Deakaba86892014-07-30 15:57:31 +03002053static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2054{
2055 unsigned long delay;
2056
2057 /*
2058 * Queue the timer to fire a long time from now (relative to the power
2059 * down delay) to keep the panel power up across a sequence of
2060 * operations.
2061 */
2062 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2063 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2064}
2065
Ville Syrjälä951468f2014-09-04 14:55:31 +03002066/*
2067 * Must be paired with edp_panel_vdd_on().
2068 * Must hold pps_mutex around the whole on/off sequence.
2069 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2070 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002071static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002072{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002073 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002074
2075 lockdep_assert_held(&dev_priv->pps_mutex);
2076
Keith Packard97af61f572011-09-28 16:23:51 -07002077 if (!is_edp(intel_dp))
2078 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002079
Rob Clarke2c719b2014-12-15 13:56:32 -05002080 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002081 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002082
Keith Packardbd943152011-09-18 23:09:52 -07002083 intel_dp->want_panel_vdd = false;
2084
Imre Deakaba86892014-07-30 15:57:31 +03002085 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002086 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002087 else
2088 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002089}
2090
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002091static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002092{
Paulo Zanoni30add222012-10-26 19:05:45 -02002093 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002094 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002095 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002096 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002097
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002098 lockdep_assert_held(&dev_priv->pps_mutex);
2099
Keith Packard97af61f572011-09-28 16:23:51 -07002100 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002101 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002102
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002103 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2104 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002105
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002106 if (WARN(edp_have_panel_power(intel_dp),
2107 "eDP port %c panel power already on\n",
2108 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002109 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002110
Daniel Vetter4be73782014-01-17 14:39:48 +01002111 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002112
Jani Nikulabf13e812013-09-06 07:40:05 +03002113 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002114 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07002115 if (IS_GEN5(dev)) {
2116 /* ILK workaround: disable reset around power sequence */
2117 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002118 I915_WRITE(pp_ctrl_reg, pp);
2119 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002120 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002121
Imre Deak5a162e22016-08-10 14:07:30 +03002122 pp |= PANEL_POWER_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07002123 if (!IS_GEN5(dev))
2124 pp |= PANEL_POWER_RESET;
2125
Jesse Barnes453c5422013-03-28 09:55:41 -07002126 I915_WRITE(pp_ctrl_reg, pp);
2127 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002128
Daniel Vetter4be73782014-01-17 14:39:48 +01002129 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002130 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002131
Keith Packard05ce1a42011-09-29 16:33:01 -07002132 if (IS_GEN5(dev)) {
2133 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002134 I915_WRITE(pp_ctrl_reg, pp);
2135 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002136 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002137}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002138
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002139void intel_edp_panel_on(struct intel_dp *intel_dp)
2140{
2141 if (!is_edp(intel_dp))
2142 return;
2143
2144 pps_lock(intel_dp);
2145 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002146 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002147}
2148
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002149
2150static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002151{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002152 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2153 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002155 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002156 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002157 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002158 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002159
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002160 lockdep_assert_held(&dev_priv->pps_mutex);
2161
Keith Packard97af61f572011-09-28 16:23:51 -07002162 if (!is_edp(intel_dp))
2163 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002164
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002165 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2166 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002167
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002168 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2169 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002170
Jesse Barnes453c5422013-03-28 09:55:41 -07002171 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002172 /* We need to switch off panel power _and_ force vdd, for otherwise some
2173 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002174 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002175 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002176
Jani Nikulabf13e812013-09-06 07:40:05 +03002177 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002178
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002179 intel_dp->want_panel_vdd = false;
2180
Jesse Barnes453c5422013-03-28 09:55:41 -07002181 I915_WRITE(pp_ctrl_reg, pp);
2182 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002183
Abhay Kumard28d4732016-01-22 17:39:04 -08002184 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002185 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002186
2187 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002188 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002189 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002190}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002191
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002192void intel_edp_panel_off(struct intel_dp *intel_dp)
2193{
2194 if (!is_edp(intel_dp))
2195 return;
2196
2197 pps_lock(intel_dp);
2198 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002199 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002200}
2201
Jani Nikula1250d102014-08-12 17:11:39 +03002202/* Enable backlight in the panel power control. */
2203static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002204{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002205 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2206 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002207 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002208 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002209 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002210
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002211 /*
2212 * If we enable the backlight right away following a panel power
2213 * on, we may see slight flicker as the panel syncs with the eDP
2214 * link. So delay a bit to make sure the image is solid before
2215 * allowing it to appear.
2216 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002217 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002218
Ville Syrjälä773538e82014-09-04 14:54:56 +03002219 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002220
Jesse Barnes453c5422013-03-28 09:55:41 -07002221 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002222 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002223
Jani Nikulabf13e812013-09-06 07:40:05 +03002224 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002225
2226 I915_WRITE(pp_ctrl_reg, pp);
2227 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002228
Ville Syrjälä773538e82014-09-04 14:54:56 +03002229 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002230}
2231
Jani Nikula1250d102014-08-12 17:11:39 +03002232/* Enable backlight PWM and backlight PP control. */
2233void intel_edp_backlight_on(struct intel_dp *intel_dp)
2234{
2235 if (!is_edp(intel_dp))
2236 return;
2237
2238 DRM_DEBUG_KMS("\n");
2239
2240 intel_panel_enable_backlight(intel_dp->attached_connector);
2241 _intel_edp_backlight_on(intel_dp);
2242}
2243
2244/* Disable backlight in the panel power control. */
2245static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002246{
Paulo Zanoni30add222012-10-26 19:05:45 -02002247 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002248 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002249 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002250 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002251
Keith Packardf01eca22011-09-28 16:48:10 -07002252 if (!is_edp(intel_dp))
2253 return;
2254
Ville Syrjälä773538e82014-09-04 14:54:56 +03002255 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002256
Jesse Barnes453c5422013-03-28 09:55:41 -07002257 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002258 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002259
Jani Nikulabf13e812013-09-06 07:40:05 +03002260 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002261
2262 I915_WRITE(pp_ctrl_reg, pp);
2263 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002264
Ville Syrjälä773538e82014-09-04 14:54:56 +03002265 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002266
Paulo Zanonidce56b32013-12-19 14:29:40 -02002267 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002268 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002269}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002270
Jani Nikula1250d102014-08-12 17:11:39 +03002271/* Disable backlight PP control and backlight PWM. */
2272void intel_edp_backlight_off(struct intel_dp *intel_dp)
2273{
2274 if (!is_edp(intel_dp))
2275 return;
2276
2277 DRM_DEBUG_KMS("\n");
2278
2279 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002280 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002281}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002282
Jani Nikula73580fb72014-08-12 17:11:41 +03002283/*
2284 * Hook for controlling the panel power control backlight through the bl_power
2285 * sysfs attribute. Take care to handle multiple calls.
2286 */
2287static void intel_edp_backlight_power(struct intel_connector *connector,
2288 bool enable)
2289{
2290 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002291 bool is_enabled;
2292
Ville Syrjälä773538e82014-09-04 14:54:56 +03002293 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002294 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002295 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002296
2297 if (is_enabled == enable)
2298 return;
2299
Jani Nikula23ba9372014-08-27 14:08:43 +03002300 DRM_DEBUG_KMS("panel power control backlight %s\n",
2301 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002302
2303 if (enable)
2304 _intel_edp_backlight_on(intel_dp);
2305 else
2306 _intel_edp_backlight_off(intel_dp);
2307}
2308
Ville Syrjälä64e10772015-10-29 21:26:01 +02002309static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2310{
2311 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2312 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2313 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2314
2315 I915_STATE_WARN(cur_state != state,
2316 "DP port %c state assertion failure (expected %s, current %s)\n",
2317 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002318 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002319}
2320#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2321
2322static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2323{
2324 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2325
2326 I915_STATE_WARN(cur_state != state,
2327 "eDP PLL state assertion failure (expected %s, current %s)\n",
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_edp_pll_enabled(d) assert_edp_pll((d), true)
2331#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2332
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002333static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2334 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002335{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002336 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002337 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002338
Ville Syrjälä64e10772015-10-29 21:26:01 +02002339 assert_pipe_disabled(dev_priv, crtc->pipe);
2340 assert_dp_port_disabled(intel_dp);
2341 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002342
Ville Syrjäläabfce942015-10-29 21:26:03 +02002343 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002344 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002345
2346 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2347
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002348 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002349 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2350 else
2351 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2352
2353 I915_WRITE(DP_A, intel_dp->DP);
2354 POSTING_READ(DP_A);
2355 udelay(500);
2356
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002357 /*
2358 * [DevILK] Work around required when enabling DP PLL
2359 * while a pipe is enabled going to FDI:
2360 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2361 * 2. Program DP PLL enable
2362 */
2363 if (IS_GEN5(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +01002364 intel_wait_for_vblank_if_active(&dev_priv->drm, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002365
Daniel Vetter07679352012-09-06 22:15:42 +02002366 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002367
Daniel Vetter07679352012-09-06 22:15:42 +02002368 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002369 POSTING_READ(DP_A);
2370 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002371}
2372
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002373static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002374{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002375 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002376 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2377 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002378
Ville Syrjälä64e10772015-10-29 21:26:01 +02002379 assert_pipe_disabled(dev_priv, crtc->pipe);
2380 assert_dp_port_disabled(intel_dp);
2381 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002382
Ville Syrjäläabfce942015-10-29 21:26:03 +02002383 DRM_DEBUG_KMS("disabling eDP PLL\n");
2384
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002385 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002386
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002387 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002388 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002389 udelay(200);
2390}
2391
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002392/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002393void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002394{
2395 int ret, i;
2396
2397 /* Should have a valid DPCD by this point */
2398 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2399 return;
2400
2401 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002402 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2403 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002404 } else {
2405 /*
2406 * When turning on, we need to retry for 1ms to give the sink
2407 * time to wake up.
2408 */
2409 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002410 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2411 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002412 if (ret == 1)
2413 break;
2414 msleep(1);
2415 }
2416 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002417
2418 if (ret != 1)
2419 DRM_DEBUG_KMS("failed to %s sink power state\n",
2420 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002421}
2422
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002423static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2424 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002425{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002426 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002427 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002428 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002429 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002430 enum intel_display_power_domain power_domain;
2431 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002432 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002433
2434 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002435 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002436 return false;
2437
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002438 ret = false;
2439
Imre Deak6d129be2014-03-05 16:20:54 +02002440 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002441
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002442 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002443 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002444
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002445 if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002446 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002447 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002448 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002449
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002450 for_each_pipe(dev_priv, p) {
2451 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2452 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2453 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002454 ret = true;
2455
2456 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002457 }
2458 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002459
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002460 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002461 i915_mmio_reg_offset(intel_dp->output_reg));
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002462 } else if (IS_CHERRYVIEW(dev)) {
2463 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2464 } else {
2465 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002466 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002467
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002468 ret = true;
2469
2470out:
2471 intel_display_power_put(dev_priv, power_domain);
2472
2473 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002474}
2475
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002476static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002477 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002478{
2479 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002480 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002481 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002482 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002483 enum port port = dp_to_dig_port(intel_dp)->port;
2484 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002485
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002486 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002487
2488 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002489
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002490 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002491 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2492
2493 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002494 flags |= DRM_MODE_FLAG_PHSYNC;
2495 else
2496 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002497
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002498 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002499 flags |= DRM_MODE_FLAG_PVSYNC;
2500 else
2501 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002502 } else {
2503 if (tmp & DP_SYNC_HS_HIGH)
2504 flags |= DRM_MODE_FLAG_PHSYNC;
2505 else
2506 flags |= DRM_MODE_FLAG_NHSYNC;
2507
2508 if (tmp & DP_SYNC_VS_HIGH)
2509 flags |= DRM_MODE_FLAG_PVSYNC;
2510 else
2511 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002512 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002513
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002514 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002515
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002516 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
2517 !IS_CHERRYVIEW(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002518 pipe_config->limited_color_range = true;
2519
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002520 pipe_config->lane_count =
2521 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2522
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002523 intel_dp_get_m_n(crtc, pipe_config);
2524
Ville Syrjälä18442d02013-09-13 16:00:08 +03002525 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002526 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002527 pipe_config->port_clock = 162000;
2528 else
2529 pipe_config->port_clock = 270000;
2530 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002531
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002532 pipe_config->base.adjusted_mode.crtc_clock =
2533 intel_dotclock_calculate(pipe_config->port_clock,
2534 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002535
Jani Nikula6aa23e62016-03-24 17:50:20 +02002536 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2537 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002538 /*
2539 * This is a big fat ugly hack.
2540 *
2541 * Some machines in UEFI boot mode provide us a VBT that has 18
2542 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2543 * unknown we fail to light up. Yet the same BIOS boots up with
2544 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2545 * max, not what it tells us to use.
2546 *
2547 * Note: This will still be broken if the eDP panel is not lit
2548 * up by the BIOS, and thus we can't get the mode at module
2549 * load.
2550 */
2551 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002552 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2553 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002554 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002555}
2556
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002557static void intel_disable_dp(struct intel_encoder *encoder,
2558 struct intel_crtc_state *old_crtc_state,
2559 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002560{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002561 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002562 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002563
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002564 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002565 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002566
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002567 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002568 intel_psr_disable(intel_dp);
2569
Daniel Vetter6cb49832012-05-20 17:14:50 +02002570 /* Make sure the panel is off before trying to change the mode. But also
2571 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002572 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002573 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002574 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002575 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002576
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002577 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002578 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002579 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002580}
2581
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002582static void ilk_post_disable_dp(struct intel_encoder *encoder,
2583 struct intel_crtc_state *old_crtc_state,
2584 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002585{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002586 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002587 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002588
Ville Syrjälä49277c32014-03-31 18:21:26 +03002589 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002590
2591 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002592 if (port == PORT_A)
2593 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002594}
2595
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002596static void vlv_post_disable_dp(struct intel_encoder *encoder,
2597 struct intel_crtc_state *old_crtc_state,
2598 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002599{
2600 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2601
2602 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002603}
2604
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002605static void chv_post_disable_dp(struct intel_encoder *encoder,
2606 struct intel_crtc_state *old_crtc_state,
2607 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002608{
2609 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002610 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002611 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002612
2613 intel_dp_link_down(intel_dp);
2614
Ville Syrjäläa5805162015-05-26 20:42:30 +03002615 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002616
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002617 /* Assert data lane reset */
2618 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002619
Ville Syrjäläa5805162015-05-26 20:42:30 +03002620 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002621}
2622
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002623static void
2624_intel_dp_set_link_train(struct intel_dp *intel_dp,
2625 uint32_t *DP,
2626 uint8_t dp_train_pat)
2627{
2628 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2629 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002630 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002631 enum port port = intel_dig_port->port;
2632
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002633 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2634 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2635 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2636
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002637 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002638 uint32_t temp = I915_READ(DP_TP_CTL(port));
2639
2640 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2641 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2642 else
2643 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2644
2645 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2646 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2647 case DP_TRAINING_PATTERN_DISABLE:
2648 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2649
2650 break;
2651 case DP_TRAINING_PATTERN_1:
2652 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2653 break;
2654 case DP_TRAINING_PATTERN_2:
2655 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2656 break;
2657 case DP_TRAINING_PATTERN_3:
2658 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2659 break;
2660 }
2661 I915_WRITE(DP_TP_CTL(port), temp);
2662
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002663 } else if ((IS_GEN7(dev) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002664 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002665 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2666
2667 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2668 case DP_TRAINING_PATTERN_DISABLE:
2669 *DP |= DP_LINK_TRAIN_OFF_CPT;
2670 break;
2671 case DP_TRAINING_PATTERN_1:
2672 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2673 break;
2674 case DP_TRAINING_PATTERN_2:
2675 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2676 break;
2677 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002678 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002679 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2680 break;
2681 }
2682
2683 } else {
2684 if (IS_CHERRYVIEW(dev))
2685 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2686 else
2687 *DP &= ~DP_LINK_TRAIN_MASK;
2688
2689 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2690 case DP_TRAINING_PATTERN_DISABLE:
2691 *DP |= DP_LINK_TRAIN_OFF;
2692 break;
2693 case DP_TRAINING_PATTERN_1:
2694 *DP |= DP_LINK_TRAIN_PAT_1;
2695 break;
2696 case DP_TRAINING_PATTERN_2:
2697 *DP |= DP_LINK_TRAIN_PAT_2;
2698 break;
2699 case DP_TRAINING_PATTERN_3:
2700 if (IS_CHERRYVIEW(dev)) {
2701 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2702 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002703 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002704 *DP |= DP_LINK_TRAIN_PAT_2;
2705 }
2706 break;
2707 }
2708 }
2709}
2710
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002711static void intel_dp_enable_port(struct intel_dp *intel_dp,
2712 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002713{
2714 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002715 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002716
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002717 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002718
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002719 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002720
2721 /*
2722 * Magic for VLV/CHV. We _must_ first set up the register
2723 * without actually enabling the port, and then do another
2724 * write to enable the port. Otherwise link training will
2725 * fail when the power sequencer is freshly used for this port.
2726 */
2727 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002728 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002729 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002730
2731 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2732 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002733}
2734
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002735static void intel_enable_dp(struct intel_encoder *encoder,
2736 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002737{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002738 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2739 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002740 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002741 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002742 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002743 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002744
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002745 if (WARN_ON(dp_reg & DP_PORT_EN))
2746 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002747
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002748 pps_lock(intel_dp);
2749
Wayne Boyer666a4532015-12-09 12:29:35 -08002750 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002751 vlv_init_panel_power_sequencer(intel_dp);
2752
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002753 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002754
2755 edp_panel_vdd_on(intel_dp);
2756 edp_panel_on(intel_dp);
2757 edp_panel_vdd_off(intel_dp, true);
2758
2759 pps_unlock(intel_dp);
2760
Wayne Boyer666a4532015-12-09 12:29:35 -08002761 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002762 unsigned int lane_mask = 0x0;
2763
2764 if (IS_CHERRYVIEW(dev))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002765 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002766
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002767 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2768 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002769 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002770
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002771 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2772 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002773 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002774
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002775 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002776 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002777 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002778 intel_audio_codec_enable(encoder);
2779 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002780}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002781
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002782static void g4x_enable_dp(struct intel_encoder *encoder,
2783 struct intel_crtc_state *pipe_config,
2784 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002785{
Jani Nikula828f5c62013-09-05 16:44:45 +03002786 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2787
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002788 intel_enable_dp(encoder, pipe_config);
Daniel Vetter4be73782014-01-17 14:39:48 +01002789 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002790}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002791
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002792static void vlv_enable_dp(struct intel_encoder *encoder,
2793 struct intel_crtc_state *pipe_config,
2794 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002795{
Jani Nikula828f5c62013-09-05 16:44:45 +03002796 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2797
Daniel Vetter4be73782014-01-17 14:39:48 +01002798 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002799 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002800}
2801
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002802static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2803 struct intel_crtc_state *pipe_config,
2804 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002805{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002806 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002807 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002808
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002809 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002810
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002811 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002812 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002813 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002814}
2815
Ville Syrjälä83b84592014-10-16 21:29:51 +03002816static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2817{
2818 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002819 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002820 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002821 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002822
2823 edp_panel_vdd_off_sync(intel_dp);
2824
2825 /*
2826 * VLV seems to get confused when multiple power seqeuencers
2827 * have the same port selected (even if only one has power/vdd
2828 * enabled). The failure manifests as vlv_wait_port_ready() failing
2829 * CHV on the other hand doesn't seem to mind having the same port
2830 * selected in multiple power seqeuencers, but let's clear the
2831 * port select always when logically disconnecting a power sequencer
2832 * from a port.
2833 */
2834 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2835 pipe_name(pipe), port_name(intel_dig_port->port));
2836 I915_WRITE(pp_on_reg, 0);
2837 POSTING_READ(pp_on_reg);
2838
2839 intel_dp->pps_pipe = INVALID_PIPE;
2840}
2841
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002842static void vlv_steal_power_sequencer(struct drm_device *dev,
2843 enum pipe pipe)
2844{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002845 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002846 struct intel_encoder *encoder;
2847
2848 lockdep_assert_held(&dev_priv->pps_mutex);
2849
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002850 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2851 return;
2852
Jani Nikula19c80542015-12-16 12:48:16 +02002853 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002854 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002855 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002856
2857 if (encoder->type != INTEL_OUTPUT_EDP)
2858 continue;
2859
2860 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002861 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002862
2863 if (intel_dp->pps_pipe != pipe)
2864 continue;
2865
2866 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002867 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002868
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002869 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002870 "stealing pipe %c power sequencer from active eDP port %c\n",
2871 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002872
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002873 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002874 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002875 }
2876}
2877
2878static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2879{
2880 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2881 struct intel_encoder *encoder = &intel_dig_port->base;
2882 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002883 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002884 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002885
2886 lockdep_assert_held(&dev_priv->pps_mutex);
2887
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002888 if (!is_edp(intel_dp))
2889 return;
2890
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002891 if (intel_dp->pps_pipe == crtc->pipe)
2892 return;
2893
2894 /*
2895 * If another power sequencer was being used on this
2896 * port previously make sure to turn off vdd there while
2897 * we still have control of it.
2898 */
2899 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002900 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002901
2902 /*
2903 * We may be stealing the power
2904 * sequencer from another port.
2905 */
2906 vlv_steal_power_sequencer(dev, crtc->pipe);
2907
2908 /* now it's all ours */
2909 intel_dp->pps_pipe = crtc->pipe;
2910
2911 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2912 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2913
2914 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002915 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2916 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002917}
2918
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002919static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2920 struct intel_crtc_state *pipe_config,
2921 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002922{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002923 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002924
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002925 intel_enable_dp(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002926}
2927
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002928static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2929 struct intel_crtc_state *pipe_config,
2930 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002931{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002932 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002933
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002934 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002935}
2936
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002937static void chv_pre_enable_dp(struct intel_encoder *encoder,
2938 struct intel_crtc_state *pipe_config,
2939 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002940{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002941 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002942
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002943 intel_enable_dp(encoder, pipe_config);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002944
2945 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002946 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002947}
2948
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002949static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2950 struct intel_crtc_state *pipe_config,
2951 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002952{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002953 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002954
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002955 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002956}
2957
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002958static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2959 struct intel_crtc_state *pipe_config,
2960 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002961{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002962 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002963}
2964
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002965/*
2966 * Fetch AUX CH registers 0x202 - 0x207 which contain
2967 * link status information
2968 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002969bool
Keith Packard93f62da2011-11-01 19:45:03 -07002970intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002971{
Lyude9f085eb2016-04-13 10:58:33 -04002972 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2973 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002974}
2975
Paulo Zanoni11002442014-06-13 18:45:41 -03002976/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002977uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002978intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002979{
Paulo Zanoni30add222012-10-26 19:05:45 -02002980 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002981 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002982 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002983
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002984 if (IS_BROXTON(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05302985 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2986 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002987 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302988 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002989 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Wayne Boyer666a4532015-12-09 12:29:35 -08002990 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Sonika Jindalbd600182014-08-08 16:23:41 +05302991 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002992 else if (IS_GEN7(dev) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302993 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002994 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302995 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08002996 else
Sonika Jindalbd600182014-08-08 16:23:41 +05302997 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08002998}
2999
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003000uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003001intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3002{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003003 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003004 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003005
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003006 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003007 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3008 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3009 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3010 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3011 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3012 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3013 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303014 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3015 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003016 default:
3017 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3018 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003019 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003020 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303021 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3022 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3023 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3024 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3025 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3026 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3027 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003028 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303029 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003030 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003031 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003032 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303033 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3034 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3035 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3036 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3037 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3038 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3039 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003040 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303041 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003042 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003043 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003044 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303045 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3046 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3047 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3048 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3049 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003050 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303051 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003052 }
3053 } else {
3054 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 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3059 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3060 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3061 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003062 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303063 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003064 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003065 }
3066}
3067
Daniel Vetter5829975c2015-04-16 11:36:52 +02003068static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003069{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003070 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003071 unsigned long demph_reg_value, preemph_reg_value,
3072 uniqtranscale_reg_value;
3073 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003074
3075 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303076 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003077 preemph_reg_value = 0x0004000;
3078 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303079 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003080 demph_reg_value = 0x2B405555;
3081 uniqtranscale_reg_value = 0x552AB83A;
3082 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303083 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003084 demph_reg_value = 0x2B404040;
3085 uniqtranscale_reg_value = 0x5548B83A;
3086 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303087 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003088 demph_reg_value = 0x2B245555;
3089 uniqtranscale_reg_value = 0x5560B83A;
3090 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303091 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003092 demph_reg_value = 0x2B405555;
3093 uniqtranscale_reg_value = 0x5598DA3A;
3094 break;
3095 default:
3096 return 0;
3097 }
3098 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303099 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003100 preemph_reg_value = 0x0002000;
3101 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303102 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003103 demph_reg_value = 0x2B404040;
3104 uniqtranscale_reg_value = 0x5552B83A;
3105 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303106 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003107 demph_reg_value = 0x2B404848;
3108 uniqtranscale_reg_value = 0x5580B83A;
3109 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003111 demph_reg_value = 0x2B404040;
3112 uniqtranscale_reg_value = 0x55ADDA3A;
3113 break;
3114 default:
3115 return 0;
3116 }
3117 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303118 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003119 preemph_reg_value = 0x0000000;
3120 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003122 demph_reg_value = 0x2B305555;
3123 uniqtranscale_reg_value = 0x5570B83A;
3124 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003126 demph_reg_value = 0x2B2B4040;
3127 uniqtranscale_reg_value = 0x55ADDA3A;
3128 break;
3129 default:
3130 return 0;
3131 }
3132 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303133 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003134 preemph_reg_value = 0x0006000;
3135 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303136 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003137 demph_reg_value = 0x1B405555;
3138 uniqtranscale_reg_value = 0x55ADDA3A;
3139 break;
3140 default:
3141 return 0;
3142 }
3143 break;
3144 default:
3145 return 0;
3146 }
3147
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003148 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3149 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003150
3151 return 0;
3152}
3153
Daniel Vetter5829975c2015-04-16 11:36:52 +02003154static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003155{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003156 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3157 u32 deemph_reg_value, margin_reg_value;
3158 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003159 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003160
3161 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303162 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003163 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303164 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003165 deemph_reg_value = 128;
3166 margin_reg_value = 52;
3167 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303168 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003169 deemph_reg_value = 128;
3170 margin_reg_value = 77;
3171 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003173 deemph_reg_value = 128;
3174 margin_reg_value = 102;
3175 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003177 deemph_reg_value = 128;
3178 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003179 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003180 break;
3181 default:
3182 return 0;
3183 }
3184 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003186 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303187 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003188 deemph_reg_value = 85;
3189 margin_reg_value = 78;
3190 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003192 deemph_reg_value = 85;
3193 margin_reg_value = 116;
3194 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003196 deemph_reg_value = 85;
3197 margin_reg_value = 154;
3198 break;
3199 default:
3200 return 0;
3201 }
3202 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003204 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003206 deemph_reg_value = 64;
3207 margin_reg_value = 104;
3208 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303209 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003210 deemph_reg_value = 64;
3211 margin_reg_value = 154;
3212 break;
3213 default:
3214 return 0;
3215 }
3216 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303217 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003218 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003220 deemph_reg_value = 43;
3221 margin_reg_value = 154;
3222 break;
3223 default:
3224 return 0;
3225 }
3226 break;
3227 default:
3228 return 0;
3229 }
3230
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003231 chv_set_phy_signal_level(encoder, deemph_reg_value,
3232 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003233
3234 return 0;
3235}
3236
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003237static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003238gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003239{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003240 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003241
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003242 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303243 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003244 default:
3245 signal_levels |= DP_VOLTAGE_0_4;
3246 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303247 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003248 signal_levels |= DP_VOLTAGE_0_6;
3249 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003251 signal_levels |= DP_VOLTAGE_0_8;
3252 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003254 signal_levels |= DP_VOLTAGE_1_2;
3255 break;
3256 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003257 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003259 default:
3260 signal_levels |= DP_PRE_EMPHASIS_0;
3261 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003263 signal_levels |= DP_PRE_EMPHASIS_3_5;
3264 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303265 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003266 signal_levels |= DP_PRE_EMPHASIS_6;
3267 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003269 signal_levels |= DP_PRE_EMPHASIS_9_5;
3270 break;
3271 }
3272 return signal_levels;
3273}
3274
Zhenyu Wange3421a12010-04-08 09:43:27 +08003275/* Gen6's DP voltage swing and pre-emphasis control */
3276static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003277gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003278{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003279 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3280 DP_TRAIN_PRE_EMPHASIS_MASK);
3281 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303282 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003284 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003286 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003289 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003292 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3294 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003295 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003296 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003297 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3298 "0x%x\n", signal_levels);
3299 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003300 }
3301}
3302
Keith Packard1a2eb462011-11-16 16:26:07 -08003303/* Gen7's DP voltage swing and pre-emphasis control */
3304static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003305gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003306{
3307 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3308 DP_TRAIN_PRE_EMPHASIS_MASK);
3309 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003311 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003313 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303314 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003315 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3316
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003318 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003320 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3321
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003323 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003325 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3326
3327 default:
3328 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3329 "0x%x\n", signal_levels);
3330 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3331 }
3332}
3333
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003334void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003335intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003336{
3337 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003338 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003339 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003340 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003341 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003342 uint8_t train_set = intel_dp->train_set[0];
3343
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003344 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003345 signal_levels = ddi_signal_levels(intel_dp);
3346
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003347 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003348 signal_levels = 0;
3349 else
3350 mask = DDI_BUF_EMP_MASK;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003351 } else if (IS_CHERRYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003352 signal_levels = chv_signal_levels(intel_dp);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003353 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003354 signal_levels = vlv_signal_levels(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003355 } else if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003356 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003357 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003358 } else if (IS_GEN6(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003359 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003360 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3361 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003362 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003363 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3364 }
3365
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303366 if (mask)
3367 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3368
3369 DRM_DEBUG_KMS("Using vswing level %d\n",
3370 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3371 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3372 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3373 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003374
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003375 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003376
3377 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3378 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003379}
3380
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003381void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003382intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3383 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003384{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003385 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003386 struct drm_i915_private *dev_priv =
3387 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003388
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003389 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003390
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003391 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003392 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003393}
3394
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003395void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003396{
3397 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3398 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003399 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003400 enum port port = intel_dig_port->port;
3401 uint32_t val;
3402
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003403 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003404 return;
3405
3406 val = I915_READ(DP_TP_CTL(port));
3407 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3408 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3409 I915_WRITE(DP_TP_CTL(port), val);
3410
3411 /*
3412 * On PORT_A we can have only eDP in SST mode. There the only reason
3413 * we need to set idle transmission mode is to work around a HW issue
3414 * where we enable the pipe while not in idle link-training mode.
3415 * In this case there is requirement to wait for a minimum number of
3416 * idle patterns to be sent.
3417 */
3418 if (port == PORT_A)
3419 return;
3420
Chris Wilsona7670172016-06-30 15:33:10 +01003421 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3422 DP_TP_STATUS_IDLE_DONE,
3423 DP_TP_STATUS_IDLE_DONE,
3424 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003425 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3426}
3427
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003428static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003429intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003430{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003431 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003432 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003433 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003434 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003435 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003436 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003437
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003438 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003439 return;
3440
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003441 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003442 return;
3443
Zhao Yakui28c97732009-10-09 11:39:41 +08003444 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003445
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03003446 if ((IS_GEN7(dev) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003447 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003448 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003449 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003450 } else {
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003451 if (IS_CHERRYVIEW(dev))
3452 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3453 else
3454 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003455 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003456 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003457 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003458 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003459
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003460 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3461 I915_WRITE(intel_dp->output_reg, DP);
3462 POSTING_READ(intel_dp->output_reg);
3463
3464 /*
3465 * HW workaround for IBX, we need to move the port
3466 * to transcoder A after disabling it to allow the
3467 * matching HDMI port to be enabled on transcoder A.
3468 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003469 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003470 /*
3471 * We get CPU/PCH FIFO underruns on the other pipe when
3472 * doing the workaround. Sweep them under the rug.
3473 */
3474 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3475 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3476
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003477 /* always enable with pattern 1 (as per spec) */
3478 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3479 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3480 I915_WRITE(intel_dp->output_reg, DP);
3481 POSTING_READ(intel_dp->output_reg);
3482
3483 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003484 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003485 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003486
Chris Wilson91c8a322016-07-05 10:40:23 +01003487 intel_wait_for_vblank_if_active(&dev_priv->drm, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003488 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3489 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003490 }
3491
Keith Packardf01eca22011-09-28 16:48:10 -07003492 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003493
3494 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003495}
3496
Keith Packard26d61aa2011-07-25 20:01:09 -07003497static bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003498intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003499{
Lyude9f085eb2016-04-13 10:58:33 -04003500 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3501 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003502 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003503
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003504 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003505
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003506 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3507}
3508
3509static bool
3510intel_edp_init_dpcd(struct intel_dp *intel_dp)
3511{
3512 struct drm_i915_private *dev_priv =
3513 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3514
3515 /* this function is meant to be called only once */
3516 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3517
3518 if (!intel_dp_read_dpcd(intel_dp))
3519 return false;
3520
3521 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3522 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3523 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3524
3525 /* Check if the panel supports PSR */
3526 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3527 intel_dp->psr_dpcd,
3528 sizeof(intel_dp->psr_dpcd));
3529 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3530 dev_priv->psr.sink_support = true;
3531 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3532 }
3533
3534 if (INTEL_GEN(dev_priv) >= 9 &&
3535 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3536 uint8_t frame_sync_cap;
3537
3538 dev_priv->psr.sink_support = true;
3539 drm_dp_dpcd_read(&intel_dp->aux,
3540 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3541 &frame_sync_cap, 1);
3542 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3543 /* PSR2 needs frame sync as well */
3544 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3545 DRM_DEBUG_KMS("PSR2 %s on sink",
3546 dev_priv->psr.psr2_support ? "supported" : "not supported");
3547 }
3548
3549 /* Read the eDP Display control capabilities registers */
3550 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3551 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003552 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3553 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003554 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3555 intel_dp->edp_dpcd);
3556
3557 /* Intermediate frequency support */
3558 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3559 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3560 int i;
3561
3562 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3563 sink_rates, sizeof(sink_rates));
3564
3565 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3566 int val = le16_to_cpu(sink_rates[i]);
3567
3568 if (val == 0)
3569 break;
3570
3571 /* Value read is in kHz while drm clock is saved in deca-kHz */
3572 intel_dp->sink_rates[i] = (val * 200) / 10;
3573 }
3574 intel_dp->num_sink_rates = i;
3575 }
3576
3577 return true;
3578}
3579
3580
3581static bool
3582intel_dp_get_dpcd(struct intel_dp *intel_dp)
3583{
3584 if (!intel_dp_read_dpcd(intel_dp))
3585 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003586
Lyude9f085eb2016-04-13 10:58:33 -04003587 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3588 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303589 return false;
3590
3591 /*
3592 * Sink count can change between short pulse hpd hence
3593 * a member variable in intel_dp will track any changes
3594 * between short pulse interrupts.
3595 */
3596 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3597
3598 /*
3599 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3600 * a dongle is present but no display. Unless we require to know
3601 * if a dongle is present or not, we don't need to update
3602 * downstream port information. So, an early return here saves
3603 * time from performing other operations which are not required.
3604 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303605 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303606 return false;
3607
Adam Jacksonedb39242012-09-18 10:58:49 -04003608 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3609 DP_DWN_STRM_PORT_PRESENT))
3610 return true; /* native DP sink */
3611
3612 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3613 return true; /* no per-port downstream info */
3614
Lyude9f085eb2016-04-13 10:58:33 -04003615 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3616 intel_dp->downstream_ports,
3617 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003618 return false; /* downstream port status fetch failed */
3619
3620 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003621}
3622
Adam Jackson0d198322012-05-14 16:05:47 -04003623static void
3624intel_dp_probe_oui(struct intel_dp *intel_dp)
3625{
3626 u8 buf[3];
3627
3628 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3629 return;
3630
Lyude9f085eb2016-04-13 10:58:33 -04003631 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003632 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3633 buf[0], buf[1], buf[2]);
3634
Lyude9f085eb2016-04-13 10:58:33 -04003635 if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003636 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3637 buf[0], buf[1], buf[2]);
3638}
3639
Dave Airlie0e32b392014-05-02 14:02:48 +10003640static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003641intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003642{
3643 u8 buf[1];
3644
Nathan Schulte7cc96132016-03-15 10:14:05 -05003645 if (!i915.enable_dp_mst)
3646 return false;
3647
Dave Airlie0e32b392014-05-02 14:02:48 +10003648 if (!intel_dp->can_mst)
3649 return false;
3650
3651 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3652 return false;
3653
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003654 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3655 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003656
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003657 return buf[0] & DP_MST_CAP;
3658}
3659
3660static void
3661intel_dp_configure_mst(struct intel_dp *intel_dp)
3662{
3663 if (!i915.enable_dp_mst)
3664 return;
3665
3666 if (!intel_dp->can_mst)
3667 return;
3668
3669 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3670
3671 if (intel_dp->is_mst)
3672 DRM_DEBUG_KMS("Sink is MST capable\n");
3673 else
3674 DRM_DEBUG_KMS("Sink is not MST capable\n");
3675
3676 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3677 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003678}
3679
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003680static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003681{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003682 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003683 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003684 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003685 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003686 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003687 int count = 0;
3688 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003689
3690 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003691 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003692 ret = -EIO;
3693 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003694 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003695
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003696 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003697 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003698 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003699 ret = -EIO;
3700 goto out;
3701 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003702
Rodrigo Vivic6297842015-11-05 10:50:20 -08003703 do {
3704 intel_wait_for_vblank(dev, intel_crtc->pipe);
3705
3706 if (drm_dp_dpcd_readb(&intel_dp->aux,
3707 DP_TEST_SINK_MISC, &buf) < 0) {
3708 ret = -EIO;
3709 goto out;
3710 }
3711 count = buf & DP_TEST_COUNT_MASK;
3712 } while (--attempts && count);
3713
3714 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003715 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003716 ret = -ETIMEDOUT;
3717 }
3718
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003719 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003720 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003721 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003722}
3723
3724static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3725{
3726 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003727 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003728 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3729 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003730 int ret;
3731
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003732 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3733 return -EIO;
3734
3735 if (!(buf & DP_TEST_CRC_SUPPORTED))
3736 return -ENOTTY;
3737
3738 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3739 return -EIO;
3740
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003741 if (buf & DP_TEST_SINK_START) {
3742 ret = intel_dp_sink_crc_stop(intel_dp);
3743 if (ret)
3744 return ret;
3745 }
3746
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003747 hsw_disable_ips(intel_crtc);
3748
3749 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3750 buf | DP_TEST_SINK_START) < 0) {
3751 hsw_enable_ips(intel_crtc);
3752 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003753 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003754
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003755 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003756 return 0;
3757}
3758
3759int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3760{
3761 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3762 struct drm_device *dev = dig_port->base.base.dev;
3763 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3764 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003765 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003766 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003767
3768 ret = intel_dp_sink_crc_start(intel_dp);
3769 if (ret)
3770 return ret;
3771
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003772 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003773 intel_wait_for_vblank(dev, intel_crtc->pipe);
3774
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003775 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003776 DP_TEST_SINK_MISC, &buf) < 0) {
3777 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003778 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003779 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003780 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003781
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003782 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003783
3784 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003785 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3786 ret = -ETIMEDOUT;
3787 goto stop;
3788 }
3789
3790 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3791 ret = -EIO;
3792 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003793 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003794
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003795stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003796 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003797 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003798}
3799
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003800static bool
3801intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3802{
Lyude9f085eb2016-04-13 10:58:33 -04003803 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003804 DP_DEVICE_SERVICE_IRQ_VECTOR,
3805 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003806}
3807
Dave Airlie0e32b392014-05-02 14:02:48 +10003808static bool
3809intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3810{
3811 int ret;
3812
Lyude9f085eb2016-04-13 10:58:33 -04003813 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003814 DP_SINK_COUNT_ESI,
3815 sink_irq_vector, 14);
3816 if (ret != 14)
3817 return false;
3818
3819 return true;
3820}
3821
Todd Previtec5d5ab72015-04-15 08:38:38 -07003822static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003823{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003824 uint8_t test_result = DP_TEST_ACK;
3825 return test_result;
3826}
3827
3828static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3829{
3830 uint8_t test_result = DP_TEST_NAK;
3831 return test_result;
3832}
3833
3834static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3835{
3836 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003837 struct intel_connector *intel_connector = intel_dp->attached_connector;
3838 struct drm_connector *connector = &intel_connector->base;
3839
3840 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003841 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003842 intel_dp->aux.i2c_defer_count > 6) {
3843 /* Check EDID read for NACKs, DEFERs and corruption
3844 * (DP CTS 1.2 Core r1.1)
3845 * 4.2.2.4 : Failed EDID read, I2C_NAK
3846 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3847 * 4.2.2.6 : EDID corruption detected
3848 * Use failsafe mode for all cases
3849 */
3850 if (intel_dp->aux.i2c_nack_count > 0 ||
3851 intel_dp->aux.i2c_defer_count > 0)
3852 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3853 intel_dp->aux.i2c_nack_count,
3854 intel_dp->aux.i2c_defer_count);
3855 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3856 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303857 struct edid *block = intel_connector->detect_edid;
3858
3859 /* We have to write the checksum
3860 * of the last block read
3861 */
3862 block += intel_connector->detect_edid->extensions;
3863
Todd Previte559be302015-05-04 07:48:20 -07003864 if (!drm_dp_dpcd_write(&intel_dp->aux,
3865 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303866 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003867 1))
Todd Previte559be302015-05-04 07:48:20 -07003868 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3869
3870 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3871 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3872 }
3873
3874 /* Set test active flag here so userspace doesn't interrupt things */
3875 intel_dp->compliance_test_active = 1;
3876
Todd Previtec5d5ab72015-04-15 08:38:38 -07003877 return test_result;
3878}
3879
3880static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3881{
3882 uint8_t test_result = DP_TEST_NAK;
3883 return test_result;
3884}
3885
3886static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3887{
3888 uint8_t response = DP_TEST_NAK;
3889 uint8_t rxdata = 0;
3890 int status = 0;
3891
Todd Previtec5d5ab72015-04-15 08:38:38 -07003892 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3893 if (status <= 0) {
3894 DRM_DEBUG_KMS("Could not read test request from sink\n");
3895 goto update_status;
3896 }
3897
3898 switch (rxdata) {
3899 case DP_TEST_LINK_TRAINING:
3900 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3901 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3902 response = intel_dp_autotest_link_training(intel_dp);
3903 break;
3904 case DP_TEST_LINK_VIDEO_PATTERN:
3905 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3906 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3907 response = intel_dp_autotest_video_pattern(intel_dp);
3908 break;
3909 case DP_TEST_LINK_EDID_READ:
3910 DRM_DEBUG_KMS("EDID test requested\n");
3911 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3912 response = intel_dp_autotest_edid(intel_dp);
3913 break;
3914 case DP_TEST_LINK_PHY_TEST_PATTERN:
3915 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3916 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3917 response = intel_dp_autotest_phy_pattern(intel_dp);
3918 break;
3919 default:
3920 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3921 break;
3922 }
3923
3924update_status:
3925 status = drm_dp_dpcd_write(&intel_dp->aux,
3926 DP_TEST_RESPONSE,
3927 &response, 1);
3928 if (status <= 0)
3929 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003930}
3931
Dave Airlie0e32b392014-05-02 14:02:48 +10003932static int
3933intel_dp_check_mst_status(struct intel_dp *intel_dp)
3934{
3935 bool bret;
3936
3937 if (intel_dp->is_mst) {
3938 u8 esi[16] = { 0 };
3939 int ret = 0;
3940 int retry;
3941 bool handled;
3942 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3943go_again:
3944 if (bret == true) {
3945
3946 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003947 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003948 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003949 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3950 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003951 intel_dp_stop_link_train(intel_dp);
3952 }
3953
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003954 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003955 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3956
3957 if (handled) {
3958 for (retry = 0; retry < 3; retry++) {
3959 int wret;
3960 wret = drm_dp_dpcd_write(&intel_dp->aux,
3961 DP_SINK_COUNT_ESI+1,
3962 &esi[1], 3);
3963 if (wret == 3) {
3964 break;
3965 }
3966 }
3967
3968 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3969 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003970 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003971 goto go_again;
3972 }
3973 } else
3974 ret = 0;
3975
3976 return ret;
3977 } else {
3978 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3979 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3980 intel_dp->is_mst = false;
3981 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3982 /* send a hotplug event */
3983 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3984 }
3985 }
3986 return -EINVAL;
3987}
3988
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303989static void
3990intel_dp_check_link_status(struct intel_dp *intel_dp)
3991{
3992 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
3993 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3994 u8 link_status[DP_LINK_STATUS_SIZE];
3995
3996 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
3997
3998 if (!intel_dp_get_link_status(intel_dp, link_status)) {
3999 DRM_ERROR("Failed to get link status\n");
4000 return;
4001 }
4002
4003 if (!intel_encoder->base.crtc)
4004 return;
4005
4006 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4007 return;
4008
4009 /* if link training is requested we should perform it always */
4010 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
4011 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4012 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4013 intel_encoder->base.name);
4014 intel_dp_start_link_train(intel_dp);
4015 intel_dp_stop_link_train(intel_dp);
4016 }
4017}
4018
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004019/*
4020 * According to DP spec
4021 * 5.1.2:
4022 * 1. Read DPCD
4023 * 2. Configure link according to Receiver Capabilities
4024 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4025 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304026 *
4027 * intel_dp_short_pulse - handles short pulse interrupts
4028 * when full detection is not required.
4029 * Returns %true if short pulse is handled and full detection
4030 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004031 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304032static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304033intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004034{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004035 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004036 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304037 u8 old_sink_count = intel_dp->sink_count;
4038 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004039
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304040 /*
4041 * Clearing compliance test variables to allow capturing
4042 * of values for next automated test request.
4043 */
4044 intel_dp->compliance_test_active = 0;
4045 intel_dp->compliance_test_type = 0;
4046 intel_dp->compliance_test_data = 0;
4047
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304048 /*
4049 * Now read the DPCD to see if it's actually running
4050 * If the current value of sink count doesn't match with
4051 * the value that was stored earlier or dpcd read failed
4052 * we need to do full detection
4053 */
4054 ret = intel_dp_get_dpcd(intel_dp);
4055
4056 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4057 /* No need to proceed if we are going to do full detect */
4058 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004059 }
4060
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004061 /* Try to read the source of the interrupt */
4062 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004063 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4064 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004065 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004066 drm_dp_dpcd_writeb(&intel_dp->aux,
4067 DP_DEVICE_SERVICE_IRQ_VECTOR,
4068 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004069
4070 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004071 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004072 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4073 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4074 }
4075
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304076 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4077 intel_dp_check_link_status(intel_dp);
4078 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304079
4080 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004081}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004082
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004083/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004084static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004085intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004086{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004087 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004088 uint8_t type;
4089
4090 if (!intel_dp_get_dpcd(intel_dp))
4091 return connector_status_disconnected;
4092
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304093 if (is_edp(intel_dp))
4094 return connector_status_connected;
4095
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004096 /* if there's no downstream port, we're done */
4097 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07004098 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004099
4100 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004101 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4102 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004103
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304104 return intel_dp->sink_count ?
4105 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004106 }
4107
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004108 if (intel_dp_can_mst(intel_dp))
4109 return connector_status_connected;
4110
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004111 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004112 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004113 return connector_status_connected;
4114
4115 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004116 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4117 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4118 if (type == DP_DS_PORT_TYPE_VGA ||
4119 type == DP_DS_PORT_TYPE_NON_EDID)
4120 return connector_status_unknown;
4121 } else {
4122 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4123 DP_DWN_STRM_PORT_TYPE_MASK;
4124 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4125 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4126 return connector_status_unknown;
4127 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004128
4129 /* Anything else is out of spec, warn and ignore */
4130 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004131 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004132}
4133
4134static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004135edp_detect(struct intel_dp *intel_dp)
4136{
4137 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4138 enum drm_connector_status status;
4139
4140 status = intel_panel_detect(dev);
4141 if (status == connector_status_unknown)
4142 status = connector_status_connected;
4143
4144 return status;
4145}
4146
Jani Nikulab93433c2015-08-20 10:47:36 +03004147static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4148 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004149{
Jani Nikulab93433c2015-08-20 10:47:36 +03004150 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004151
Jani Nikula0df53b72015-08-20 10:47:40 +03004152 switch (port->port) {
4153 case PORT_A:
4154 return true;
4155 case PORT_B:
4156 bit = SDE_PORTB_HOTPLUG;
4157 break;
4158 case PORT_C:
4159 bit = SDE_PORTC_HOTPLUG;
4160 break;
4161 case PORT_D:
4162 bit = SDE_PORTD_HOTPLUG;
4163 break;
4164 default:
4165 MISSING_CASE(port->port);
4166 return false;
4167 }
4168
4169 return I915_READ(SDEISR) & bit;
4170}
4171
4172static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4173 struct intel_digital_port *port)
4174{
4175 u32 bit;
4176
4177 switch (port->port) {
4178 case PORT_A:
4179 return true;
4180 case PORT_B:
4181 bit = SDE_PORTB_HOTPLUG_CPT;
4182 break;
4183 case PORT_C:
4184 bit = SDE_PORTC_HOTPLUG_CPT;
4185 break;
4186 case PORT_D:
4187 bit = SDE_PORTD_HOTPLUG_CPT;
4188 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004189 case PORT_E:
4190 bit = SDE_PORTE_HOTPLUG_SPT;
4191 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004192 default:
4193 MISSING_CASE(port->port);
4194 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004195 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004196
Jani Nikulab93433c2015-08-20 10:47:36 +03004197 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004198}
4199
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004200static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004201 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004202{
Jani Nikula9642c812015-08-20 10:47:41 +03004203 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004204
Jani Nikula9642c812015-08-20 10:47:41 +03004205 switch (port->port) {
4206 case PORT_B:
4207 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4208 break;
4209 case PORT_C:
4210 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4211 break;
4212 case PORT_D:
4213 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4214 break;
4215 default:
4216 MISSING_CASE(port->port);
4217 return false;
4218 }
4219
4220 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4221}
4222
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004223static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4224 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004225{
4226 u32 bit;
4227
4228 switch (port->port) {
4229 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004230 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004231 break;
4232 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004233 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004234 break;
4235 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004236 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004237 break;
4238 default:
4239 MISSING_CASE(port->port);
4240 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004241 }
4242
Jani Nikula1d245982015-08-20 10:47:37 +03004243 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004244}
4245
Jani Nikulae464bfd2015-08-20 10:47:42 +03004246static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304247 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004248{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304249 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4250 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004251 u32 bit;
4252
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304253 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4254 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004255 case PORT_A:
4256 bit = BXT_DE_PORT_HP_DDIA;
4257 break;
4258 case PORT_B:
4259 bit = BXT_DE_PORT_HP_DDIB;
4260 break;
4261 case PORT_C:
4262 bit = BXT_DE_PORT_HP_DDIC;
4263 break;
4264 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304265 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004266 return false;
4267 }
4268
4269 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4270}
4271
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004272/*
4273 * intel_digital_port_connected - is the specified port connected?
4274 * @dev_priv: i915 private structure
4275 * @port: the port to test
4276 *
4277 * Return %true if @port is connected, %false otherwise.
4278 */
David Weinehall23f889b2016-08-17 15:47:48 +03004279static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004280 struct intel_digital_port *port)
4281{
Jani Nikula0df53b72015-08-20 10:47:40 +03004282 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004283 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004284 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004285 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004286 else if (IS_BROXTON(dev_priv))
4287 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004288 else if (IS_GM45(dev_priv))
4289 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004290 else
4291 return g4x_digital_port_connected(dev_priv, port);
4292}
4293
Keith Packard8c241fe2011-09-28 16:38:44 -07004294static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004295intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004296{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004297 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004298
Jani Nikula9cd300e2012-10-19 14:51:52 +03004299 /* use cached edid if we have one */
4300 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004301 /* invalid edid */
4302 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004303 return NULL;
4304
Jani Nikula55e9ede2013-10-01 10:38:54 +03004305 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004306 } else
4307 return drm_get_edid(&intel_connector->base,
4308 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004309}
4310
Chris Wilsonbeb60602014-09-02 20:04:00 +01004311static void
4312intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004313{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004314 struct intel_connector *intel_connector = intel_dp->attached_connector;
4315 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004316
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304317 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004318 edid = intel_dp_get_edid(intel_dp);
4319 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004320
Chris Wilsonbeb60602014-09-02 20:04:00 +01004321 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4322 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4323 else
4324 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4325}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004326
Chris Wilsonbeb60602014-09-02 20:04:00 +01004327static void
4328intel_dp_unset_edid(struct intel_dp *intel_dp)
4329{
4330 struct intel_connector *intel_connector = intel_dp->attached_connector;
4331
4332 kfree(intel_connector->detect_edid);
4333 intel_connector->detect_edid = NULL;
4334
4335 intel_dp->has_audio = false;
4336}
4337
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004338static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304339intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004340{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304341 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004342 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004343 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4344 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004345 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004346 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004347 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004348 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004349
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004350 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4351 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004352
Chris Wilsond410b562014-09-02 20:03:59 +01004353 /* Can't disconnect eDP, but you can close the lid... */
4354 if (is_edp(intel_dp))
4355 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004356 else if (intel_digital_port_connected(to_i915(dev),
4357 dp_to_dig_port(intel_dp)))
4358 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004359 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004360 status = connector_status_disconnected;
4361
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004362 if (status == connector_status_disconnected) {
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304363 intel_dp->compliance_test_active = 0;
4364 intel_dp->compliance_test_type = 0;
4365 intel_dp->compliance_test_data = 0;
4366
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004367 if (intel_dp->is_mst) {
4368 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4369 intel_dp->is_mst,
4370 intel_dp->mst_mgr.mst_state);
4371 intel_dp->is_mst = false;
4372 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4373 intel_dp->is_mst);
4374 }
4375
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004376 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304377 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004378
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304379 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004380 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304381
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004382 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4383 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4384 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4385
4386 intel_dp_print_rates(intel_dp);
4387
Adam Jackson0d198322012-05-14 16:05:47 -04004388 intel_dp_probe_oui(intel_dp);
4389
Mika Kahola0e390a32016-09-09 14:10:53 +03004390 intel_dp_print_hw_revision(intel_dp);
Mika Kahola1a2724f2016-09-09 14:10:54 +03004391 intel_dp_print_sw_revision(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004392
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004393 intel_dp_configure_mst(intel_dp);
4394
4395 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304396 /*
4397 * If we are in MST mode then this connector
4398 * won't appear connected or have anything
4399 * with EDID on it
4400 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004401 status = connector_status_disconnected;
4402 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304403 } else if (connector->status == connector_status_connected) {
4404 /*
4405 * If display was connected already and is still connected
4406 * check links status, there has been known issues of
4407 * link loss triggerring long pulse!!!!
4408 */
4409 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4410 intel_dp_check_link_status(intel_dp);
4411 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4412 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004413 }
4414
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304415 /*
4416 * Clearing NACK and defer counts to get their exact values
4417 * while reading EDID which are required by Compliance tests
4418 * 4.2.2.4 and 4.2.2.5
4419 */
4420 intel_dp->aux.i2c_nack_count = 0;
4421 intel_dp->aux.i2c_defer_count = 0;
4422
Chris Wilsonbeb60602014-09-02 20:04:00 +01004423 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004424 if (is_edp(intel_dp) || intel_connector->detect_edid)
4425 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304426 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004427
Todd Previte09b1eb12015-04-20 15:27:34 -07004428 /* Try to read the source of the interrupt */
4429 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004430 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4431 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004432 /* Clear interrupt source */
4433 drm_dp_dpcd_writeb(&intel_dp->aux,
4434 DP_DEVICE_SERVICE_IRQ_VECTOR,
4435 sink_irq_vector);
4436
4437 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4438 intel_dp_handle_test_request(intel_dp);
4439 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4440 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4441 }
4442
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004443out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004444 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304445 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304446
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004447 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004448 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304449}
4450
4451static enum drm_connector_status
4452intel_dp_detect(struct drm_connector *connector, bool force)
4453{
4454 struct intel_dp *intel_dp = intel_attached_dp(connector);
4455 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4456 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004457 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304458
4459 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4460 connector->base.id, connector->name);
4461
4462 if (intel_dp->is_mst) {
4463 /* MST devices are disconnected from a monitor POV */
4464 intel_dp_unset_edid(intel_dp);
4465 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004466 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304467 return connector_status_disconnected;
4468 }
4469
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304470 /* If full detect is not performed yet, do a full detect */
4471 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004472 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304473
4474 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304475
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004476 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004477}
4478
Chris Wilsonbeb60602014-09-02 20:04:00 +01004479static void
4480intel_dp_force(struct drm_connector *connector)
4481{
4482 struct intel_dp *intel_dp = intel_attached_dp(connector);
4483 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004484 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004485 enum intel_display_power_domain power_domain;
4486
4487 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4488 connector->base.id, connector->name);
4489 intel_dp_unset_edid(intel_dp);
4490
4491 if (connector->status != connector_status_connected)
4492 return;
4493
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004494 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4495 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004496
4497 intel_dp_set_edid(intel_dp);
4498
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004499 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004500
4501 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004502 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004503}
4504
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004505static int intel_dp_get_modes(struct drm_connector *connector)
4506{
Jani Nikuladd06f902012-10-19 14:51:50 +03004507 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004508 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004509
Chris Wilsonbeb60602014-09-02 20:04:00 +01004510 edid = intel_connector->detect_edid;
4511 if (edid) {
4512 int ret = intel_connector_update_modes(connector, edid);
4513 if (ret)
4514 return ret;
4515 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004516
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004517 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004518 if (is_edp(intel_attached_dp(connector)) &&
4519 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004520 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004521
4522 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004523 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004524 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004525 drm_mode_probed_add(connector, mode);
4526 return 1;
4527 }
4528 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004529
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004530 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004531}
4532
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004533static bool
4534intel_dp_detect_audio(struct drm_connector *connector)
4535{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004536 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004537 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004538
Chris Wilsonbeb60602014-09-02 20:04:00 +01004539 edid = to_intel_connector(connector)->detect_edid;
4540 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004541 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004542
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004543 return has_audio;
4544}
4545
Chris Wilsonf6849602010-09-19 09:29:33 +01004546static int
4547intel_dp_set_property(struct drm_connector *connector,
4548 struct drm_property *property,
4549 uint64_t val)
4550{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004551 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004552 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004553 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4554 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004555 int ret;
4556
Rob Clark662595d2012-10-11 20:36:04 -05004557 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004558 if (ret)
4559 return ret;
4560
Chris Wilson3f43c482011-05-12 22:17:24 +01004561 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004562 int i = val;
4563 bool has_audio;
4564
4565 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004566 return 0;
4567
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004568 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004569
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004570 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004571 has_audio = intel_dp_detect_audio(connector);
4572 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004573 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004574
4575 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004576 return 0;
4577
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004578 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004579 goto done;
4580 }
4581
Chris Wilsone953fd72011-02-21 22:23:52 +00004582 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004583 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004584 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004585
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004586 switch (val) {
4587 case INTEL_BROADCAST_RGB_AUTO:
4588 intel_dp->color_range_auto = true;
4589 break;
4590 case INTEL_BROADCAST_RGB_FULL:
4591 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004592 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004593 break;
4594 case INTEL_BROADCAST_RGB_LIMITED:
4595 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004596 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004597 break;
4598 default:
4599 return -EINVAL;
4600 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004601
4602 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004603 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004604 return 0;
4605
Chris Wilsone953fd72011-02-21 22:23:52 +00004606 goto done;
4607 }
4608
Yuly Novikov53b41832012-10-26 12:04:00 +03004609 if (is_edp(intel_dp) &&
4610 property == connector->dev->mode_config.scaling_mode_property) {
4611 if (val == DRM_MODE_SCALE_NONE) {
4612 DRM_DEBUG_KMS("no scaling not supported\n");
4613 return -EINVAL;
4614 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004615 if (HAS_GMCH_DISPLAY(dev_priv) &&
4616 val == DRM_MODE_SCALE_CENTER) {
4617 DRM_DEBUG_KMS("centering not supported\n");
4618 return -EINVAL;
4619 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004620
4621 if (intel_connector->panel.fitting_mode == val) {
4622 /* the eDP scaling property is not changed */
4623 return 0;
4624 }
4625 intel_connector->panel.fitting_mode = val;
4626
4627 goto done;
4628 }
4629
Chris Wilsonf6849602010-09-19 09:29:33 +01004630 return -EINVAL;
4631
4632done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004633 if (intel_encoder->base.crtc)
4634 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004635
4636 return 0;
4637}
4638
Chris Wilson7a418e32016-06-24 14:00:14 +01004639static int
4640intel_dp_connector_register(struct drm_connector *connector)
4641{
4642 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004643 int ret;
4644
4645 ret = intel_connector_register(connector);
4646 if (ret)
4647 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004648
4649 i915_debugfs_connector_add(connector);
4650
4651 DRM_DEBUG_KMS("registering %s bus for %s\n",
4652 intel_dp->aux.name, connector->kdev->kobj.name);
4653
4654 intel_dp->aux.dev = connector->kdev;
4655 return drm_dp_aux_register(&intel_dp->aux);
4656}
4657
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004658static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004659intel_dp_connector_unregister(struct drm_connector *connector)
4660{
4661 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4662 intel_connector_unregister(connector);
4663}
4664
4665static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004666intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004667{
Jani Nikula1d508702012-10-19 14:51:49 +03004668 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004669
Chris Wilson10e972d2014-09-04 21:43:45 +01004670 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004671
Jani Nikula9cd300e2012-10-19 14:51:52 +03004672 if (!IS_ERR_OR_NULL(intel_connector->edid))
4673 kfree(intel_connector->edid);
4674
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004675 /* Can't call is_edp() since the encoder may have been destroyed
4676 * already. */
4677 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004678 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004679
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004680 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004681 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004682}
4683
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004684void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004685{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004686 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4687 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004688
Dave Airlie0e32b392014-05-02 14:02:48 +10004689 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004690 if (is_edp(intel_dp)) {
4691 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004692 /*
4693 * vdd might still be enabled do to the delayed vdd off.
4694 * Make sure vdd is actually turned off here.
4695 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004696 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004697 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004698 pps_unlock(intel_dp);
4699
Clint Taylor01527b32014-07-07 13:01:46 -07004700 if (intel_dp->edp_notifier.notifier_call) {
4701 unregister_reboot_notifier(&intel_dp->edp_notifier);
4702 intel_dp->edp_notifier.notifier_call = NULL;
4703 }
Keith Packardbd943152011-09-18 23:09:52 -07004704 }
Chris Wilson99681882016-06-20 09:29:17 +01004705
4706 intel_dp_aux_fini(intel_dp);
4707
Imre Deakc8bd0e42014-12-12 17:57:38 +02004708 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004709 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004710}
4711
Imre Deakbf93ba62016-04-18 10:04:21 +03004712void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004713{
4714 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4715
4716 if (!is_edp(intel_dp))
4717 return;
4718
Ville Syrjälä951468f2014-09-04 14:55:31 +03004719 /*
4720 * vdd might still be enabled do to the delayed vdd off.
4721 * Make sure vdd is actually turned off here.
4722 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004723 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004724 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004725 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004726 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004727}
4728
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004729static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4730{
4731 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4732 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004733 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004734 enum intel_display_power_domain power_domain;
4735
4736 lockdep_assert_held(&dev_priv->pps_mutex);
4737
4738 if (!edp_have_panel_vdd(intel_dp))
4739 return;
4740
4741 /*
4742 * The VDD bit needs a power domain reference, so if the bit is
4743 * already enabled when we boot or resume, grab this reference and
4744 * schedule a vdd off, so we don't hold on to the reference
4745 * indefinitely.
4746 */
4747 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004748 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004749 intel_display_power_get(dev_priv, power_domain);
4750
4751 edp_panel_vdd_schedule_off(intel_dp);
4752}
4753
Imre Deakbf93ba62016-04-18 10:04:21 +03004754void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004755{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004756 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
4757 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4758
4759 if (!HAS_DDI(dev_priv))
4760 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004761
4762 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4763 return;
4764
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004765 pps_lock(intel_dp);
4766
Imre Deak335f7522016-08-10 14:07:32 +03004767 /* Reinit the power sequencer, in case BIOS did something with it. */
4768 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004769 intel_edp_panel_vdd_sanitize(intel_dp);
4770
4771 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004772}
4773
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004774static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004775 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004776 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004777 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004778 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004779 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004780 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004781 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004782 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004783 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004784 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004785 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004786};
4787
4788static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4789 .get_modes = intel_dp_get_modes,
4790 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004791};
4792
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004793static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004794 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004795 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004796};
4797
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004798enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004799intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4800{
4801 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004802 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004803 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004804 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004805 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004806 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004807
Takashi Iwai25400582015-11-19 12:09:56 +01004808 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4809 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004810 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004811
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004812 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4813 /*
4814 * vdd off can generate a long pulse on eDP which
4815 * would require vdd on to handle it, and thus we
4816 * would end up in an endless cycle of
4817 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4818 */
4819 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4820 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02004821 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004822 }
4823
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004824 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4825 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004826 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004827
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004828 if (long_hpd) {
4829 intel_dp->detect_done = false;
4830 return IRQ_NONE;
4831 }
4832
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004833 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004834 intel_display_power_get(dev_priv, power_domain);
4835
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004836 if (intel_dp->is_mst) {
4837 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4838 /*
4839 * If we were in MST mode, and device is not
4840 * there, get out of MST mode
4841 */
4842 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4843 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4844 intel_dp->is_mst = false;
4845 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4846 intel_dp->is_mst);
4847 intel_dp->detect_done = false;
4848 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004849 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004850 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004851
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004852 if (!intel_dp->is_mst) {
4853 if (!intel_dp_short_pulse(intel_dp)) {
4854 intel_dp->detect_done = false;
4855 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304856 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004857 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004858
4859 ret = IRQ_HANDLED;
4860
Imre Deak1c767b32014-08-18 14:42:42 +03004861put_power:
4862 intel_display_power_put(dev_priv, power_domain);
4863
4864 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004865}
4866
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004867/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004868bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004869{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004870 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004871
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004872 /*
4873 * eDP not supported on g4x. so bail out early just
4874 * for a bit extra safety in case the VBT is bonkers.
4875 */
4876 if (INTEL_INFO(dev)->gen < 5)
4877 return false;
4878
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004879 if (port == PORT_A)
4880 return true;
4881
Jani Nikula951d9ef2016-03-16 12:43:31 +02004882 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004883}
4884
Dave Airlie0e32b392014-05-02 14:02:48 +10004885void
Chris Wilsonf6849602010-09-19 09:29:33 +01004886intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4887{
Yuly Novikov53b41832012-10-26 12:04:00 +03004888 struct intel_connector *intel_connector = to_intel_connector(connector);
4889
Chris Wilson3f43c482011-05-12 22:17:24 +01004890 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004891 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004892 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004893
4894 if (is_edp(intel_dp)) {
4895 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004896 drm_object_attach_property(
4897 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004898 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004899 DRM_MODE_SCALE_ASPECT);
4900 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004901 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004902}
4903
Imre Deakdada1a92014-01-29 13:25:41 +02004904static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4905{
Abhay Kumard28d4732016-01-22 17:39:04 -08004906 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004907 intel_dp->last_power_on = jiffies;
4908 intel_dp->last_backlight_off = jiffies;
4909}
4910
Daniel Vetter67a54562012-10-20 20:57:45 +02004911static void
Imre Deak54648612016-06-16 16:37:22 +03004912intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4913 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004914{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304915 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004916 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004917
Imre Deak8e8232d2016-06-16 16:37:21 +03004918 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004919
4920 /* Workaround: Need to write PP_CONTROL with the unlock key as
4921 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304922 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004923
Imre Deak8e8232d2016-06-16 16:37:21 +03004924 pp_on = I915_READ(regs.pp_on);
4925 pp_off = I915_READ(regs.pp_off);
Imre Deak54648612016-06-16 16:37:22 +03004926 if (!IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004927 I915_WRITE(regs.pp_ctrl, pp_ctl);
4928 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304929 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004930
4931 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004932 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4933 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004934
Imre Deak54648612016-06-16 16:37:22 +03004935 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4936 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004937
Imre Deak54648612016-06-16 16:37:22 +03004938 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4939 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004940
Imre Deak54648612016-06-16 16:37:22 +03004941 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4942 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004943
Imre Deak54648612016-06-16 16:37:22 +03004944 if (IS_BROXTON(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304945 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4946 BXT_POWER_CYCLE_DELAY_SHIFT;
4947 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004948 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304949 else
Imre Deak54648612016-06-16 16:37:22 +03004950 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304951 } else {
Imre Deak54648612016-06-16 16:37:22 +03004952 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004953 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304954 }
Imre Deak54648612016-06-16 16:37:22 +03004955}
4956
4957static void
Imre Deakde9c1b62016-06-16 20:01:46 +03004958intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
4959{
4960 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4961 state_name,
4962 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
4963}
4964
4965static void
4966intel_pps_verify_state(struct drm_i915_private *dev_priv,
4967 struct intel_dp *intel_dp)
4968{
4969 struct edp_power_seq hw;
4970 struct edp_power_seq *sw = &intel_dp->pps_delays;
4971
4972 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
4973
4974 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
4975 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
4976 DRM_ERROR("PPS state mismatch\n");
4977 intel_pps_dump_state("sw", sw);
4978 intel_pps_dump_state("hw", &hw);
4979 }
4980}
4981
4982static void
Imre Deak54648612016-06-16 16:37:22 +03004983intel_dp_init_panel_power_sequencer(struct drm_device *dev,
4984 struct intel_dp *intel_dp)
4985{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004986 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03004987 struct edp_power_seq cur, vbt, spec,
4988 *final = &intel_dp->pps_delays;
4989
4990 lockdep_assert_held(&dev_priv->pps_mutex);
4991
4992 /* already initialized? */
4993 if (final->t11_t12 != 0)
4994 return;
4995
4996 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02004997
Imre Deakde9c1b62016-06-16 20:01:46 +03004998 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02004999
Jani Nikula6aa23e62016-03-24 17:50:20 +02005000 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005001
5002 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5003 * our hw here, which are all in 100usec. */
5004 spec.t1_t3 = 210 * 10;
5005 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5006 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5007 spec.t10 = 500 * 10;
5008 /* This one is special and actually in units of 100ms, but zero
5009 * based in the hw (so we need to add 100 ms). But the sw vbt
5010 * table multiplies it with 1000 to make it in units of 100usec,
5011 * too. */
5012 spec.t11_t12 = (510 + 100) * 10;
5013
Imre Deakde9c1b62016-06-16 20:01:46 +03005014 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005015
5016 /* Use the max of the register settings and vbt. If both are
5017 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005018#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005019 spec.field : \
5020 max(cur.field, vbt.field))
5021 assign_final(t1_t3);
5022 assign_final(t8);
5023 assign_final(t9);
5024 assign_final(t10);
5025 assign_final(t11_t12);
5026#undef assign_final
5027
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005028#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005029 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5030 intel_dp->backlight_on_delay = get_delay(t8);
5031 intel_dp->backlight_off_delay = get_delay(t9);
5032 intel_dp->panel_power_down_delay = get_delay(t10);
5033 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5034#undef get_delay
5035
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005036 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5037 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5038 intel_dp->panel_power_cycle_delay);
5039
5040 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5041 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005042
5043 /*
5044 * We override the HW backlight delays to 1 because we do manual waits
5045 * on them. For T8, even BSpec recommends doing it. For T9, if we
5046 * don't do this, we'll end up waiting for the backlight off delay
5047 * twice: once when we do the manual sleep, and once when we disable
5048 * the panel and wait for the PP_STATUS bit to become zero.
5049 */
5050 final->t8 = 1;
5051 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005052}
5053
5054static void
5055intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005056 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005057{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005058 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005059 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005060 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005061 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005062 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005063 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005064
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005065 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005066
Imre Deak8e8232d2016-06-16 16:37:21 +03005067 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005068
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005069 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005070 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5071 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005072 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005073 /* Compute the divisor for the pp clock, simply match the Bspec
5074 * formula. */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005075 if (IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005076 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305077 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5078 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5079 << BXT_POWER_CYCLE_DELAY_SHIFT);
5080 } else {
5081 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5082 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5083 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5084 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005085
5086 /* Haswell doesn't have any port selection bits for the panel
5087 * power sequencer any more. */
Wayne Boyer666a4532015-12-09 12:29:35 -08005088 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005089 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005090 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005091 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005092 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005093 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005094 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005095 }
5096
Jesse Barnes453c5422013-03-28 09:55:41 -07005097 pp_on |= port_sel;
5098
Imre Deak8e8232d2016-06-16 16:37:21 +03005099 I915_WRITE(regs.pp_on, pp_on);
5100 I915_WRITE(regs.pp_off, pp_off);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005101 if (IS_BROXTON(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005102 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305103 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005104 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005105
Daniel Vetter67a54562012-10-20 20:57:45 +02005106 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 +03005107 I915_READ(regs.pp_on),
5108 I915_READ(regs.pp_off),
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005109 IS_BROXTON(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005110 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5111 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005112}
5113
Imre Deak335f7522016-08-10 14:07:32 +03005114static void intel_dp_pps_init(struct drm_device *dev,
5115 struct intel_dp *intel_dp)
5116{
5117 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
5118 vlv_initial_power_sequencer_setup(intel_dp);
5119 } else {
5120 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5121 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5122 }
5123}
5124
Vandana Kannanb33a2812015-02-13 15:33:03 +05305125/**
5126 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005127 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005128 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305129 * @refresh_rate: RR to be programmed
5130 *
5131 * This function gets called when refresh rate (RR) has to be changed from
5132 * one frequency to another. Switches can be between high and low RR
5133 * supported by the panel or to any other RR based on media playback (in
5134 * this case, RR value needs to be passed from user space).
5135 *
5136 * The caller of this function needs to take a lock on dev_priv->drrs.
5137 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005138static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5139 struct intel_crtc_state *crtc_state,
5140 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305141{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305142 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305143 struct intel_digital_port *dig_port = NULL;
5144 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005145 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305146 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305147
5148 if (refresh_rate <= 0) {
5149 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5150 return;
5151 }
5152
Vandana Kannan96178ee2015-01-10 02:25:56 +05305153 if (intel_dp == NULL) {
5154 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305155 return;
5156 }
5157
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005158 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005159 * FIXME: This needs proper synchronization with psr state for some
5160 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005161 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305162
Vandana Kannan96178ee2015-01-10 02:25:56 +05305163 dig_port = dp_to_dig_port(intel_dp);
5164 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005165 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305166
5167 if (!intel_crtc) {
5168 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5169 return;
5170 }
5171
Vandana Kannan96178ee2015-01-10 02:25:56 +05305172 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305173 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5174 return;
5175 }
5176
Vandana Kannan96178ee2015-01-10 02:25:56 +05305177 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5178 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305179 index = DRRS_LOW_RR;
5180
Vandana Kannan96178ee2015-01-10 02:25:56 +05305181 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305182 DRM_DEBUG_KMS(
5183 "DRRS requested for previously set RR...ignoring\n");
5184 return;
5185 }
5186
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005187 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305188 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5189 return;
5190 }
5191
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005192 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305193 switch (index) {
5194 case DRRS_HIGH_RR:
5195 intel_dp_set_m_n(intel_crtc, M1_N1);
5196 break;
5197 case DRRS_LOW_RR:
5198 intel_dp_set_m_n(intel_crtc, M2_N2);
5199 break;
5200 case DRRS_MAX_RR:
5201 default:
5202 DRM_ERROR("Unsupported refreshrate type\n");
5203 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005204 } else if (INTEL_GEN(dev_priv) > 6) {
5205 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005206 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305207
Ville Syrjälä649636e2015-09-22 19:50:01 +03005208 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305209 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005210 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305211 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5212 else
5213 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305214 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005215 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305216 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5217 else
5218 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305219 }
5220 I915_WRITE(reg, val);
5221 }
5222
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305223 dev_priv->drrs.refresh_rate_type = index;
5224
5225 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5226}
5227
Vandana Kannanb33a2812015-02-13 15:33:03 +05305228/**
5229 * intel_edp_drrs_enable - init drrs struct if supported
5230 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005231 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305232 *
5233 * Initializes frontbuffer_bits and drrs.dp
5234 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005235void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5236 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305237{
5238 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005239 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305240
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005241 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305242 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5243 return;
5244 }
5245
5246 mutex_lock(&dev_priv->drrs.mutex);
5247 if (WARN_ON(dev_priv->drrs.dp)) {
5248 DRM_ERROR("DRRS already enabled\n");
5249 goto unlock;
5250 }
5251
5252 dev_priv->drrs.busy_frontbuffer_bits = 0;
5253
5254 dev_priv->drrs.dp = intel_dp;
5255
5256unlock:
5257 mutex_unlock(&dev_priv->drrs.mutex);
5258}
5259
Vandana Kannanb33a2812015-02-13 15:33:03 +05305260/**
5261 * intel_edp_drrs_disable - Disable DRRS
5262 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005263 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305264 *
5265 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005266void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5267 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305268{
5269 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005270 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305271
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005272 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305273 return;
5274
5275 mutex_lock(&dev_priv->drrs.mutex);
5276 if (!dev_priv->drrs.dp) {
5277 mutex_unlock(&dev_priv->drrs.mutex);
5278 return;
5279 }
5280
5281 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005282 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5283 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305284
5285 dev_priv->drrs.dp = NULL;
5286 mutex_unlock(&dev_priv->drrs.mutex);
5287
5288 cancel_delayed_work_sync(&dev_priv->drrs.work);
5289}
5290
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305291static void intel_edp_drrs_downclock_work(struct work_struct *work)
5292{
5293 struct drm_i915_private *dev_priv =
5294 container_of(work, typeof(*dev_priv), drrs.work.work);
5295 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305296
Vandana Kannan96178ee2015-01-10 02:25:56 +05305297 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305298
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305299 intel_dp = dev_priv->drrs.dp;
5300
5301 if (!intel_dp)
5302 goto unlock;
5303
5304 /*
5305 * The delayed work can race with an invalidate hence we need to
5306 * recheck.
5307 */
5308
5309 if (dev_priv->drrs.busy_frontbuffer_bits)
5310 goto unlock;
5311
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005312 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5313 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5314
5315 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5316 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5317 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305318
5319unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305320 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305321}
5322
Vandana Kannanb33a2812015-02-13 15:33:03 +05305323/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305324 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005325 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305326 * @frontbuffer_bits: frontbuffer plane tracking bits
5327 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305328 * This function gets called everytime rendering on the given planes start.
5329 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305330 *
5331 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5332 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005333void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5334 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305335{
Vandana Kannana93fad02015-01-10 02:25:59 +05305336 struct drm_crtc *crtc;
5337 enum pipe pipe;
5338
Daniel Vetter9da7d692015-04-09 16:44:15 +02005339 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305340 return;
5341
Daniel Vetter88f933a2015-04-09 16:44:16 +02005342 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305343
Vandana Kannana93fad02015-01-10 02:25:59 +05305344 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005345 if (!dev_priv->drrs.dp) {
5346 mutex_unlock(&dev_priv->drrs.mutex);
5347 return;
5348 }
5349
Vandana Kannana93fad02015-01-10 02:25:59 +05305350 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5351 pipe = to_intel_crtc(crtc)->pipe;
5352
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005353 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5354 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5355
Ramalingam C0ddfd202015-06-15 20:50:05 +05305356 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005357 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005358 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5359 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305360
Vandana Kannana93fad02015-01-10 02:25:59 +05305361 mutex_unlock(&dev_priv->drrs.mutex);
5362}
5363
Vandana Kannanb33a2812015-02-13 15:33:03 +05305364/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305365 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005366 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305367 * @frontbuffer_bits: frontbuffer plane tracking bits
5368 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305369 * This function gets called every time rendering on the given planes has
5370 * completed or flip on a crtc is completed. So DRRS should be upclocked
5371 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5372 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305373 *
5374 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5375 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005376void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5377 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305378{
Vandana Kannana93fad02015-01-10 02:25:59 +05305379 struct drm_crtc *crtc;
5380 enum pipe pipe;
5381
Daniel Vetter9da7d692015-04-09 16:44:15 +02005382 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305383 return;
5384
Daniel Vetter88f933a2015-04-09 16:44:16 +02005385 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305386
Vandana Kannana93fad02015-01-10 02:25:59 +05305387 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005388 if (!dev_priv->drrs.dp) {
5389 mutex_unlock(&dev_priv->drrs.mutex);
5390 return;
5391 }
5392
Vandana Kannana93fad02015-01-10 02:25:59 +05305393 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5394 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005395
5396 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305397 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5398
Ramalingam C0ddfd202015-06-15 20:50:05 +05305399 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005400 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005401 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5402 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305403
5404 /*
5405 * flush also means no more activity hence schedule downclock, if all
5406 * other fbs are quiescent too
5407 */
5408 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305409 schedule_delayed_work(&dev_priv->drrs.work,
5410 msecs_to_jiffies(1000));
5411 mutex_unlock(&dev_priv->drrs.mutex);
5412}
5413
Vandana Kannanb33a2812015-02-13 15:33:03 +05305414/**
5415 * DOC: Display Refresh Rate Switching (DRRS)
5416 *
5417 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5418 * which enables swtching between low and high refresh rates,
5419 * dynamically, based on the usage scenario. This feature is applicable
5420 * for internal panels.
5421 *
5422 * Indication that the panel supports DRRS is given by the panel EDID, which
5423 * would list multiple refresh rates for one resolution.
5424 *
5425 * DRRS is of 2 types - static and seamless.
5426 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5427 * (may appear as a blink on screen) and is used in dock-undock scenario.
5428 * Seamless DRRS involves changing RR without any visual effect to the user
5429 * and can be used during normal system usage. This is done by programming
5430 * certain registers.
5431 *
5432 * Support for static/seamless DRRS may be indicated in the VBT based on
5433 * inputs from the panel spec.
5434 *
5435 * DRRS saves power by switching to low RR based on usage scenarios.
5436 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005437 * The implementation is based on frontbuffer tracking implementation. When
5438 * there is a disturbance on the screen triggered by user activity or a periodic
5439 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5440 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5441 * made.
5442 *
5443 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5444 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305445 *
5446 * DRRS can be further extended to support other internal panels and also
5447 * the scenario of video playback wherein RR is set based on the rate
5448 * requested by userspace.
5449 */
5450
5451/**
5452 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5453 * @intel_connector: eDP connector
5454 * @fixed_mode: preferred mode of panel
5455 *
5456 * This function is called only once at driver load to initialize basic
5457 * DRRS stuff.
5458 *
5459 * Returns:
5460 * Downclock mode if panel supports it, else return NULL.
5461 * DRRS support is determined by the presence of downclock mode (apart
5462 * from VBT setting).
5463 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305464static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305465intel_dp_drrs_init(struct intel_connector *intel_connector,
5466 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305467{
5468 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305469 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005470 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305471 struct drm_display_mode *downclock_mode = NULL;
5472
Daniel Vetter9da7d692015-04-09 16:44:15 +02005473 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5474 mutex_init(&dev_priv->drrs.mutex);
5475
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305476 if (INTEL_INFO(dev)->gen <= 6) {
5477 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5478 return NULL;
5479 }
5480
5481 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005482 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305483 return NULL;
5484 }
5485
5486 downclock_mode = intel_find_panel_downclock
5487 (dev, fixed_mode, connector);
5488
5489 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305490 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305491 return NULL;
5492 }
5493
Vandana Kannan96178ee2015-01-10 02:25:56 +05305494 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305495
Vandana Kannan96178ee2015-01-10 02:25:56 +05305496 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005497 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305498 return downclock_mode;
5499}
5500
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005501static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005502 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005503{
5504 struct drm_connector *connector = &intel_connector->base;
5505 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005506 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5507 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005508 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005509 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305510 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005511 bool has_dpcd;
5512 struct drm_display_mode *scan;
5513 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005514 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005515
5516 if (!is_edp(intel_dp))
5517 return true;
5518
Imre Deak97a824e12016-06-21 11:51:47 +03005519 /*
5520 * On IBX/CPT we may get here with LVDS already registered. Since the
5521 * driver uses the only internal power sequencer available for both
5522 * eDP and LVDS bail out early in this case to prevent interfering
5523 * with an already powered-on LVDS power sequencer.
5524 */
5525 if (intel_get_lvds_encoder(dev)) {
5526 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5527 DRM_INFO("LVDS was detected, not registering eDP\n");
5528
5529 return false;
5530 }
5531
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005532 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005533
5534 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005535 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005536 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005537
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005538 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005539
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005540 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005541 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005542
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005543 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005544 /* if this fails, presume the device is a ghost */
5545 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005546 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005547 }
5548
Daniel Vetter060c8772014-03-21 23:22:35 +01005549 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005550 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005551 if (edid) {
5552 if (drm_add_edid_modes(connector, edid)) {
5553 drm_mode_connector_update_edid_property(connector,
5554 edid);
5555 drm_edid_to_eld(connector, edid);
5556 } else {
5557 kfree(edid);
5558 edid = ERR_PTR(-EINVAL);
5559 }
5560 } else {
5561 edid = ERR_PTR(-ENOENT);
5562 }
5563 intel_connector->edid = edid;
5564
5565 /* prefer fixed mode from EDID if available */
5566 list_for_each_entry(scan, &connector->probed_modes, head) {
5567 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5568 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305569 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305570 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005571 break;
5572 }
5573 }
5574
5575 /* fallback to VBT if available for eDP */
5576 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5577 fixed_mode = drm_mode_duplicate(dev,
5578 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005579 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005580 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005581 connector->display_info.width_mm = fixed_mode->width_mm;
5582 connector->display_info.height_mm = fixed_mode->height_mm;
5583 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005584 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005585 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005586
Wayne Boyer666a4532015-12-09 12:29:35 -08005587 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005588 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5589 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005590
5591 /*
5592 * Figure out the current pipe for the initial backlight setup.
5593 * If the current pipe isn't valid, try the PPS pipe, and if that
5594 * fails just assume pipe A.
5595 */
5596 if (IS_CHERRYVIEW(dev))
5597 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5598 else
5599 pipe = PORT_TO_PIPE(intel_dp->DP);
5600
5601 if (pipe != PIPE_A && pipe != PIPE_B)
5602 pipe = intel_dp->pps_pipe;
5603
5604 if (pipe != PIPE_A && pipe != PIPE_B)
5605 pipe = PIPE_A;
5606
5607 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5608 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005609 }
5610
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305611 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005612 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005613 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005614
5615 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005616
5617out_vdd_off:
5618 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5619 /*
5620 * vdd might still be enabled do to the delayed vdd off.
5621 * Make sure vdd is actually turned off here.
5622 */
5623 pps_lock(intel_dp);
5624 edp_panel_vdd_off_sync(intel_dp);
5625 pps_unlock(intel_dp);
5626
5627 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005628}
5629
Paulo Zanoni16c25532013-06-12 17:27:25 -03005630bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005631intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5632 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005633{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005634 struct drm_connector *connector = &intel_connector->base;
5635 struct intel_dp *intel_dp = &intel_dig_port->dp;
5636 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5637 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005638 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005639 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005640 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005641
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005642 if (WARN(intel_dig_port->max_lanes < 1,
5643 "Not enough lanes (%d) for DP on port %c\n",
5644 intel_dig_port->max_lanes, port_name(port)))
5645 return false;
5646
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005647 intel_dp->pps_pipe = INVALID_PIPE;
5648
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005649 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005650 if (INTEL_INFO(dev)->gen >= 9)
5651 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005652 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005653 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005654 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005655 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5656 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005657 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005658
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005659 if (INTEL_INFO(dev)->gen >= 9)
5660 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5661 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005662 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005663
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005664 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005665 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5666
Daniel Vetter07679352012-09-06 22:15:42 +02005667 /* Preserve the current hw state. */
5668 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005669 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005670
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005671 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305672 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005673 else
5674 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005675
Imre Deakf7d24902013-05-08 13:14:05 +03005676 /*
5677 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5678 * for DP the encoder type can be set by the caller to
5679 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5680 */
5681 if (type == DRM_MODE_CONNECTOR_eDP)
5682 intel_encoder->type = INTEL_OUTPUT_EDP;
5683
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005684 /* eDP only on port B and/or C on vlv/chv */
Wayne Boyer666a4532015-12-09 12:29:35 -08005685 if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
5686 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005687 return false;
5688
Imre Deake7281ea2013-05-08 13:14:08 +03005689 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5690 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5691 port_name(port));
5692
Adam Jacksonb3295302010-07-16 14:46:28 -04005693 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005694 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5695
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005696 connector->interlace_allowed = true;
5697 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005698
Mika Kaholab6339582016-09-09 14:10:52 +03005699 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005700
Daniel Vetter66a92782012-07-12 20:08:18 +02005701 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005702 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005703
Chris Wilsondf0e9242010-09-09 16:20:55 +01005704 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005705
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005706 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005707 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5708 else
5709 intel_connector->get_hw_state = intel_connector_get_hw_state;
5710
Jani Nikula0b998362014-03-14 16:51:17 +02005711 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005712 switch (port) {
5713 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005714 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005715 break;
5716 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005717 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005718 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305719 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005720 break;
5721 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005722 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005723 break;
5724 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005725 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005726 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005727 case PORT_E:
5728 intel_encoder->hpd_pin = HPD_PORT_E;
5729 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005730 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005731 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005732 }
5733
Dave Airlie0e32b392014-05-02 14:02:48 +10005734 /* init MST on ports that can support it */
Ville Syrjäläf8e58dd2016-06-22 21:56:59 +03005735 if (HAS_DP_MST(dev) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005736 (port == PORT_B || port == PORT_C || port == PORT_D))
5737 intel_dp_mst_encoder_init(intel_dig_port,
5738 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005739
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005740 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005741 intel_dp_aux_fini(intel_dp);
5742 intel_dp_mst_encoder_cleanup(intel_dig_port);
5743 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005744 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005745
Chris Wilsonf6849602010-09-19 09:29:33 +01005746 intel_dp_add_properties(intel_dp, connector);
5747
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005748 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5749 * 0xd. Failure to do so will result in spurious interrupts being
5750 * generated on the port when a cable is not attached.
5751 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005752 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005753 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5754 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5755 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005756
5757 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005758
5759fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005760 drm_connector_cleanup(connector);
5761
5762 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005763}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005764
Chris Wilson457c52d2016-06-01 08:27:50 +01005765bool intel_dp_init(struct drm_device *dev,
5766 i915_reg_t output_reg,
5767 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005768{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005769 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005770 struct intel_digital_port *intel_dig_port;
5771 struct intel_encoder *intel_encoder;
5772 struct drm_encoder *encoder;
5773 struct intel_connector *intel_connector;
5774
Daniel Vetterb14c5672013-09-19 12:18:32 +02005775 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005776 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005777 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005778
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005779 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305780 if (!intel_connector)
5781 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005782
5783 intel_encoder = &intel_dig_port->base;
5784 encoder = &intel_encoder->base;
5785
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305786 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005787 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305788 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005789
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005790 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005791 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005792 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005793 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005794 intel_encoder->suspend = intel_dp_encoder_suspend;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005795 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005796 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005797 intel_encoder->pre_enable = chv_pre_enable_dp;
5798 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005799 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005800 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005801 } else if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005802 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005803 intel_encoder->pre_enable = vlv_pre_enable_dp;
5804 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005805 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005806 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005807 intel_encoder->pre_enable = g4x_pre_enable_dp;
5808 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005809 if (INTEL_INFO(dev)->gen >= 5)
5810 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005811 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005812
Paulo Zanoni174edf12012-10-26 19:05:50 -02005813 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005814 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005815 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005816
Ville Syrjäläcca05022016-06-22 21:57:06 +03005817 intel_encoder->type = INTEL_OUTPUT_DP;
Ville Syrjälä882ec382014-04-28 14:07:43 +03005818 if (IS_CHERRYVIEW(dev)) {
5819 if (port == PORT_D)
5820 intel_encoder->crtc_mask = 1 << 2;
5821 else
5822 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5823 } else {
5824 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5825 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005826 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005827 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005828
Dave Airlie13cf5502014-06-18 11:29:35 +10005829 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005830 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005831
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305832 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5833 goto err_init_connector;
5834
Chris Wilson457c52d2016-06-01 08:27:50 +01005835 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305836
5837err_init_connector:
5838 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305839err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305840 kfree(intel_connector);
5841err_connector_alloc:
5842 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005843 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005844}
Dave Airlie0e32b392014-05-02 14:02:48 +10005845
5846void intel_dp_mst_suspend(struct drm_device *dev)
5847{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005848 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005849 int i;
5850
5851 /* disable MST */
5852 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005853 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005854
5855 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005856 continue;
5857
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005858 if (intel_dig_port->dp.is_mst)
5859 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005860 }
5861}
5862
5863void intel_dp_mst_resume(struct drm_device *dev)
5864{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005865 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005866 int i;
5867
5868 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005869 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005870 int ret;
5871
5872 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005873 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005874
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005875 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5876 if (ret)
5877 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005878 }
5879}