blob: d8cc4f373d00096432b165bdae33282b5928e898 [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
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000193static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700194intel_dp_mode_valid(struct drm_connector *connector,
195 struct drm_display_mode *mode)
196{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100197 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300198 struct intel_connector *intel_connector = to_intel_connector(connector);
199 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100200 int target_clock = mode->clock;
201 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola799487f2016-02-02 15:16:38 +0200202 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700203
Jani Nikuladd06f902012-10-19 14:51:50 +0300204 if (is_edp(intel_dp) && fixed_mode) {
205 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100206 return MODE_PANEL;
207
Jani Nikuladd06f902012-10-19 14:51:50 +0300208 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100209 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200210
211 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100212 }
213
Ville Syrjälä50fec212015-03-12 17:10:34 +0200214 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300215 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100216
217 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
218 mode_rate = intel_dp_link_required(target_clock, 18);
219
Mika Kahola799487f2016-02-02 15:16:38 +0200220 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200221 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700222
223 if (mode->clock < 10000)
224 return MODE_CLOCK_LOW;
225
Daniel Vetter0af78a22012-05-23 11:30:55 +0200226 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
227 return MODE_H_ILLEGAL;
228
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700229 return MODE_OK;
230}
231
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800232uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700233{
234 int i;
235 uint32_t v = 0;
236
237 if (src_bytes > 4)
238 src_bytes = 4;
239 for (i = 0; i < src_bytes; i++)
240 v |= ((uint32_t) src[i]) << ((3-i) * 8);
241 return v;
242}
243
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000244static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700245{
246 int i;
247 if (dst_bytes > 4)
248 dst_bytes = 4;
249 for (i = 0; i < dst_bytes; i++)
250 dst[i] = src >> ((3-i) * 8);
251}
252
Jani Nikulabf13e812013-09-06 07:40:05 +0300253static void
254intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300255 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300256static void
257intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300258 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300259
Ville Syrjälä773538e82014-09-04 14:54:56 +0300260static void pps_lock(struct intel_dp *intel_dp)
261{
262 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
263 struct intel_encoder *encoder = &intel_dig_port->base;
264 struct drm_device *dev = encoder->base.dev;
265 struct drm_i915_private *dev_priv = dev->dev_private;
266 enum intel_display_power_domain power_domain;
267
268 /*
269 * See vlv_power_sequencer_reset() why we need
270 * a power domain reference here.
271 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100272 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300273 intel_display_power_get(dev_priv, power_domain);
274
275 mutex_lock(&dev_priv->pps_mutex);
276}
277
278static void pps_unlock(struct intel_dp *intel_dp)
279{
280 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
281 struct intel_encoder *encoder = &intel_dig_port->base;
282 struct drm_device *dev = encoder->base.dev;
283 struct drm_i915_private *dev_priv = dev->dev_private;
284 enum intel_display_power_domain power_domain;
285
286 mutex_unlock(&dev_priv->pps_mutex);
287
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100288 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300289 intel_display_power_put(dev_priv, power_domain);
290}
291
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300292static void
293vlv_power_sequencer_kick(struct intel_dp *intel_dp)
294{
295 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
296 struct drm_device *dev = intel_dig_port->base.base.dev;
297 struct drm_i915_private *dev_priv = dev->dev_private;
298 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300299 bool pll_enabled, release_cl_override = false;
300 enum dpio_phy phy = DPIO_PHY(pipe);
301 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300302 uint32_t DP;
303
304 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
305 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
306 pipe_name(pipe), port_name(intel_dig_port->port)))
307 return;
308
309 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
310 pipe_name(pipe), port_name(intel_dig_port->port));
311
312 /* Preserve the BIOS-computed detected bit. This is
313 * supposed to be read-only.
314 */
315 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
316 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
317 DP |= DP_PORT_WIDTH(1);
318 DP |= DP_LINK_TRAIN_PAT_1;
319
320 if (IS_CHERRYVIEW(dev))
321 DP |= DP_PIPE_SELECT_CHV(pipe);
322 else if (pipe == PIPE_B)
323 DP |= DP_PIPEB_SELECT;
324
Ville Syrjäläd288f652014-10-28 13:20:22 +0200325 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
326
327 /*
328 * The DPLL for the pipe must be enabled for this to work.
329 * So enable temporarily it if it's not already enabled.
330 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300331 if (!pll_enabled) {
332 release_cl_override = IS_CHERRYVIEW(dev) &&
333 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
334
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000335 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
336 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
337 DRM_ERROR("Failed to force on pll for pipe %c!\n",
338 pipe_name(pipe));
339 return;
340 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300341 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200342
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300343 /*
344 * Similar magic as in intel_dp_enable_port().
345 * We _must_ do this port enable + disable trick
346 * to make this power seqeuencer lock onto the port.
347 * Otherwise even VDD force bit won't work.
348 */
349 I915_WRITE(intel_dp->output_reg, DP);
350 POSTING_READ(intel_dp->output_reg);
351
352 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
353 POSTING_READ(intel_dp->output_reg);
354
355 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
356 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200357
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300358 if (!pll_enabled) {
Ville Syrjäläd288f652014-10-28 13:20:22 +0200359 vlv_force_pll_off(dev, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300360
361 if (release_cl_override)
362 chv_phy_powergate_ch(dev_priv, phy, ch, false);
363 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300364}
365
Jani Nikulabf13e812013-09-06 07:40:05 +0300366static enum pipe
367vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
368{
369 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300370 struct drm_device *dev = intel_dig_port->base.base.dev;
371 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300372 struct intel_encoder *encoder;
373 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300374 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300375
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300376 lockdep_assert_held(&dev_priv->pps_mutex);
377
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300378 /* We should never land here with regular DP ports */
379 WARN_ON(!is_edp(intel_dp));
380
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300381 if (intel_dp->pps_pipe != INVALID_PIPE)
382 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300383
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300384 /*
385 * We don't have power sequencer currently.
386 * Pick one that's not used by other ports.
387 */
Jani Nikula19c80542015-12-16 12:48:16 +0200388 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300389 struct intel_dp *tmp;
390
391 if (encoder->type != INTEL_OUTPUT_EDP)
392 continue;
393
394 tmp = enc_to_intel_dp(&encoder->base);
395
396 if (tmp->pps_pipe != INVALID_PIPE)
397 pipes &= ~(1 << tmp->pps_pipe);
398 }
399
400 /*
401 * Didn't find one. This should not happen since there
402 * are two power sequencers and up to two eDP ports.
403 */
404 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300405 pipe = PIPE_A;
406 else
407 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300408
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300409 vlv_steal_power_sequencer(dev, pipe);
410 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300411
412 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
413 pipe_name(intel_dp->pps_pipe),
414 port_name(intel_dig_port->port));
415
416 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300417 intel_dp_init_panel_power_sequencer(dev, intel_dp);
418 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300419
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300420 /*
421 * Even vdd force doesn't work until we've made
422 * the power sequencer lock in on the port.
423 */
424 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300425
426 return intel_dp->pps_pipe;
427}
428
Imre Deak78597992016-06-16 16:37:20 +0300429static int
430bxt_power_sequencer_idx(struct intel_dp *intel_dp)
431{
432 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
433 struct drm_device *dev = intel_dig_port->base.base.dev;
434 struct drm_i915_private *dev_priv = dev->dev_private;
435
436 lockdep_assert_held(&dev_priv->pps_mutex);
437
438 /* We should never land here with regular DP ports */
439 WARN_ON(!is_edp(intel_dp));
440
441 /*
442 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
443 * mapping needs to be retrieved from VBT, for now just hard-code to
444 * use instance #0 always.
445 */
446 if (!intel_dp->pps_reset)
447 return 0;
448
449 intel_dp->pps_reset = false;
450
451 /*
452 * Only the HW needs to be reprogrammed, the SW state is fixed and
453 * has been setup during connector init.
454 */
455 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
456
457 return 0;
458}
459
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300460typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
461 enum pipe pipe);
462
463static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
464 enum pipe pipe)
465{
466 return I915_READ(VLV_PIPE_PP_STATUS(pipe)) & PP_ON;
467}
468
469static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
470 enum pipe pipe)
471{
472 return I915_READ(VLV_PIPE_PP_CONTROL(pipe)) & EDP_FORCE_VDD;
473}
474
475static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
476 enum pipe pipe)
477{
478 return true;
479}
480
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300481static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300482vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
483 enum port port,
484 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300485{
Jani Nikulabf13e812013-09-06 07:40:05 +0300486 enum pipe pipe;
487
Jani Nikulabf13e812013-09-06 07:40:05 +0300488 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
489 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
490 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300491
492 if (port_sel != PANEL_PORT_SELECT_VLV(port))
493 continue;
494
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300495 if (!pipe_check(dev_priv, pipe))
496 continue;
497
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300498 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300499 }
500
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300501 return INVALID_PIPE;
502}
503
504static void
505vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
506{
507 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
508 struct drm_device *dev = intel_dig_port->base.base.dev;
509 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300510 enum port port = intel_dig_port->port;
511
512 lockdep_assert_held(&dev_priv->pps_mutex);
513
514 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300515 /* first pick one where the panel is on */
516 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
517 vlv_pipe_has_pp_on);
518 /* didn't find one? pick one where vdd is on */
519 if (intel_dp->pps_pipe == INVALID_PIPE)
520 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
521 vlv_pipe_has_vdd_on);
522 /* didn't find one? pick one with just the correct port */
523 if (intel_dp->pps_pipe == INVALID_PIPE)
524 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
525 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300526
527 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
528 if (intel_dp->pps_pipe == INVALID_PIPE) {
529 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
530 port_name(port));
531 return;
532 }
533
534 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
535 port_name(port), pipe_name(intel_dp->pps_pipe));
536
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300537 intel_dp_init_panel_power_sequencer(dev, intel_dp);
538 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300539}
540
Imre Deak78597992016-06-16 16:37:20 +0300541void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300542{
543 struct drm_device *dev = dev_priv->dev;
544 struct intel_encoder *encoder;
545
Imre Deak78597992016-06-16 16:37:20 +0300546 if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
547 !IS_BROXTON(dev)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300548 return;
549
550 /*
551 * We can't grab pps_mutex here due to deadlock with power_domain
552 * mutex when power_domain functions are called while holding pps_mutex.
553 * That also means that in order to use pps_pipe the code needs to
554 * hold both a power domain reference and pps_mutex, and the power domain
555 * reference get/put must be done while _not_ holding pps_mutex.
556 * pps_{lock,unlock}() do these steps in the correct order, so one
557 * should use them always.
558 */
559
Jani Nikula19c80542015-12-16 12:48:16 +0200560 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300561 struct intel_dp *intel_dp;
562
563 if (encoder->type != INTEL_OUTPUT_EDP)
564 continue;
565
566 intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak78597992016-06-16 16:37:20 +0300567 if (IS_BROXTON(dev))
568 intel_dp->pps_reset = true;
569 else
570 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300571 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300572}
573
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200574static i915_reg_t
575_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300576{
577 struct drm_device *dev = intel_dp_to_dev(intel_dp);
578
Vandana Kannanb0a08be2015-06-18 11:00:55 +0530579 if (IS_BROXTON(dev))
Imre Deak78597992016-06-16 16:37:20 +0300580 return BXT_PP_CONTROL(bxt_power_sequencer_idx(intel_dp));
Vandana Kannanb0a08be2015-06-18 11:00:55 +0530581 else if (HAS_PCH_SPLIT(dev))
Jani Nikulabf13e812013-09-06 07:40:05 +0300582 return PCH_PP_CONTROL;
583 else
584 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
585}
586
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200587static i915_reg_t
588_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300589{
590 struct drm_device *dev = intel_dp_to_dev(intel_dp);
591
Vandana Kannanb0a08be2015-06-18 11:00:55 +0530592 if (IS_BROXTON(dev))
Imre Deak78597992016-06-16 16:37:20 +0300593 return BXT_PP_STATUS(bxt_power_sequencer_idx(intel_dp));
Vandana Kannanb0a08be2015-06-18 11:00:55 +0530594 else if (HAS_PCH_SPLIT(dev))
Jani Nikulabf13e812013-09-06 07:40:05 +0300595 return PCH_PP_STATUS;
596 else
597 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
598}
599
Clint Taylor01527b32014-07-07 13:01:46 -0700600/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
601 This function only applicable when panel PM state is not to be tracked */
602static int edp_notify_handler(struct notifier_block *this, unsigned long code,
603 void *unused)
604{
605 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
606 edp_notifier);
607 struct drm_device *dev = intel_dp_to_dev(intel_dp);
608 struct drm_i915_private *dev_priv = dev->dev_private;
Clint Taylor01527b32014-07-07 13:01:46 -0700609
610 if (!is_edp(intel_dp) || code != SYS_RESTART)
611 return 0;
612
Ville Syrjälä773538e82014-09-04 14:54:56 +0300613 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300614
Wayne Boyer666a4532015-12-09 12:29:35 -0800615 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300616 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200617 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300618 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300619
Clint Taylor01527b32014-07-07 13:01:46 -0700620 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
621 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
622 pp_div = I915_READ(pp_div_reg);
623 pp_div &= PP_REFERENCE_DIVIDER_MASK;
624
625 /* 0x1F write to PP_DIV_REG sets max cycle delay */
626 I915_WRITE(pp_div_reg, pp_div | 0x1F);
627 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
628 msleep(intel_dp->panel_power_cycle_delay);
629 }
630
Ville Syrjälä773538e82014-09-04 14:54:56 +0300631 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300632
Clint Taylor01527b32014-07-07 13:01:46 -0700633 return 0;
634}
635
Daniel Vetter4be73782014-01-17 14:39:48 +0100636static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700637{
Paulo Zanoni30add222012-10-26 19:05:45 -0200638 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700639 struct drm_i915_private *dev_priv = dev->dev_private;
640
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300641 lockdep_assert_held(&dev_priv->pps_mutex);
642
Wayne Boyer666a4532015-12-09 12:29:35 -0800643 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300644 intel_dp->pps_pipe == INVALID_PIPE)
645 return false;
646
Jani Nikulabf13e812013-09-06 07:40:05 +0300647 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700648}
649
Daniel Vetter4be73782014-01-17 14:39:48 +0100650static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700651{
Paulo Zanoni30add222012-10-26 19:05:45 -0200652 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700653 struct drm_i915_private *dev_priv = dev->dev_private;
654
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300655 lockdep_assert_held(&dev_priv->pps_mutex);
656
Wayne Boyer666a4532015-12-09 12:29:35 -0800657 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300658 intel_dp->pps_pipe == INVALID_PIPE)
659 return false;
660
Ville Syrjälä773538e82014-09-04 14:54:56 +0300661 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700662}
663
Keith Packard9b984da2011-09-19 13:54:47 -0700664static void
665intel_dp_check_edp(struct intel_dp *intel_dp)
666{
Paulo Zanoni30add222012-10-26 19:05:45 -0200667 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700668 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700669
Keith Packard9b984da2011-09-19 13:54:47 -0700670 if (!is_edp(intel_dp))
671 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700672
Daniel Vetter4be73782014-01-17 14:39:48 +0100673 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700674 WARN(1, "eDP powered off while attempting aux channel communication.\n");
675 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300676 I915_READ(_pp_stat_reg(intel_dp)),
677 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700678 }
679}
680
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100681static uint32_t
682intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
683{
684 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
685 struct drm_device *dev = intel_dig_port->base.base.dev;
686 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200687 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100688 uint32_t status;
689 bool done;
690
Daniel Vetteref04f002012-12-01 21:03:59 +0100691#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100692 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300693 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300694 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100695 else
696 done = wait_for_atomic(C, 10) == 0;
697 if (!done)
698 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
699 has_aux_irq);
700#undef C
701
702 return status;
703}
704
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200705static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000706{
707 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200708 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000709
Ville Syrjäläa457f542016-03-02 17:22:17 +0200710 if (index)
711 return 0;
712
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000713 /*
714 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200715 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000716 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200717 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000718}
719
720static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
721{
722 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200723 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000724
725 if (index)
726 return 0;
727
Ville Syrjäläa457f542016-03-02 17:22:17 +0200728 /*
729 * The clock divider is based off the cdclk or PCH rawclk, and would
730 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
731 * divide by 2000 and use that
732 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200733 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200734 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200735 else
736 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000737}
738
739static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300740{
741 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200742 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300743
Ville Syrjäläa457f542016-03-02 17:22:17 +0200744 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300745 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100746 switch (index) {
747 case 0: return 63;
748 case 1: return 72;
749 default: return 0;
750 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300751 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200752
753 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300754}
755
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000756static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
757{
758 /*
759 * SKL doesn't need us to program the AUX clock divider (Hardware will
760 * derive the clock from CDCLK automatically). We still implement the
761 * get_aux_clock_divider vfunc to plug-in into the existing code.
762 */
763 return index ? 0 : 1;
764}
765
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200766static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
767 bool has_aux_irq,
768 int send_bytes,
769 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000770{
771 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
772 struct drm_device *dev = intel_dig_port->base.base.dev;
773 uint32_t precharge, timeout;
774
775 if (IS_GEN6(dev))
776 precharge = 3;
777 else
778 precharge = 5;
779
Ville Syrjäläf3c6a3a2015-11-11 20:34:10 +0200780 if (IS_BROADWELL(dev) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000781 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
782 else
783 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
784
785 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000786 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000787 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000788 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000789 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000790 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000791 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
792 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000793 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000794}
795
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000796static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
797 bool has_aux_irq,
798 int send_bytes,
799 uint32_t unused)
800{
801 return DP_AUX_CH_CTL_SEND_BUSY |
802 DP_AUX_CH_CTL_DONE |
803 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
804 DP_AUX_CH_CTL_TIME_OUT_ERROR |
805 DP_AUX_CH_CTL_TIME_OUT_1600us |
806 DP_AUX_CH_CTL_RECEIVE_ERROR |
807 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200808 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000809 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
810}
811
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700812static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100813intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200814 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700815 uint8_t *recv, int recv_size)
816{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200817 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
818 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700819 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200820 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100821 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100822 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700823 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000824 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100825 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200826 bool vdd;
827
Ville Syrjälä773538e82014-09-04 14:54:56 +0300828 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300829
Ville Syrjälä72c35002014-08-18 22:16:00 +0300830 /*
831 * We will be called with VDD already enabled for dpcd/edid/oui reads.
832 * In such cases we want to leave VDD enabled and it's up to upper layers
833 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
834 * ourselves.
835 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300836 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100837
838 /* dp aux is extremely sensitive to irq latency, hence request the
839 * lowest possible wakeup latency and so prevent the cpu from going into
840 * deep sleep states.
841 */
842 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700843
Keith Packard9b984da2011-09-19 13:54:47 -0700844 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800845
Jesse Barnes11bee432011-08-01 15:02:20 -0700846 /* Try to wait for any previous AUX channel activity */
847 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100848 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700849 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
850 break;
851 msleep(1);
852 }
853
854 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300855 static u32 last_status = -1;
856 const u32 status = I915_READ(ch_ctl);
857
858 if (status != last_status) {
859 WARN(1, "dp_aux_ch not started status 0x%08x\n",
860 status);
861 last_status = status;
862 }
863
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100864 ret = -EBUSY;
865 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100866 }
867
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300868 /* Only 5 data registers! */
869 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
870 ret = -E2BIG;
871 goto out;
872 }
873
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000874 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000875 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
876 has_aux_irq,
877 send_bytes,
878 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000879
Chris Wilsonbc866252013-07-21 16:00:03 +0100880 /* Must try at least 3 times according to DP spec */
881 for (try = 0; try < 5; try++) {
882 /* Load the send data into the aux channel data registers */
883 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200884 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800885 intel_dp_pack_aux(send + i,
886 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400887
Chris Wilsonbc866252013-07-21 16:00:03 +0100888 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000889 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100890
Chris Wilsonbc866252013-07-21 16:00:03 +0100891 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400892
Chris Wilsonbc866252013-07-21 16:00:03 +0100893 /* Clear done status and any errors */
894 I915_WRITE(ch_ctl,
895 status |
896 DP_AUX_CH_CTL_DONE |
897 DP_AUX_CH_CTL_TIME_OUT_ERROR |
898 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400899
Todd Previte74ebf292015-04-15 08:38:41 -0700900 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +0100901 continue;
Todd Previte74ebf292015-04-15 08:38:41 -0700902
903 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
904 * 400us delay required for errors and timeouts
905 * Timeout errors from the HW already meet this
906 * requirement so skip to next iteration
907 */
908 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
909 usleep_range(400, 500);
910 continue;
911 }
Chris Wilsonbc866252013-07-21 16:00:03 +0100912 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -0700913 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +0100914 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700915 }
916
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700917 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700918 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100919 ret = -EBUSY;
920 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700921 }
922
Jim Bridee058c942015-05-27 10:21:48 -0700923done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700924 /* Check for timeout or receive error.
925 * Timeouts occur when the sink is not connected
926 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700927 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700928 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100929 ret = -EIO;
930 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700931 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700932
933 /* Timeouts occur when the device isn't connected, so they're
934 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700935 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800936 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100937 ret = -ETIMEDOUT;
938 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700939 }
940
941 /* Unload any bytes sent back from the other side */
942 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
943 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -0800944
945 /*
946 * By BSpec: "Message sizes of 0 or >20 are not allowed."
947 * We have no idea of what happened so we return -EBUSY so
948 * drm layer takes care for the necessary retries.
949 */
950 if (recv_bytes == 0 || recv_bytes > 20) {
951 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
952 recv_bytes);
953 /*
954 * FIXME: This patch was created on top of a series that
955 * organize the retries at drm level. There EBUSY should
956 * also take care for 1ms wait before retrying.
957 * That aux retries re-org is still needed and after that is
958 * merged we remove this sleep from here.
959 */
960 usleep_range(1000, 1500);
961 ret = -EBUSY;
962 goto out;
963 }
964
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700965 if (recv_bytes > recv_size)
966 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400967
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100968 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200969 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800970 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700971
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100972 ret = recv_bytes;
973out:
974 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
975
Jani Nikula884f19e2014-03-14 16:51:14 +0200976 if (vdd)
977 edp_panel_vdd_off(intel_dp, false);
978
Ville Syrjälä773538e82014-09-04 14:54:56 +0300979 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300980
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100981 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700982}
983
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300984#define BARE_ADDRESS_SIZE 3
985#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +0200986static ssize_t
987intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700988{
Jani Nikula9d1a1032014-03-14 16:51:15 +0200989 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
990 uint8_t txbuf[20], rxbuf[20];
991 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700992 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700993
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +0200994 txbuf[0] = (msg->request << 4) |
995 ((msg->address >> 16) & 0xf);
996 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +0200997 txbuf[2] = msg->address & 0xff;
998 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300999
Jani Nikula9d1a1032014-03-14 16:51:15 +02001000 switch (msg->request & ~DP_AUX_I2C_MOT) {
1001 case DP_AUX_NATIVE_WRITE:
1002 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001003 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001004 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001005 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001006
Jani Nikula9d1a1032014-03-14 16:51:15 +02001007 if (WARN_ON(txsize > 20))
1008 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001009
Imre Deakd81a67c2016-01-29 14:52:26 +02001010 if (msg->buffer)
1011 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
1012 else
1013 WARN_ON(msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001014
Jani Nikula9d1a1032014-03-14 16:51:15 +02001015 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1016 if (ret > 0) {
1017 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001018
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001019 if (ret > 1) {
1020 /* Number of bytes written in a short write. */
1021 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1022 } else {
1023 /* Return payload size. */
1024 ret = msg->size;
1025 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001026 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001027 break;
1028
1029 case DP_AUX_NATIVE_READ:
1030 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001031 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001032 rxsize = msg->size + 1;
1033
1034 if (WARN_ON(rxsize > 20))
1035 return -E2BIG;
1036
1037 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1038 if (ret > 0) {
1039 msg->reply = rxbuf[0] >> 4;
1040 /*
1041 * Assume happy day, and copy the data. The caller is
1042 * expected to check msg->reply before touching it.
1043 *
1044 * Return payload size.
1045 */
1046 ret--;
1047 memcpy(msg->buffer, rxbuf + 1, ret);
1048 }
1049 break;
1050
1051 default:
1052 ret = -EINVAL;
1053 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001054 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001055
Jani Nikula9d1a1032014-03-14 16:51:15 +02001056 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001057}
1058
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001059static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1060 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001061{
1062 switch (port) {
1063 case PORT_B:
1064 case PORT_C:
1065 case PORT_D:
1066 return DP_AUX_CH_CTL(port);
1067 default:
1068 MISSING_CASE(port);
1069 return DP_AUX_CH_CTL(PORT_B);
1070 }
1071}
1072
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001073static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1074 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001075{
1076 switch (port) {
1077 case PORT_B:
1078 case PORT_C:
1079 case PORT_D:
1080 return DP_AUX_CH_DATA(port, index);
1081 default:
1082 MISSING_CASE(port);
1083 return DP_AUX_CH_DATA(PORT_B, index);
1084 }
1085}
1086
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001087static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1088 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001089{
1090 switch (port) {
1091 case PORT_A:
1092 return DP_AUX_CH_CTL(port);
1093 case PORT_B:
1094 case PORT_C:
1095 case PORT_D:
1096 return PCH_DP_AUX_CH_CTL(port);
1097 default:
1098 MISSING_CASE(port);
1099 return DP_AUX_CH_CTL(PORT_A);
1100 }
1101}
1102
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001103static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1104 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001105{
1106 switch (port) {
1107 case PORT_A:
1108 return DP_AUX_CH_DATA(port, index);
1109 case PORT_B:
1110 case PORT_C:
1111 case PORT_D:
1112 return PCH_DP_AUX_CH_DATA(port, index);
1113 default:
1114 MISSING_CASE(port);
1115 return DP_AUX_CH_DATA(PORT_A, index);
1116 }
1117}
1118
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001119/*
1120 * On SKL we don't have Aux for port E so we rely
1121 * on VBT to set a proper alternate aux channel.
1122 */
1123static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
1124{
1125 const struct ddi_vbt_port_info *info =
1126 &dev_priv->vbt.ddi_port_info[PORT_E];
1127
1128 switch (info->alternate_aux_channel) {
1129 case DP_AUX_A:
1130 return PORT_A;
1131 case DP_AUX_B:
1132 return PORT_B;
1133 case DP_AUX_C:
1134 return PORT_C;
1135 case DP_AUX_D:
1136 return PORT_D;
1137 default:
1138 MISSING_CASE(info->alternate_aux_channel);
1139 return PORT_A;
1140 }
1141}
1142
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001143static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1144 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001145{
1146 if (port == PORT_E)
1147 port = skl_porte_aux_port(dev_priv);
1148
1149 switch (port) {
1150 case PORT_A:
1151 case PORT_B:
1152 case PORT_C:
1153 case PORT_D:
1154 return DP_AUX_CH_CTL(port);
1155 default:
1156 MISSING_CASE(port);
1157 return DP_AUX_CH_CTL(PORT_A);
1158 }
1159}
1160
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001161static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1162 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001163{
1164 if (port == PORT_E)
1165 port = skl_porte_aux_port(dev_priv);
1166
1167 switch (port) {
1168 case PORT_A:
1169 case PORT_B:
1170 case PORT_C:
1171 case PORT_D:
1172 return DP_AUX_CH_DATA(port, index);
1173 default:
1174 MISSING_CASE(port);
1175 return DP_AUX_CH_DATA(PORT_A, index);
1176 }
1177}
1178
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001179static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1180 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001181{
1182 if (INTEL_INFO(dev_priv)->gen >= 9)
1183 return skl_aux_ctl_reg(dev_priv, port);
1184 else if (HAS_PCH_SPLIT(dev_priv))
1185 return ilk_aux_ctl_reg(dev_priv, port);
1186 else
1187 return g4x_aux_ctl_reg(dev_priv, port);
1188}
1189
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001190static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1191 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001192{
1193 if (INTEL_INFO(dev_priv)->gen >= 9)
1194 return skl_aux_data_reg(dev_priv, port, index);
1195 else if (HAS_PCH_SPLIT(dev_priv))
1196 return ilk_aux_data_reg(dev_priv, port, index);
1197 else
1198 return g4x_aux_data_reg(dev_priv, port, index);
1199}
1200
1201static void intel_aux_reg_init(struct intel_dp *intel_dp)
1202{
1203 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1204 enum port port = dp_to_dig_port(intel_dp)->port;
1205 int i;
1206
1207 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1208 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1209 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1210}
1211
Jani Nikula9d1a1032014-03-14 16:51:15 +02001212static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001213intel_dp_aux_fini(struct intel_dp *intel_dp)
1214{
1215 drm_dp_aux_unregister(&intel_dp->aux);
1216 kfree(intel_dp->aux.name);
1217}
1218
1219static int
Jani Nikula9d1a1032014-03-14 16:51:15 +02001220intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001221{
Jani Nikula33ad6622014-03-14 16:51:16 +02001222 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1223 enum port port = intel_dig_port->port;
Dave Airlieab2c0672009-12-04 10:55:24 +10001224 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001225
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001226 intel_aux_reg_init(intel_dp);
David Flynn8316f332010-12-08 16:10:21 +00001227
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001228 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
1229 if (!intel_dp->aux.name)
1230 return -ENOMEM;
1231
Rafael Antognolli4d32c0d2016-01-21 15:10:20 -08001232 intel_dp->aux.dev = connector->base.kdev;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001233 intel_dp->aux.transfer = intel_dp_aux_transfer;
David Flynn8316f332010-12-08 16:10:21 +00001234
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001235 DRM_DEBUG_KMS("registering %s bus for %s\n",
1236 intel_dp->aux.name,
Jani Nikula0b998362014-03-14 16:51:17 +02001237 connector->base.kdev->kobj.name);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001238
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001239 ret = drm_dp_aux_register(&intel_dp->aux);
Jani Nikula0b998362014-03-14 16:51:17 +02001240 if (ret < 0) {
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001241 DRM_ERROR("drm_dp_aux_register() for %s failed (%d)\n",
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001242 intel_dp->aux.name, ret);
1243 kfree(intel_dp->aux.name);
1244 return ret;
Dave Airlieab2c0672009-12-04 10:55:24 +10001245 }
David Flynn8316f332010-12-08 16:10:21 +00001246
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001247 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001248}
1249
Imre Deak80f65de2014-02-11 17:12:49 +02001250static void
1251intel_dp_connector_unregister(struct intel_connector *intel_connector)
1252{
1253 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
1254
Rafael Antognolli4d32c0d2016-01-21 15:10:20 -08001255 intel_dp_aux_fini(intel_dp);
Imre Deak80f65de2014-02-11 17:12:49 +02001256 intel_connector_unregister(intel_connector);
1257}
1258
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301259static int
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001260intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301261{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001262 if (intel_dp->num_sink_rates) {
1263 *sink_rates = intel_dp->sink_rates;
1264 return intel_dp->num_sink_rates;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301265 }
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001266
1267 *sink_rates = default_rates;
1268
1269 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301270}
1271
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001272bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301273{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001274 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1275 struct drm_device *dev = dig_port->base.base.dev;
1276
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301277 /* WaDisableHBR2:skl */
Jani Nikulae87a0052015-10-20 15:22:02 +03001278 if (IS_SKL_REVID(dev, 0, SKL_REVID_B0))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301279 return false;
1280
1281 if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) ||
1282 (INTEL_INFO(dev)->gen >= 9))
1283 return true;
1284 else
1285 return false;
1286}
1287
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301288static int
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001289intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301290{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001291 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1292 struct drm_device *dev = dig_port->base.base.dev;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301293 int size;
1294
Sonika Jindal64987fc2015-05-26 17:50:13 +05301295 if (IS_BROXTON(dev)) {
1296 *source_rates = bxt_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301297 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001298 } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Sonika Jindal637a9c62015-05-07 09:52:08 +05301299 *source_rates = skl_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301300 size = ARRAY_SIZE(skl_rates);
1301 } else {
1302 *source_rates = default_rates;
1303 size = ARRAY_SIZE(default_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301304 }
Ville Syrjälä636280b2015-03-12 17:10:29 +02001305
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301306 /* This depends on the fact that 5.4 is last value in the array */
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001307 if (!intel_dp_source_supports_hbr2(intel_dp))
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301308 size--;
Ville Syrjälä636280b2015-03-12 17:10:29 +02001309
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301310 return size;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301311}
1312
Daniel Vetter0e503382014-07-04 11:26:04 -03001313static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001314intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001315 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001316{
1317 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001318 const struct dp_link_dpll *divisor = NULL;
1319 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001320
1321 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001322 divisor = gen4_dpll;
1323 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001324 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001325 divisor = pch_dpll;
1326 count = ARRAY_SIZE(pch_dpll);
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001327 } else if (IS_CHERRYVIEW(dev)) {
1328 divisor = chv_dpll;
1329 count = ARRAY_SIZE(chv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001330 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001331 divisor = vlv_dpll;
1332 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001333 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001334
1335 if (divisor && count) {
1336 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001337 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001338 pipe_config->dpll = divisor[i].dpll;
1339 pipe_config->clock_set = true;
1340 break;
1341 }
1342 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001343 }
1344}
1345
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001346static int intersect_rates(const int *source_rates, int source_len,
1347 const int *sink_rates, int sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001348 int *common_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301349{
1350 int i = 0, j = 0, k = 0;
1351
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301352 while (i < source_len && j < sink_len) {
1353 if (source_rates[i] == sink_rates[j]) {
Ville Syrjäläe6bda3e2015-03-12 17:10:37 +02001354 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
1355 return k;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001356 common_rates[k] = source_rates[i];
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301357 ++k;
1358 ++i;
1359 ++j;
1360 } else if (source_rates[i] < sink_rates[j]) {
1361 ++i;
1362 } else {
1363 ++j;
1364 }
1365 }
1366 return k;
1367}
1368
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001369static int intel_dp_common_rates(struct intel_dp *intel_dp,
1370 int *common_rates)
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001371{
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001372 const int *source_rates, *sink_rates;
1373 int source_len, sink_len;
1374
1375 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001376 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001377
1378 return intersect_rates(source_rates, source_len,
1379 sink_rates, sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001380 common_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001381}
1382
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001383static void snprintf_int_array(char *str, size_t len,
1384 const int *array, int nelem)
1385{
1386 int i;
1387
1388 str[0] = '\0';
1389
1390 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001391 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001392 if (r >= len)
1393 return;
1394 str += r;
1395 len -= r;
1396 }
1397}
1398
1399static void intel_dp_print_rates(struct intel_dp *intel_dp)
1400{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001401 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001402 int source_len, sink_len, common_len;
1403 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001404 char str[128]; /* FIXME: too big for stack? */
1405
1406 if ((drm_debug & DRM_UT_KMS) == 0)
1407 return;
1408
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001409 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001410 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1411 DRM_DEBUG_KMS("source rates: %s\n", str);
1412
1413 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1414 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1415 DRM_DEBUG_KMS("sink rates: %s\n", str);
1416
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001417 common_len = intel_dp_common_rates(intel_dp, common_rates);
1418 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1419 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001420}
1421
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001422static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301423{
1424 int i = 0;
1425
1426 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1427 if (find == rates[i])
1428 break;
1429
1430 return i;
1431}
1432
Ville Syrjälä50fec212015-03-12 17:10:34 +02001433int
1434intel_dp_max_link_rate(struct intel_dp *intel_dp)
1435{
1436 int rates[DP_MAX_SUPPORTED_RATES] = {};
1437 int len;
1438
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001439 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001440 if (WARN_ON(len <= 0))
1441 return 162000;
1442
1443 return rates[rate_to_index(0, rates) - 1];
1444}
1445
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001446int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1447{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001448 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001449}
1450
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001451void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1452 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001453{
1454 if (intel_dp->num_sink_rates) {
1455 *link_bw = 0;
1456 *rate_select =
1457 intel_dp_rate_select(intel_dp, port_clock);
1458 } else {
1459 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1460 *rate_select = 0;
1461 }
1462}
1463
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001464bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001465intel_dp_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001466 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001467{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001468 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +01001469 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001470 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001471 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001472 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001473 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001474 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001475 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001476 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001477 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001478 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001479 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301480 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001481 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001482 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001483 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1484 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001485 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301486
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001487 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301488
1489 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001490 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301491
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001492 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001493
Imre Deakbc7d38a2013-05-16 14:40:36 +03001494 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001495 pipe_config->has_pch_encoder = true;
1496
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001497 pipe_config->has_dp_encoder = true;
Vandana Kannanf769cd22014-08-05 07:51:22 -07001498 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001499 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001500
Jani Nikuladd06f902012-10-19 14:51:50 +03001501 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1502 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1503 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001504
1505 if (INTEL_INFO(dev)->gen >= 9) {
1506 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001507 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001508 if (ret)
1509 return ret;
1510 }
1511
Matt Roperb56676272015-11-04 09:05:27 -08001512 if (HAS_GMCH_DISPLAY(dev))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001513 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1514 intel_connector->panel.fitting_mode);
1515 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001516 intel_pch_panel_fitting(intel_crtc, pipe_config,
1517 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001518 }
1519
Daniel Vettercb1793c2012-06-04 18:39:21 +02001520 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001521 return false;
1522
Daniel Vetter083f9562012-04-20 20:23:49 +02001523 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301524 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001525 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001526 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001527
Daniel Vetter36008362013-03-27 00:44:59 +01001528 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1529 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +02001530 bpp = pipe_config->pipe_bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001531 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301532
1533 /* Get bpp from vbt only for panels that dont have bpp in edid */
1534 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001535 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001536 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001537 dev_priv->vbt.edp.bpp);
1538 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001539 }
1540
Jani Nikula344c5bb2014-09-09 11:25:13 +03001541 /*
1542 * Use the maximum clock and number of lanes the eDP panel
1543 * advertizes being capable of. The panels are generally
1544 * designed to support only a single clock and lane
1545 * configuration, and typically these values correspond to the
1546 * native resolution of the panel.
1547 */
1548 min_lane_count = max_lane_count;
1549 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001550 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001551
Daniel Vetter36008362013-03-27 00:44:59 +01001552 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001553 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1554 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001555
Dave Airliec6930992014-07-14 11:04:39 +10001556 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301557 for (lane_count = min_lane_count;
1558 lane_count <= max_lane_count;
1559 lane_count <<= 1) {
1560
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001561 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001562 link_avail = intel_dp_max_data_rate(link_clock,
1563 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001564
Daniel Vetter36008362013-03-27 00:44:59 +01001565 if (mode_rate <= link_avail) {
1566 goto found;
1567 }
1568 }
1569 }
1570 }
1571
1572 return false;
1573
1574found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001575 if (intel_dp->color_range_auto) {
1576 /*
1577 * See:
1578 * CEA-861-E - 5.1 Default Encoding Parameters
1579 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1580 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001581 pipe_config->limited_color_range =
1582 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1583 } else {
1584 pipe_config->limited_color_range =
1585 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001586 }
1587
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001588 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301589
Daniel Vetter657445f2013-05-04 10:09:18 +02001590 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001591 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001592
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001593 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1594 &link_bw, &rate_select);
1595
1596 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1597 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001598 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001599 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1600 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001601
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001602 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001603 adjusted_mode->crtc_clock,
1604 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001605 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001606
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301607 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301608 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001609 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301610 intel_link_compute_m_n(bpp, lane_count,
1611 intel_connector->panel.downclock_mode->clock,
1612 pipe_config->port_clock,
1613 &pipe_config->dp_m2_n2);
1614 }
1615
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001616 /*
1617 * DPLL0 VCO may need to be adjusted to get the correct
1618 * clock for eDP. This will affect cdclk as well.
1619 */
1620 if (is_edp(intel_dp) &&
1621 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1622 int vco;
1623
1624 switch (pipe_config->port_clock / 2) {
1625 case 108000:
1626 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001627 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001628 break;
1629 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001630 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001631 break;
1632 }
1633
1634 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1635 }
1636
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02001637 if (!HAS_DDI(dev))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001638 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001639
Daniel Vetter36008362013-03-27 00:44:59 +01001640 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001641}
1642
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001643void intel_dp_set_link_params(struct intel_dp *intel_dp,
1644 const struct intel_crtc_state *pipe_config)
1645{
1646 intel_dp->link_rate = pipe_config->port_clock;
1647 intel_dp->lane_count = pipe_config->lane_count;
1648}
1649
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02001650static void intel_dp_prepare(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001651{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001652 struct drm_device *dev = encoder->base.dev;
Keith Packard417e8222011-11-01 19:54:11 -07001653 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001654 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001655 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001656 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03001657 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001658
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001659 intel_dp_set_link_params(intel_dp, crtc->config);
1660
Keith Packard417e8222011-11-01 19:54:11 -07001661 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001662 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001663 *
1664 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001665 * SNB CPU
1666 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001667 * CPT PCH
1668 *
1669 * IBX PCH and CPU are the same for almost everything,
1670 * except that the CPU DP PLL is configured in this
1671 * register
1672 *
1673 * CPT PCH is quite different, having many bits moved
1674 * to the TRANS_DP_CTL register instead. That
1675 * configuration happens (oddly) in ironlake_pch_enable
1676 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001677
Keith Packard417e8222011-11-01 19:54:11 -07001678 /* Preserve the BIOS-computed detected bit. This is
1679 * supposed to be read-only.
1680 */
1681 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001682
Keith Packard417e8222011-11-01 19:54:11 -07001683 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001684 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001685 intel_dp->DP |= DP_PORT_WIDTH(crtc->config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001686
Keith Packard417e8222011-11-01 19:54:11 -07001687 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001688
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001689 if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001690 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1691 intel_dp->DP |= DP_SYNC_HS_HIGH;
1692 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1693 intel_dp->DP |= DP_SYNC_VS_HIGH;
1694 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1695
Jani Nikula6aba5b62013-10-04 15:08:10 +03001696 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001697 intel_dp->DP |= DP_ENHANCED_FRAMING;
1698
Daniel Vetter7c62a162013-06-01 17:16:20 +02001699 intel_dp->DP |= crtc->pipe << 29;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001700 } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001701 u32 trans_dp;
1702
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001703 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001704
1705 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1706 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1707 trans_dp |= TRANS_DP_ENH_FRAMING;
1708 else
1709 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1710 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001711 } else {
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001712 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08001713 !IS_CHERRYVIEW(dev) && crtc->config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001714 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001715
1716 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1717 intel_dp->DP |= DP_SYNC_HS_HIGH;
1718 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1719 intel_dp->DP |= DP_SYNC_VS_HIGH;
1720 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1721
Jani Nikula6aba5b62013-10-04 15:08:10 +03001722 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001723 intel_dp->DP |= DP_ENHANCED_FRAMING;
1724
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001725 if (IS_CHERRYVIEW(dev))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001726 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001727 else if (crtc->pipe == PIPE_B)
1728 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001729 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001730}
1731
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001732#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1733#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001734
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001735#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1736#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001737
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001738#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1739#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001740
Daniel Vetter4be73782014-01-17 14:39:48 +01001741static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001742 u32 mask,
1743 u32 value)
1744{
Paulo Zanoni30add222012-10-26 19:05:45 -02001745 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001746 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001747 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001748
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001749 lockdep_assert_held(&dev_priv->pps_mutex);
1750
Jani Nikulabf13e812013-09-06 07:40:05 +03001751 pp_stat_reg = _pp_stat_reg(intel_dp);
1752 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001753
1754 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001755 mask, value,
1756 I915_READ(pp_stat_reg),
1757 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001758
Tvrtko Ursulin3f177622016-03-03 14:36:41 +00001759 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value,
1760 5 * USEC_PER_SEC, 10 * USEC_PER_MSEC))
Keith Packard99ea7122011-11-01 19:57:50 -07001761 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001762 I915_READ(pp_stat_reg),
1763 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001764
1765 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001766}
1767
Daniel Vetter4be73782014-01-17 14:39:48 +01001768static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001769{
1770 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001771 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001772}
1773
Daniel Vetter4be73782014-01-17 14:39:48 +01001774static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001775{
Keith Packardbd943152011-09-18 23:09:52 -07001776 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001777 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001778}
Keith Packardbd943152011-09-18 23:09:52 -07001779
Daniel Vetter4be73782014-01-17 14:39:48 +01001780static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001781{
Abhay Kumard28d4732016-01-22 17:39:04 -08001782 ktime_t panel_power_on_time;
1783 s64 panel_power_off_duration;
1784
Keith Packard99ea7122011-11-01 19:57:50 -07001785 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001786
Abhay Kumard28d4732016-01-22 17:39:04 -08001787 /* take the difference of currrent time and panel power off time
1788 * and then make panel wait for t11_t12 if needed. */
1789 panel_power_on_time = ktime_get_boottime();
1790 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1791
Paulo Zanonidce56b32013-12-19 14:29:40 -02001792 /* When we disable the VDD override bit last we have to do the manual
1793 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001794 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1795 wait_remaining_ms_from_jiffies(jiffies,
1796 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001797
Daniel Vetter4be73782014-01-17 14:39:48 +01001798 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001799}
Keith Packardbd943152011-09-18 23:09:52 -07001800
Daniel Vetter4be73782014-01-17 14:39:48 +01001801static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001802{
1803 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1804 intel_dp->backlight_on_delay);
1805}
1806
Daniel Vetter4be73782014-01-17 14:39:48 +01001807static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001808{
1809 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1810 intel_dp->backlight_off_delay);
1811}
Keith Packard99ea7122011-11-01 19:57:50 -07001812
Keith Packard832dd3c2011-11-01 19:34:06 -07001813/* Read the current pp_control value, unlocking the register if it
1814 * is locked
1815 */
1816
Jesse Barnes453c5422013-03-28 09:55:41 -07001817static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001818{
Jesse Barnes453c5422013-03-28 09:55:41 -07001819 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1820 struct drm_i915_private *dev_priv = dev->dev_private;
1821 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001822
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001823 lockdep_assert_held(&dev_priv->pps_mutex);
1824
Jani Nikulabf13e812013-09-06 07:40:05 +03001825 control = I915_READ(_pp_ctrl_reg(intel_dp));
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301826 if (!IS_BROXTON(dev)) {
1827 control &= ~PANEL_UNLOCK_MASK;
1828 control |= PANEL_UNLOCK_REGS;
1829 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001830 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001831}
1832
Ville Syrjälä951468f2014-09-04 14:55:31 +03001833/*
1834 * Must be paired with edp_panel_vdd_off().
1835 * Must hold pps_mutex around the whole on/off sequence.
1836 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1837 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001838static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001839{
Paulo Zanoni30add222012-10-26 19:05:45 -02001840 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001841 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1842 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Jesse Barnes5d613502011-01-24 17:10:54 -08001843 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak4e6e1a52014-03-27 17:45:11 +02001844 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001845 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001846 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001847 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001848
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001849 lockdep_assert_held(&dev_priv->pps_mutex);
1850
Keith Packard97af61f572011-09-28 16:23:51 -07001851 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001852 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001853
Egbert Eich2c623c12014-11-25 12:54:57 +01001854 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001855 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001856
Daniel Vetter4be73782014-01-17 14:39:48 +01001857 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001858 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001859
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001860 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001861 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001862
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001863 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1864 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001865
Daniel Vetter4be73782014-01-17 14:39:48 +01001866 if (!edp_have_panel_power(intel_dp))
1867 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001868
Jesse Barnes453c5422013-03-28 09:55:41 -07001869 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001870 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001871
Jani Nikulabf13e812013-09-06 07:40:05 +03001872 pp_stat_reg = _pp_stat_reg(intel_dp);
1873 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001874
1875 I915_WRITE(pp_ctrl_reg, pp);
1876 POSTING_READ(pp_ctrl_reg);
1877 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1878 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001879 /*
1880 * If the panel wasn't on, delay before accessing aux channel
1881 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001882 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001883 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1884 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001885 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001886 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001887
1888 return need_to_disable;
1889}
1890
Ville Syrjälä951468f2014-09-04 14:55:31 +03001891/*
1892 * Must be paired with intel_edp_panel_vdd_off() or
1893 * intel_edp_panel_off().
1894 * Nested calls to these functions are not allowed since
1895 * we drop the lock. Caller must use some higher level
1896 * locking to prevent nested calls from other threads.
1897 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001898void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001899{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001900 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001901
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001902 if (!is_edp(intel_dp))
1903 return;
1904
Ville Syrjälä773538e82014-09-04 14:54:56 +03001905 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001906 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001907 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001908
Rob Clarke2c719b2014-12-15 13:56:32 -05001909 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001910 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08001911}
1912
Daniel Vetter4be73782014-01-17 14:39:48 +01001913static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001914{
Paulo Zanoni30add222012-10-26 19:05:45 -02001915 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001916 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001917 struct intel_digital_port *intel_dig_port =
1918 dp_to_dig_port(intel_dp);
1919 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1920 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001921 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001922 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001923
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001924 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01001925
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001926 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001927
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001928 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001929 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001930
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001931 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
1932 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07001933
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001934 pp = ironlake_get_pp_control(intel_dp);
1935 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07001936
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001937 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1938 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001939
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001940 I915_WRITE(pp_ctrl_reg, pp);
1941 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02001942
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001943 /* Make sure sequencer is idle before allowing subsequent activity */
1944 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1945 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001946
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001947 if ((pp & POWER_TARGET_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08001948 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001949
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001950 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001951 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07001952}
1953
Daniel Vetter4be73782014-01-17 14:39:48 +01001954static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07001955{
1956 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1957 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001958
Ville Syrjälä773538e82014-09-04 14:54:56 +03001959 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001960 if (!intel_dp->want_panel_vdd)
1961 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001962 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001963}
1964
Imre Deakaba86892014-07-30 15:57:31 +03001965static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
1966{
1967 unsigned long delay;
1968
1969 /*
1970 * Queue the timer to fire a long time from now (relative to the power
1971 * down delay) to keep the panel power up across a sequence of
1972 * operations.
1973 */
1974 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
1975 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
1976}
1977
Ville Syrjälä951468f2014-09-04 14:55:31 +03001978/*
1979 * Must be paired with edp_panel_vdd_on().
1980 * Must hold pps_mutex around the whole on/off sequence.
1981 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1982 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001983static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001984{
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001985 struct drm_i915_private *dev_priv =
1986 intel_dp_to_dev(intel_dp)->dev_private;
1987
1988 lockdep_assert_held(&dev_priv->pps_mutex);
1989
Keith Packard97af61f572011-09-28 16:23:51 -07001990 if (!is_edp(intel_dp))
1991 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001992
Rob Clarke2c719b2014-12-15 13:56:32 -05001993 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001994 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07001995
Keith Packardbd943152011-09-18 23:09:52 -07001996 intel_dp->want_panel_vdd = false;
1997
Imre Deakaba86892014-07-30 15:57:31 +03001998 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01001999 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002000 else
2001 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002002}
2003
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002004static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002005{
Paulo Zanoni30add222012-10-26 19:05:45 -02002006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002007 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07002008 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002009 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002010
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002011 lockdep_assert_held(&dev_priv->pps_mutex);
2012
Keith Packard97af61f572011-09-28 16:23:51 -07002013 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002014 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002015
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002016 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2017 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002018
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002019 if (WARN(edp_have_panel_power(intel_dp),
2020 "eDP port %c panel power already on\n",
2021 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002022 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002023
Daniel Vetter4be73782014-01-17 14:39:48 +01002024 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002025
Jani Nikulabf13e812013-09-06 07:40:05 +03002026 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002027 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07002028 if (IS_GEN5(dev)) {
2029 /* ILK workaround: disable reset around power sequence */
2030 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002031 I915_WRITE(pp_ctrl_reg, pp);
2032 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002033 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002034
Keith Packard1c0ae802011-09-19 13:59:29 -07002035 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07002036 if (!IS_GEN5(dev))
2037 pp |= PANEL_POWER_RESET;
2038
Jesse Barnes453c5422013-03-28 09:55:41 -07002039 I915_WRITE(pp_ctrl_reg, pp);
2040 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002041
Daniel Vetter4be73782014-01-17 14:39:48 +01002042 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002043 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002044
Keith Packard05ce1a42011-09-29 16:33:01 -07002045 if (IS_GEN5(dev)) {
2046 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002047 I915_WRITE(pp_ctrl_reg, pp);
2048 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002049 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002050}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002051
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002052void intel_edp_panel_on(struct intel_dp *intel_dp)
2053{
2054 if (!is_edp(intel_dp))
2055 return;
2056
2057 pps_lock(intel_dp);
2058 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002059 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002060}
2061
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002062
2063static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002064{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002065 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2066 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002067 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002068 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak4e6e1a52014-03-27 17:45:11 +02002069 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002070 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002071 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002072
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002073 lockdep_assert_held(&dev_priv->pps_mutex);
2074
Keith Packard97af61f572011-09-28 16:23:51 -07002075 if (!is_edp(intel_dp))
2076 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002077
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002078 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2079 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002080
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002081 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2082 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002083
Jesse Barnes453c5422013-03-28 09:55:41 -07002084 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002085 /* We need to switch off panel power _and_ force vdd, for otherwise some
2086 * panels get very unhappy and cease to work. */
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002087 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
2088 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002089
Jani Nikulabf13e812013-09-06 07:40:05 +03002090 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002091
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002092 intel_dp->want_panel_vdd = false;
2093
Jesse Barnes453c5422013-03-28 09:55:41 -07002094 I915_WRITE(pp_ctrl_reg, pp);
2095 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002096
Abhay Kumard28d4732016-01-22 17:39:04 -08002097 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002098 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002099
2100 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002101 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002102 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002103}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002104
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002105void intel_edp_panel_off(struct intel_dp *intel_dp)
2106{
2107 if (!is_edp(intel_dp))
2108 return;
2109
2110 pps_lock(intel_dp);
2111 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002112 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002113}
2114
Jani Nikula1250d102014-08-12 17:11:39 +03002115/* Enable backlight in the panel power control. */
2116static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002117{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002118 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2119 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002120 struct drm_i915_private *dev_priv = dev->dev_private;
2121 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002122 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002123
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002124 /*
2125 * If we enable the backlight right away following a panel power
2126 * on, we may see slight flicker as the panel syncs with the eDP
2127 * link. So delay a bit to make sure the image is solid before
2128 * allowing it to appear.
2129 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002130 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002131
Ville Syrjälä773538e82014-09-04 14:54:56 +03002132 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002133
Jesse Barnes453c5422013-03-28 09:55:41 -07002134 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002135 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002136
Jani Nikulabf13e812013-09-06 07:40:05 +03002137 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002138
2139 I915_WRITE(pp_ctrl_reg, pp);
2140 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002141
Ville Syrjälä773538e82014-09-04 14:54:56 +03002142 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002143}
2144
Jani Nikula1250d102014-08-12 17:11:39 +03002145/* Enable backlight PWM and backlight PP control. */
2146void intel_edp_backlight_on(struct intel_dp *intel_dp)
2147{
2148 if (!is_edp(intel_dp))
2149 return;
2150
2151 DRM_DEBUG_KMS("\n");
2152
2153 intel_panel_enable_backlight(intel_dp->attached_connector);
2154 _intel_edp_backlight_on(intel_dp);
2155}
2156
2157/* Disable backlight in the panel power control. */
2158static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002159{
Paulo Zanoni30add222012-10-26 19:05:45 -02002160 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002161 struct drm_i915_private *dev_priv = dev->dev_private;
2162 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002163 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002164
Keith Packardf01eca22011-09-28 16:48:10 -07002165 if (!is_edp(intel_dp))
2166 return;
2167
Ville Syrjälä773538e82014-09-04 14:54:56 +03002168 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002169
Jesse Barnes453c5422013-03-28 09:55:41 -07002170 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002171 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002172
Jani Nikulabf13e812013-09-06 07:40:05 +03002173 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002174
2175 I915_WRITE(pp_ctrl_reg, pp);
2176 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002177
Ville Syrjälä773538e82014-09-04 14:54:56 +03002178 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002179
Paulo Zanonidce56b32013-12-19 14:29:40 -02002180 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002181 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002182}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002183
Jani Nikula1250d102014-08-12 17:11:39 +03002184/* Disable backlight PP control and backlight PWM. */
2185void intel_edp_backlight_off(struct intel_dp *intel_dp)
2186{
2187 if (!is_edp(intel_dp))
2188 return;
2189
2190 DRM_DEBUG_KMS("\n");
2191
2192 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002193 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002194}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002195
Jani Nikula73580fb72014-08-12 17:11:41 +03002196/*
2197 * Hook for controlling the panel power control backlight through the bl_power
2198 * sysfs attribute. Take care to handle multiple calls.
2199 */
2200static void intel_edp_backlight_power(struct intel_connector *connector,
2201 bool enable)
2202{
2203 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002204 bool is_enabled;
2205
Ville Syrjälä773538e82014-09-04 14:54:56 +03002206 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002207 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002208 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002209
2210 if (is_enabled == enable)
2211 return;
2212
Jani Nikula23ba9372014-08-27 14:08:43 +03002213 DRM_DEBUG_KMS("panel power control backlight %s\n",
2214 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002215
2216 if (enable)
2217 _intel_edp_backlight_on(intel_dp);
2218 else
2219 _intel_edp_backlight_off(intel_dp);
2220}
2221
Ville Syrjälä64e10772015-10-29 21:26:01 +02002222static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2223{
2224 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2225 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2226 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2227
2228 I915_STATE_WARN(cur_state != state,
2229 "DP port %c state assertion failure (expected %s, current %s)\n",
2230 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002231 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002232}
2233#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2234
2235static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2236{
2237 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2238
2239 I915_STATE_WARN(cur_state != state,
2240 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002241 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002242}
2243#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2244#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2245
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002246static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002247{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002248 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002249 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2250 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002251
Ville Syrjälä64e10772015-10-29 21:26:01 +02002252 assert_pipe_disabled(dev_priv, crtc->pipe);
2253 assert_dp_port_disabled(intel_dp);
2254 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002255
Ville Syrjäläabfce942015-10-29 21:26:03 +02002256 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
2257 crtc->config->port_clock);
2258
2259 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2260
2261 if (crtc->config->port_clock == 162000)
2262 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2263 else
2264 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2265
2266 I915_WRITE(DP_A, intel_dp->DP);
2267 POSTING_READ(DP_A);
2268 udelay(500);
2269
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002270 /*
2271 * [DevILK] Work around required when enabling DP PLL
2272 * while a pipe is enabled going to FDI:
2273 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2274 * 2. Program DP PLL enable
2275 */
2276 if (IS_GEN5(dev_priv))
2277 intel_wait_for_vblank_if_active(dev_priv->dev, !crtc->pipe);
2278
Daniel Vetter07679352012-09-06 22:15:42 +02002279 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002280
Daniel Vetter07679352012-09-06 22:15:42 +02002281 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002282 POSTING_READ(DP_A);
2283 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002284}
2285
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002286static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002287{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002288 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002289 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2290 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002291
Ville Syrjälä64e10772015-10-29 21:26:01 +02002292 assert_pipe_disabled(dev_priv, crtc->pipe);
2293 assert_dp_port_disabled(intel_dp);
2294 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002295
Ville Syrjäläabfce942015-10-29 21:26:03 +02002296 DRM_DEBUG_KMS("disabling eDP PLL\n");
2297
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002298 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002299
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002300 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002301 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002302 udelay(200);
2303}
2304
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002305/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002306void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002307{
2308 int ret, i;
2309
2310 /* Should have a valid DPCD by this point */
2311 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2312 return;
2313
2314 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002315 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2316 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002317 } else {
2318 /*
2319 * When turning on, we need to retry for 1ms to give the sink
2320 * time to wake up.
2321 */
2322 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002323 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2324 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002325 if (ret == 1)
2326 break;
2327 msleep(1);
2328 }
2329 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002330
2331 if (ret != 1)
2332 DRM_DEBUG_KMS("failed to %s sink power state\n",
2333 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002334}
2335
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002336static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2337 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002338{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002339 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002340 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002341 struct drm_device *dev = encoder->base.dev;
2342 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +02002343 enum intel_display_power_domain power_domain;
2344 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002345 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002346
2347 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002348 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002349 return false;
2350
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002351 ret = false;
2352
Imre Deak6d129be2014-03-05 16:20:54 +02002353 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002354
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002355 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002356 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002357
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002358 if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002359 *pipe = PORT_TO_PIPE_CPT(tmp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002360 } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002361 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002362
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002363 for_each_pipe(dev_priv, p) {
2364 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2365 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2366 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002367 ret = true;
2368
2369 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002370 }
2371 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002372
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002373 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002374 i915_mmio_reg_offset(intel_dp->output_reg));
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002375 } else if (IS_CHERRYVIEW(dev)) {
2376 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2377 } else {
2378 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002379 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002380
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002381 ret = true;
2382
2383out:
2384 intel_display_power_put(dev_priv, power_domain);
2385
2386 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002387}
2388
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002389static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002390 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002391{
2392 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002393 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002394 struct drm_device *dev = encoder->base.dev;
2395 struct drm_i915_private *dev_priv = dev->dev_private;
2396 enum port port = dp_to_dig_port(intel_dp)->port;
2397 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002398
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002399 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002400
2401 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002402
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002403 if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002404 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2405
2406 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002407 flags |= DRM_MODE_FLAG_PHSYNC;
2408 else
2409 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002410
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002411 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002412 flags |= DRM_MODE_FLAG_PVSYNC;
2413 else
2414 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002415 } else {
2416 if (tmp & DP_SYNC_HS_HIGH)
2417 flags |= DRM_MODE_FLAG_PHSYNC;
2418 else
2419 flags |= DRM_MODE_FLAG_NHSYNC;
2420
2421 if (tmp & DP_SYNC_VS_HIGH)
2422 flags |= DRM_MODE_FLAG_PVSYNC;
2423 else
2424 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002425 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002426
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002427 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002428
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002429 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08002430 !IS_CHERRYVIEW(dev) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002431 pipe_config->limited_color_range = true;
2432
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002433 pipe_config->has_dp_encoder = true;
2434
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002435 pipe_config->lane_count =
2436 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2437
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002438 intel_dp_get_m_n(crtc, pipe_config);
2439
Ville Syrjälä18442d02013-09-13 16:00:08 +03002440 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002441 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002442 pipe_config->port_clock = 162000;
2443 else
2444 pipe_config->port_clock = 270000;
2445 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002446
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002447 pipe_config->base.adjusted_mode.crtc_clock =
2448 intel_dotclock_calculate(pipe_config->port_clock,
2449 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002450
Jani Nikula6aa23e62016-03-24 17:50:20 +02002451 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2452 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002453 /*
2454 * This is a big fat ugly hack.
2455 *
2456 * Some machines in UEFI boot mode provide us a VBT that has 18
2457 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2458 * unknown we fail to light up. Yet the same BIOS boots up with
2459 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2460 * max, not what it tells us to use.
2461 *
2462 * Note: This will still be broken if the eDP panel is not lit
2463 * up by the BIOS, and thus we can't get the mode at module
2464 * load.
2465 */
2466 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002467 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2468 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002469 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002470}
2471
Daniel Vettere8cb4552012-07-01 13:05:48 +02002472static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002473{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002474 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002475 struct drm_device *dev = encoder->base.dev;
Jani Nikula495a5bb2014-10-27 16:26:55 +02002476 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
2477
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002478 if (crtc->config->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002479 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002480
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002481 if (HAS_PSR(dev) && !HAS_DDI(dev))
2482 intel_psr_disable(intel_dp);
2483
Daniel Vetter6cb49832012-05-20 17:14:50 +02002484 /* Make sure the panel is off before trying to change the mode. But also
2485 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002486 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002487 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002488 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002489 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002490
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002491 /* disable the port before the pipe on g4x */
2492 if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002493 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002494}
2495
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002496static void ilk_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002497{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002498 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002499 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002500
Ville Syrjälä49277c32014-03-31 18:21:26 +03002501 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002502
2503 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002504 if (port == PORT_A)
2505 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002506}
2507
2508static void vlv_post_disable_dp(struct intel_encoder *encoder)
2509{
2510 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2511
2512 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002513}
2514
Ville Syrjälä580d3812014-04-09 13:29:00 +03002515static void chv_post_disable_dp(struct intel_encoder *encoder)
2516{
2517 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002518 struct drm_device *dev = encoder->base.dev;
2519 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä580d3812014-04-09 13:29:00 +03002520
2521 intel_dp_link_down(intel_dp);
2522
Ville Syrjäläa5805162015-05-26 20:42:30 +03002523 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002524
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002525 /* Assert data lane reset */
2526 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002527
Ville Syrjäläa5805162015-05-26 20:42:30 +03002528 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002529}
2530
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002531static void
2532_intel_dp_set_link_train(struct intel_dp *intel_dp,
2533 uint32_t *DP,
2534 uint8_t dp_train_pat)
2535{
2536 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2537 struct drm_device *dev = intel_dig_port->base.base.dev;
2538 struct drm_i915_private *dev_priv = dev->dev_private;
2539 enum port port = intel_dig_port->port;
2540
2541 if (HAS_DDI(dev)) {
2542 uint32_t temp = I915_READ(DP_TP_CTL(port));
2543
2544 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2545 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2546 else
2547 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2548
2549 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2550 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2551 case DP_TRAINING_PATTERN_DISABLE:
2552 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2553
2554 break;
2555 case DP_TRAINING_PATTERN_1:
2556 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2557 break;
2558 case DP_TRAINING_PATTERN_2:
2559 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2560 break;
2561 case DP_TRAINING_PATTERN_3:
2562 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2563 break;
2564 }
2565 I915_WRITE(DP_TP_CTL(port), temp);
2566
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002567 } else if ((IS_GEN7(dev) && port == PORT_A) ||
2568 (HAS_PCH_CPT(dev) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002569 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2570
2571 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2572 case DP_TRAINING_PATTERN_DISABLE:
2573 *DP |= DP_LINK_TRAIN_OFF_CPT;
2574 break;
2575 case DP_TRAINING_PATTERN_1:
2576 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2577 break;
2578 case DP_TRAINING_PATTERN_2:
2579 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2580 break;
2581 case DP_TRAINING_PATTERN_3:
2582 DRM_ERROR("DP training pattern 3 not supported\n");
2583 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2584 break;
2585 }
2586
2587 } else {
2588 if (IS_CHERRYVIEW(dev))
2589 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2590 else
2591 *DP &= ~DP_LINK_TRAIN_MASK;
2592
2593 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2594 case DP_TRAINING_PATTERN_DISABLE:
2595 *DP |= DP_LINK_TRAIN_OFF;
2596 break;
2597 case DP_TRAINING_PATTERN_1:
2598 *DP |= DP_LINK_TRAIN_PAT_1;
2599 break;
2600 case DP_TRAINING_PATTERN_2:
2601 *DP |= DP_LINK_TRAIN_PAT_2;
2602 break;
2603 case DP_TRAINING_PATTERN_3:
2604 if (IS_CHERRYVIEW(dev)) {
2605 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2606 } else {
2607 DRM_ERROR("DP training pattern 3 not supported\n");
2608 *DP |= DP_LINK_TRAIN_PAT_2;
2609 }
2610 break;
2611 }
2612 }
2613}
2614
2615static void intel_dp_enable_port(struct intel_dp *intel_dp)
2616{
2617 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2618 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002619 struct intel_crtc *crtc =
2620 to_intel_crtc(dp_to_dig_port(intel_dp)->base.base.crtc);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002621
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002622 /* enable with pattern 1 (as per spec) */
2623 _intel_dp_set_link_train(intel_dp, &intel_dp->DP,
2624 DP_TRAINING_PATTERN_1);
2625
2626 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2627 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002628
2629 /*
2630 * Magic for VLV/CHV. We _must_ first set up the register
2631 * without actually enabling the port, and then do another
2632 * write to enable the port. Otherwise link training will
2633 * fail when the power sequencer is freshly used for this port.
2634 */
2635 intel_dp->DP |= DP_PORT_EN;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002636 if (crtc->config->has_audio)
2637 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002638
2639 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2640 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002641}
2642
Daniel Vettere8cb4552012-07-01 13:05:48 +02002643static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002644{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002645 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2646 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002647 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulac1dec792014-10-27 16:26:56 +02002648 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002649 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002650 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002651
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002652 if (WARN_ON(dp_reg & DP_PORT_EN))
2653 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002654
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002655 pps_lock(intel_dp);
2656
Wayne Boyer666a4532015-12-09 12:29:35 -08002657 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002658 vlv_init_panel_power_sequencer(intel_dp);
2659
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002660 intel_dp_enable_port(intel_dp);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002661
2662 edp_panel_vdd_on(intel_dp);
2663 edp_panel_on(intel_dp);
2664 edp_panel_vdd_off(intel_dp, true);
2665
2666 pps_unlock(intel_dp);
2667
Wayne Boyer666a4532015-12-09 12:29:35 -08002668 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002669 unsigned int lane_mask = 0x0;
2670
2671 if (IS_CHERRYVIEW(dev))
2672 lane_mask = intel_dp_unused_lane_mask(crtc->config->lane_count);
2673
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002674 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2675 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002676 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002677
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002678 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2679 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002680 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002681
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002682 if (crtc->config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002683 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002684 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002685 intel_audio_codec_enable(encoder);
2686 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002687}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002688
Jani Nikulaecff4f32013-09-06 07:38:29 +03002689static void g4x_enable_dp(struct intel_encoder *encoder)
2690{
Jani Nikula828f5c62013-09-05 16:44:45 +03002691 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2692
Jani Nikulaecff4f32013-09-06 07:38:29 +03002693 intel_enable_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01002694 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002695}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002696
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002697static void vlv_enable_dp(struct intel_encoder *encoder)
2698{
Jani Nikula828f5c62013-09-05 16:44:45 +03002699 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2700
Daniel Vetter4be73782014-01-17 14:39:48 +01002701 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002702 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002703}
2704
Jani Nikulaecff4f32013-09-06 07:38:29 +03002705static void g4x_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002706{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002707 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002708 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002709
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002710 intel_dp_prepare(encoder);
2711
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002712 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002713 if (port == PORT_A)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002714 ironlake_edp_pll_on(intel_dp);
2715}
2716
Ville Syrjälä83b84592014-10-16 21:29:51 +03002717static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2718{
2719 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2720 struct drm_i915_private *dev_priv = intel_dig_port->base.base.dev->dev_private;
2721 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002722 i915_reg_t pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002723
2724 edp_panel_vdd_off_sync(intel_dp);
2725
2726 /*
2727 * VLV seems to get confused when multiple power seqeuencers
2728 * have the same port selected (even if only one has power/vdd
2729 * enabled). The failure manifests as vlv_wait_port_ready() failing
2730 * CHV on the other hand doesn't seem to mind having the same port
2731 * selected in multiple power seqeuencers, but let's clear the
2732 * port select always when logically disconnecting a power sequencer
2733 * from a port.
2734 */
2735 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2736 pipe_name(pipe), port_name(intel_dig_port->port));
2737 I915_WRITE(pp_on_reg, 0);
2738 POSTING_READ(pp_on_reg);
2739
2740 intel_dp->pps_pipe = INVALID_PIPE;
2741}
2742
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002743static void vlv_steal_power_sequencer(struct drm_device *dev,
2744 enum pipe pipe)
2745{
2746 struct drm_i915_private *dev_priv = dev->dev_private;
2747 struct intel_encoder *encoder;
2748
2749 lockdep_assert_held(&dev_priv->pps_mutex);
2750
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002751 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2752 return;
2753
Jani Nikula19c80542015-12-16 12:48:16 +02002754 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002755 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002756 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002757
2758 if (encoder->type != INTEL_OUTPUT_EDP)
2759 continue;
2760
2761 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002762 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002763
2764 if (intel_dp->pps_pipe != pipe)
2765 continue;
2766
2767 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002768 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002769
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002770 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002771 "stealing pipe %c power sequencer from active eDP port %c\n",
2772 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002773
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002774 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002775 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002776 }
2777}
2778
2779static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2780{
2781 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2782 struct intel_encoder *encoder = &intel_dig_port->base;
2783 struct drm_device *dev = encoder->base.dev;
2784 struct drm_i915_private *dev_priv = dev->dev_private;
2785 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002786
2787 lockdep_assert_held(&dev_priv->pps_mutex);
2788
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002789 if (!is_edp(intel_dp))
2790 return;
2791
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002792 if (intel_dp->pps_pipe == crtc->pipe)
2793 return;
2794
2795 /*
2796 * If another power sequencer was being used on this
2797 * port previously make sure to turn off vdd there while
2798 * we still have control of it.
2799 */
2800 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002801 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002802
2803 /*
2804 * We may be stealing the power
2805 * sequencer from another port.
2806 */
2807 vlv_steal_power_sequencer(dev, crtc->pipe);
2808
2809 /* now it's all ours */
2810 intel_dp->pps_pipe = crtc->pipe;
2811
2812 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2813 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2814
2815 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002816 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2817 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002818}
2819
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002820static void vlv_pre_enable_dp(struct intel_encoder *encoder)
2821{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002822 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002823
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002824 intel_enable_dp(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002825}
2826
Jani Nikulaecff4f32013-09-06 07:38:29 +03002827static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002828{
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002829 intel_dp_prepare(encoder);
2830
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002831 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002832}
2833
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002834static void chv_pre_enable_dp(struct intel_encoder *encoder)
2835{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002836 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002837
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002838 intel_enable_dp(encoder);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002839
2840 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002841 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002842}
2843
Ville Syrjälä9197c882014-04-09 13:29:05 +03002844static void chv_dp_pre_pll_enable(struct intel_encoder *encoder)
2845{
Ville Syrjälä625695f2014-06-28 02:04:02 +03002846 intel_dp_prepare(encoder);
2847
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002848 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002849}
2850
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002851static void chv_dp_post_pll_disable(struct intel_encoder *encoder)
2852{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002853 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002854}
2855
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002856/*
2857 * Fetch AUX CH registers 0x202 - 0x207 which contain
2858 * link status information
2859 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002860bool
Keith Packard93f62da2011-11-01 19:45:03 -07002861intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002862{
Lyude9f085eb2016-04-13 10:58:33 -04002863 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2864 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002865}
2866
Paulo Zanoni11002442014-06-13 18:45:41 -03002867/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002868uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002869intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002870{
Paulo Zanoni30add222012-10-26 19:05:45 -02002871 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302872 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002873 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002874
Vandana Kannan93147262014-11-18 15:45:29 +05302875 if (IS_BROXTON(dev))
2876 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2877 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002878 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302879 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002880 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Wayne Boyer666a4532015-12-09 12:29:35 -08002881 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Sonika Jindalbd600182014-08-08 16:23:41 +05302882 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002883 else if (IS_GEN7(dev) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302884 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002885 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302886 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08002887 else
Sonika Jindalbd600182014-08-08 16:23:41 +05302888 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08002889}
2890
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002891uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002892intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
2893{
Paulo Zanoni30add222012-10-26 19:05:45 -02002894 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002895 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002896
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002897 if (INTEL_INFO(dev)->gen >= 9) {
2898 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2899 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
2900 return DP_TRAIN_PRE_EMPH_LEVEL_3;
2901 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2902 return DP_TRAIN_PRE_EMPH_LEVEL_2;
2903 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
2904 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302905 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
2906 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002907 default:
2908 return DP_TRAIN_PRE_EMPH_LEVEL_0;
2909 }
2910 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002911 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302912 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
2913 return DP_TRAIN_PRE_EMPH_LEVEL_3;
2914 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2915 return DP_TRAIN_PRE_EMPH_LEVEL_2;
2916 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
2917 return DP_TRAIN_PRE_EMPH_LEVEL_1;
2918 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002919 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05302920 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002921 }
Wayne Boyer666a4532015-12-09 12:29:35 -08002922 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002923 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302924 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
2925 return DP_TRAIN_PRE_EMPH_LEVEL_3;
2926 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2927 return DP_TRAIN_PRE_EMPH_LEVEL_2;
2928 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
2929 return DP_TRAIN_PRE_EMPH_LEVEL_1;
2930 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002931 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05302932 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002933 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03002934 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08002935 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302936 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
2937 return DP_TRAIN_PRE_EMPH_LEVEL_2;
2938 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2939 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
2940 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08002941 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05302942 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08002943 }
2944 } else {
2945 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302946 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
2947 return DP_TRAIN_PRE_EMPH_LEVEL_2;
2948 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2949 return DP_TRAIN_PRE_EMPH_LEVEL_2;
2950 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
2951 return DP_TRAIN_PRE_EMPH_LEVEL_1;
2952 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08002953 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05302954 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08002955 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002956 }
2957}
2958
Daniel Vetter5829975c2015-04-16 11:36:52 +02002959static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002960{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03002961 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002962 unsigned long demph_reg_value, preemph_reg_value,
2963 uniqtranscale_reg_value;
2964 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002965
2966 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302967 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002968 preemph_reg_value = 0x0004000;
2969 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302970 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002971 demph_reg_value = 0x2B405555;
2972 uniqtranscale_reg_value = 0x552AB83A;
2973 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05302974 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002975 demph_reg_value = 0x2B404040;
2976 uniqtranscale_reg_value = 0x5548B83A;
2977 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05302978 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002979 demph_reg_value = 0x2B245555;
2980 uniqtranscale_reg_value = 0x5560B83A;
2981 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05302982 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002983 demph_reg_value = 0x2B405555;
2984 uniqtranscale_reg_value = 0x5598DA3A;
2985 break;
2986 default:
2987 return 0;
2988 }
2989 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05302990 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002991 preemph_reg_value = 0x0002000;
2992 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05302993 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002994 demph_reg_value = 0x2B404040;
2995 uniqtranscale_reg_value = 0x5552B83A;
2996 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05302997 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002998 demph_reg_value = 0x2B404848;
2999 uniqtranscale_reg_value = 0x5580B83A;
3000 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303001 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003002 demph_reg_value = 0x2B404040;
3003 uniqtranscale_reg_value = 0x55ADDA3A;
3004 break;
3005 default:
3006 return 0;
3007 }
3008 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303009 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003010 preemph_reg_value = 0x0000000;
3011 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303012 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003013 demph_reg_value = 0x2B305555;
3014 uniqtranscale_reg_value = 0x5570B83A;
3015 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303016 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003017 demph_reg_value = 0x2B2B4040;
3018 uniqtranscale_reg_value = 0x55ADDA3A;
3019 break;
3020 default:
3021 return 0;
3022 }
3023 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303024 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003025 preemph_reg_value = 0x0006000;
3026 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303027 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003028 demph_reg_value = 0x1B405555;
3029 uniqtranscale_reg_value = 0x55ADDA3A;
3030 break;
3031 default:
3032 return 0;
3033 }
3034 break;
3035 default:
3036 return 0;
3037 }
3038
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003039 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3040 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003041
3042 return 0;
3043}
3044
Daniel Vetter5829975c2015-04-16 11:36:52 +02003045static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003046{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003047 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3048 u32 deemph_reg_value, margin_reg_value;
3049 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003050 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003051
3052 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303053 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003054 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303055 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003056 deemph_reg_value = 128;
3057 margin_reg_value = 52;
3058 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303059 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003060 deemph_reg_value = 128;
3061 margin_reg_value = 77;
3062 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303063 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003064 deemph_reg_value = 128;
3065 margin_reg_value = 102;
3066 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303067 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003068 deemph_reg_value = 128;
3069 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003070 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003071 break;
3072 default:
3073 return 0;
3074 }
3075 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303076 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003077 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303078 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003079 deemph_reg_value = 85;
3080 margin_reg_value = 78;
3081 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303082 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003083 deemph_reg_value = 85;
3084 margin_reg_value = 116;
3085 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303086 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003087 deemph_reg_value = 85;
3088 margin_reg_value = 154;
3089 break;
3090 default:
3091 return 0;
3092 }
3093 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303094 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003095 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303096 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003097 deemph_reg_value = 64;
3098 margin_reg_value = 104;
3099 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303100 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003101 deemph_reg_value = 64;
3102 margin_reg_value = 154;
3103 break;
3104 default:
3105 return 0;
3106 }
3107 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303108 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003109 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003111 deemph_reg_value = 43;
3112 margin_reg_value = 154;
3113 break;
3114 default:
3115 return 0;
3116 }
3117 break;
3118 default:
3119 return 0;
3120 }
3121
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003122 chv_set_phy_signal_level(encoder, deemph_reg_value,
3123 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003124
3125 return 0;
3126}
3127
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003128static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003129gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003130{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003131 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003132
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003133 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303134 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003135 default:
3136 signal_levels |= DP_VOLTAGE_0_4;
3137 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303138 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003139 signal_levels |= DP_VOLTAGE_0_6;
3140 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003142 signal_levels |= DP_VOLTAGE_0_8;
3143 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303144 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003145 signal_levels |= DP_VOLTAGE_1_2;
3146 break;
3147 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003148 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003150 default:
3151 signal_levels |= DP_PRE_EMPHASIS_0;
3152 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303153 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003154 signal_levels |= DP_PRE_EMPHASIS_3_5;
3155 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003157 signal_levels |= DP_PRE_EMPHASIS_6;
3158 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303159 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003160 signal_levels |= DP_PRE_EMPHASIS_9_5;
3161 break;
3162 }
3163 return signal_levels;
3164}
3165
Zhenyu Wange3421a12010-04-08 09:43:27 +08003166/* Gen6's DP voltage swing and pre-emphasis control */
3167static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003168gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003169{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003170 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3171 DP_TRAIN_PRE_EMPHASIS_MASK);
3172 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3174 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003175 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003177 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303178 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3179 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003180 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303181 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3182 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003183 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303184 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3185 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003186 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003187 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003188 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3189 "0x%x\n", signal_levels);
3190 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003191 }
3192}
3193
Keith Packard1a2eb462011-11-16 16:26:07 -08003194/* Gen7's DP voltage swing and pre-emphasis control */
3195static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003196gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003197{
3198 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3199 DP_TRAIN_PRE_EMPHASIS_MASK);
3200 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303201 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003202 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003204 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003206 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3207
Sonika Jindalbd600182014-08-08 16:23:41 +05303208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003209 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003211 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3212
Sonika Jindalbd600182014-08-08 16:23:41 +05303213 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003214 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003216 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3217
3218 default:
3219 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3220 "0x%x\n", signal_levels);
3221 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3222 }
3223}
3224
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003225void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003226intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003227{
3228 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003229 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003230 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003231 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003232 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003233 uint8_t train_set = intel_dp->train_set[0];
3234
David Weinehallf8896f52015-06-25 11:11:03 +03003235 if (HAS_DDI(dev)) {
3236 signal_levels = ddi_signal_levels(intel_dp);
3237
3238 if (IS_BROXTON(dev))
3239 signal_levels = 0;
3240 else
3241 mask = DDI_BUF_EMP_MASK;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003242 } else if (IS_CHERRYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003243 signal_levels = chv_signal_levels(intel_dp);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003244 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003245 signal_levels = vlv_signal_levels(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003246 } else if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003247 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003248 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003249 } else if (IS_GEN6(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003250 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003251 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3252 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003253 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003254 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3255 }
3256
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303257 if (mask)
3258 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3259
3260 DRM_DEBUG_KMS("Using vswing level %d\n",
3261 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3262 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3263 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3264 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003265
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003266 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003267
3268 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3269 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003270}
3271
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003272void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003273intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3274 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003275{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003276 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003277 struct drm_i915_private *dev_priv =
3278 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003279
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003280 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003281
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003282 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003283 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003284}
3285
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003286void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003287{
3288 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3289 struct drm_device *dev = intel_dig_port->base.base.dev;
3290 struct drm_i915_private *dev_priv = dev->dev_private;
3291 enum port port = intel_dig_port->port;
3292 uint32_t val;
3293
3294 if (!HAS_DDI(dev))
3295 return;
3296
3297 val = I915_READ(DP_TP_CTL(port));
3298 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3299 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3300 I915_WRITE(DP_TP_CTL(port), val);
3301
3302 /*
3303 * On PORT_A we can have only eDP in SST mode. There the only reason
3304 * we need to set idle transmission mode is to work around a HW issue
3305 * where we enable the pipe while not in idle link-training mode.
3306 * In this case there is requirement to wait for a minimum number of
3307 * idle patterns to be sent.
3308 */
3309 if (port == PORT_A)
3310 return;
3311
3312 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
3313 1))
3314 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3315}
3316
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003317static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003318intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003319{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003320 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003321 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003322 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003323 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003324 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003325 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003326
Daniel Vetterbc76e3202014-05-20 22:46:50 +02003327 if (WARN_ON(HAS_DDI(dev)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003328 return;
3329
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003330 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003331 return;
3332
Zhao Yakui28c97732009-10-09 11:39:41 +08003333 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003334
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03003335 if ((IS_GEN7(dev) && port == PORT_A) ||
3336 (HAS_PCH_CPT(dev) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003337 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003338 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003339 } else {
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003340 if (IS_CHERRYVIEW(dev))
3341 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3342 else
3343 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003344 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003345 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003346 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003347 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003348
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003349 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3350 I915_WRITE(intel_dp->output_reg, DP);
3351 POSTING_READ(intel_dp->output_reg);
3352
3353 /*
3354 * HW workaround for IBX, we need to move the port
3355 * to transcoder A after disabling it to allow the
3356 * matching HDMI port to be enabled on transcoder A.
3357 */
3358 if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003359 /*
3360 * We get CPU/PCH FIFO underruns on the other pipe when
3361 * doing the workaround. Sweep them under the rug.
3362 */
3363 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3364 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3365
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003366 /* always enable with pattern 1 (as per spec) */
3367 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3368 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3369 I915_WRITE(intel_dp->output_reg, DP);
3370 POSTING_READ(intel_dp->output_reg);
3371
3372 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003373 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003374 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003375
3376 intel_wait_for_vblank_if_active(dev_priv->dev, PIPE_A);
3377 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3378 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003379 }
3380
Keith Packardf01eca22011-09-28 16:48:10 -07003381 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003382
3383 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003384}
3385
Keith Packard26d61aa2011-07-25 20:01:09 -07003386static bool
3387intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003388{
Rodrigo Vivia031d702013-10-03 16:15:06 -03003389 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3390 struct drm_device *dev = dig_port->base.base.dev;
3391 struct drm_i915_private *dev_priv = dev->dev_private;
3392
Lyude9f085eb2016-04-13 10:58:33 -04003393 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3394 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003395 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003396
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003397 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003398
Adam Jacksonedb39242012-09-18 10:58:49 -04003399 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
3400 return false; /* DPCD not present */
3401
Lyude9f085eb2016-04-13 10:58:33 -04003402 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3403 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303404 return false;
3405
3406 /*
3407 * Sink count can change between short pulse hpd hence
3408 * a member variable in intel_dp will track any changes
3409 * between short pulse interrupts.
3410 */
3411 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3412
3413 /*
3414 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3415 * a dongle is present but no display. Unless we require to know
3416 * if a dongle is present or not, we don't need to update
3417 * downstream port information. So, an early return here saves
3418 * time from performing other operations which are not required.
3419 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303420 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303421 return false;
3422
Shobhit Kumar2293bb52013-07-11 18:44:56 -03003423 /* Check if the panel supports PSR */
3424 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
Jani Nikula50003932013-09-20 16:42:17 +03003425 if (is_edp(intel_dp)) {
Lyude9f085eb2016-04-13 10:58:33 -04003426 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3427 intel_dp->psr_dpcd,
3428 sizeof(intel_dp->psr_dpcd));
Rodrigo Vivia031d702013-10-03 16:15:06 -03003429 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3430 dev_priv->psr.sink_support = true;
Jani Nikula50003932013-09-20 16:42:17 +03003431 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
Rodrigo Vivia031d702013-10-03 16:15:06 -03003432 }
Sonika Jindal474d1ec2015-04-02 11:02:44 +05303433
3434 if (INTEL_INFO(dev)->gen >= 9 &&
3435 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3436 uint8_t frame_sync_cap;
3437
3438 dev_priv->psr.sink_support = true;
Lyude9f085eb2016-04-13 10:58:33 -04003439 drm_dp_dpcd_read(&intel_dp->aux,
3440 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3441 &frame_sync_cap, 1);
Sonika Jindal474d1ec2015-04-02 11:02:44 +05303442 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3443 /* PSR2 needs frame sync as well */
3444 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3445 DRM_DEBUG_KMS("PSR2 %s on sink",
3446 dev_priv->psr.psr2_support ? "supported" : "not supported");
3447 }
Yetunde Adebisi86ee27b2016-04-05 15:10:51 +01003448
3449 /* Read the eDP Display control capabilities registers */
3450 memset(intel_dp->edp_dpcd, 0, sizeof(intel_dp->edp_dpcd));
3451 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
Daniel Vetter9a652cc2016-05-17 12:15:49 +02003452 (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Yetunde Adebisi86ee27b2016-04-05 15:10:51 +01003453 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3454 sizeof(intel_dp->edp_dpcd)))
3455 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3456 intel_dp->edp_dpcd);
Jani Nikula50003932013-09-20 16:42:17 +03003457 }
3458
Jani Nikulabc5133d2015-09-03 11:16:07 +03003459 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03003460 yesno(intel_dp_source_supports_hbr2(intel_dp)),
Jani Nikula742f4912015-09-03 11:16:09 +03003461 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
Todd Previte06ea66b2014-01-20 10:19:39 -07003462
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05303463 /* Intermediate frequency support */
Yetunde Adebisi86ee27b2016-04-05 15:10:51 +01003464 if (is_edp(intel_dp) && (intel_dp->edp_dpcd[0] >= 0x03)) { /* eDp v1.4 or higher */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003465 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003466 int i;
3467
Lyude9f085eb2016-04-13 10:58:33 -04003468 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3469 sink_rates, sizeof(sink_rates));
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003470
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003471 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3472 int val = le16_to_cpu(sink_rates[i]);
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003473
3474 if (val == 0)
3475 break;
3476
Sonika Jindalaf77b972015-05-07 13:59:28 +05303477 /* Value read is in kHz while drm clock is saved in deca-kHz */
3478 intel_dp->sink_rates[i] = (val * 200) / 10;
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003479 }
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003480 intel_dp->num_sink_rates = i;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05303481 }
Ville Syrjälä0336400e2015-03-12 17:10:39 +02003482
3483 intel_dp_print_rates(intel_dp);
3484
Adam Jacksonedb39242012-09-18 10:58:49 -04003485 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3486 DP_DWN_STRM_PORT_PRESENT))
3487 return true; /* native DP sink */
3488
3489 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3490 return true; /* no per-port downstream info */
3491
Lyude9f085eb2016-04-13 10:58:33 -04003492 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3493 intel_dp->downstream_ports,
3494 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003495 return false; /* downstream port status fetch failed */
3496
3497 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003498}
3499
Adam Jackson0d198322012-05-14 16:05:47 -04003500static void
3501intel_dp_probe_oui(struct intel_dp *intel_dp)
3502{
3503 u8 buf[3];
3504
3505 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3506 return;
3507
Lyude9f085eb2016-04-13 10:58:33 -04003508 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003509 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3510 buf[0], buf[1], buf[2]);
3511
Lyude9f085eb2016-04-13 10:58:33 -04003512 if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003513 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3514 buf[0], buf[1], buf[2]);
3515}
3516
Dave Airlie0e32b392014-05-02 14:02:48 +10003517static bool
3518intel_dp_probe_mst(struct intel_dp *intel_dp)
3519{
3520 u8 buf[1];
3521
Nathan Schulte7cc96132016-03-15 10:14:05 -05003522 if (!i915.enable_dp_mst)
3523 return false;
3524
Dave Airlie0e32b392014-05-02 14:02:48 +10003525 if (!intel_dp->can_mst)
3526 return false;
3527
3528 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3529 return false;
3530
Lyude9f085eb2016-04-13 10:58:33 -04003531 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003532 if (buf[0] & DP_MST_CAP) {
3533 DRM_DEBUG_KMS("Sink is MST capable\n");
3534 intel_dp->is_mst = true;
3535 } else {
3536 DRM_DEBUG_KMS("Sink is not MST capable\n");
3537 intel_dp->is_mst = false;
3538 }
3539 }
Dave Airlie0e32b392014-05-02 14:02:48 +10003540
3541 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3542 return intel_dp->is_mst;
3543}
3544
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003545static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003546{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003547 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003548 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003549 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003550 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003551 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003552 int count = 0;
3553 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003554
3555 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003556 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003557 ret = -EIO;
3558 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003559 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003560
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003561 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003562 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003563 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003564 ret = -EIO;
3565 goto out;
3566 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003567
Rodrigo Vivic6297842015-11-05 10:50:20 -08003568 do {
3569 intel_wait_for_vblank(dev, intel_crtc->pipe);
3570
3571 if (drm_dp_dpcd_readb(&intel_dp->aux,
3572 DP_TEST_SINK_MISC, &buf) < 0) {
3573 ret = -EIO;
3574 goto out;
3575 }
3576 count = buf & DP_TEST_COUNT_MASK;
3577 } while (--attempts && count);
3578
3579 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003580 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003581 ret = -ETIMEDOUT;
3582 }
3583
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003584 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003585 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003586 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003587}
3588
3589static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3590{
3591 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003592 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003593 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3594 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003595 int ret;
3596
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003597 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3598 return -EIO;
3599
3600 if (!(buf & DP_TEST_CRC_SUPPORTED))
3601 return -ENOTTY;
3602
3603 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3604 return -EIO;
3605
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003606 if (buf & DP_TEST_SINK_START) {
3607 ret = intel_dp_sink_crc_stop(intel_dp);
3608 if (ret)
3609 return ret;
3610 }
3611
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003612 hsw_disable_ips(intel_crtc);
3613
3614 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3615 buf | DP_TEST_SINK_START) < 0) {
3616 hsw_enable_ips(intel_crtc);
3617 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003618 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003619
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003620 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003621 return 0;
3622}
3623
3624int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3625{
3626 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3627 struct drm_device *dev = dig_port->base.base.dev;
3628 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3629 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003630 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003631 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003632
3633 ret = intel_dp_sink_crc_start(intel_dp);
3634 if (ret)
3635 return ret;
3636
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003637 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003638 intel_wait_for_vblank(dev, intel_crtc->pipe);
3639
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003640 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003641 DP_TEST_SINK_MISC, &buf) < 0) {
3642 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003643 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003644 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003645 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003646
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003647 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003648
3649 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003650 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3651 ret = -ETIMEDOUT;
3652 goto stop;
3653 }
3654
3655 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3656 ret = -EIO;
3657 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003658 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003659
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003660stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003661 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003662 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003663}
3664
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003665static bool
3666intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3667{
Lyude9f085eb2016-04-13 10:58:33 -04003668 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003669 DP_DEVICE_SERVICE_IRQ_VECTOR,
3670 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003671}
3672
Dave Airlie0e32b392014-05-02 14:02:48 +10003673static bool
3674intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3675{
3676 int ret;
3677
Lyude9f085eb2016-04-13 10:58:33 -04003678 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003679 DP_SINK_COUNT_ESI,
3680 sink_irq_vector, 14);
3681 if (ret != 14)
3682 return false;
3683
3684 return true;
3685}
3686
Todd Previtec5d5ab72015-04-15 08:38:38 -07003687static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003688{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003689 uint8_t test_result = DP_TEST_ACK;
3690 return test_result;
3691}
3692
3693static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3694{
3695 uint8_t test_result = DP_TEST_NAK;
3696 return test_result;
3697}
3698
3699static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3700{
3701 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003702 struct intel_connector *intel_connector = intel_dp->attached_connector;
3703 struct drm_connector *connector = &intel_connector->base;
3704
3705 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003706 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003707 intel_dp->aux.i2c_defer_count > 6) {
3708 /* Check EDID read for NACKs, DEFERs and corruption
3709 * (DP CTS 1.2 Core r1.1)
3710 * 4.2.2.4 : Failed EDID read, I2C_NAK
3711 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3712 * 4.2.2.6 : EDID corruption detected
3713 * Use failsafe mode for all cases
3714 */
3715 if (intel_dp->aux.i2c_nack_count > 0 ||
3716 intel_dp->aux.i2c_defer_count > 0)
3717 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3718 intel_dp->aux.i2c_nack_count,
3719 intel_dp->aux.i2c_defer_count);
3720 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3721 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303722 struct edid *block = intel_connector->detect_edid;
3723
3724 /* We have to write the checksum
3725 * of the last block read
3726 */
3727 block += intel_connector->detect_edid->extensions;
3728
Todd Previte559be302015-05-04 07:48:20 -07003729 if (!drm_dp_dpcd_write(&intel_dp->aux,
3730 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303731 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003732 1))
Todd Previte559be302015-05-04 07:48:20 -07003733 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3734
3735 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3736 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3737 }
3738
3739 /* Set test active flag here so userspace doesn't interrupt things */
3740 intel_dp->compliance_test_active = 1;
3741
Todd Previtec5d5ab72015-04-15 08:38:38 -07003742 return test_result;
3743}
3744
3745static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3746{
3747 uint8_t test_result = DP_TEST_NAK;
3748 return test_result;
3749}
3750
3751static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3752{
3753 uint8_t response = DP_TEST_NAK;
3754 uint8_t rxdata = 0;
3755 int status = 0;
3756
Todd Previtec5d5ab72015-04-15 08:38:38 -07003757 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3758 if (status <= 0) {
3759 DRM_DEBUG_KMS("Could not read test request from sink\n");
3760 goto update_status;
3761 }
3762
3763 switch (rxdata) {
3764 case DP_TEST_LINK_TRAINING:
3765 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3766 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3767 response = intel_dp_autotest_link_training(intel_dp);
3768 break;
3769 case DP_TEST_LINK_VIDEO_PATTERN:
3770 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3771 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3772 response = intel_dp_autotest_video_pattern(intel_dp);
3773 break;
3774 case DP_TEST_LINK_EDID_READ:
3775 DRM_DEBUG_KMS("EDID test requested\n");
3776 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3777 response = intel_dp_autotest_edid(intel_dp);
3778 break;
3779 case DP_TEST_LINK_PHY_TEST_PATTERN:
3780 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3781 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3782 response = intel_dp_autotest_phy_pattern(intel_dp);
3783 break;
3784 default:
3785 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3786 break;
3787 }
3788
3789update_status:
3790 status = drm_dp_dpcd_write(&intel_dp->aux,
3791 DP_TEST_RESPONSE,
3792 &response, 1);
3793 if (status <= 0)
3794 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003795}
3796
Dave Airlie0e32b392014-05-02 14:02:48 +10003797static int
3798intel_dp_check_mst_status(struct intel_dp *intel_dp)
3799{
3800 bool bret;
3801
3802 if (intel_dp->is_mst) {
3803 u8 esi[16] = { 0 };
3804 int ret = 0;
3805 int retry;
3806 bool handled;
3807 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3808go_again:
3809 if (bret == true) {
3810
3811 /* check link status - esi[10] = 0x200c */
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003812 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003813 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003814 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3815 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003816 intel_dp_stop_link_train(intel_dp);
3817 }
3818
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003819 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003820 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3821
3822 if (handled) {
3823 for (retry = 0; retry < 3; retry++) {
3824 int wret;
3825 wret = drm_dp_dpcd_write(&intel_dp->aux,
3826 DP_SINK_COUNT_ESI+1,
3827 &esi[1], 3);
3828 if (wret == 3) {
3829 break;
3830 }
3831 }
3832
3833 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3834 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003835 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003836 goto go_again;
3837 }
3838 } else
3839 ret = 0;
3840
3841 return ret;
3842 } else {
3843 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3844 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3845 intel_dp->is_mst = false;
3846 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3847 /* send a hotplug event */
3848 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3849 }
3850 }
3851 return -EINVAL;
3852}
3853
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303854static void
3855intel_dp_check_link_status(struct intel_dp *intel_dp)
3856{
3857 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
3858 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3859 u8 link_status[DP_LINK_STATUS_SIZE];
3860
3861 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
3862
3863 if (!intel_dp_get_link_status(intel_dp, link_status)) {
3864 DRM_ERROR("Failed to get link status\n");
3865 return;
3866 }
3867
3868 if (!intel_encoder->base.crtc)
3869 return;
3870
3871 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
3872 return;
3873
3874 /* if link training is requested we should perform it always */
3875 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
3876 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
3877 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
3878 intel_encoder->base.name);
3879 intel_dp_start_link_train(intel_dp);
3880 intel_dp_stop_link_train(intel_dp);
3881 }
3882}
3883
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003884/*
3885 * According to DP spec
3886 * 5.1.2:
3887 * 1. Read DPCD
3888 * 2. Configure link according to Receiver Capabilities
3889 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
3890 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05303891 *
3892 * intel_dp_short_pulse - handles short pulse interrupts
3893 * when full detection is not required.
3894 * Returns %true if short pulse is handled and full detection
3895 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003896 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05303897static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303898intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003899{
Dave Airlie5b215bc2014-08-05 10:40:20 +10003900 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003901 u8 sink_irq_vector;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05303902 u8 old_sink_count = intel_dp->sink_count;
3903 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10003904
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05303905 /*
3906 * Clearing compliance test variables to allow capturing
3907 * of values for next automated test request.
3908 */
3909 intel_dp->compliance_test_active = 0;
3910 intel_dp->compliance_test_type = 0;
3911 intel_dp->compliance_test_data = 0;
3912
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05303913 /*
3914 * Now read the DPCD to see if it's actually running
3915 * If the current value of sink count doesn't match with
3916 * the value that was stored earlier or dpcd read failed
3917 * we need to do full detection
3918 */
3919 ret = intel_dp_get_dpcd(intel_dp);
3920
3921 if ((old_sink_count != intel_dp->sink_count) || !ret) {
3922 /* No need to proceed if we are going to do full detect */
3923 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07003924 }
3925
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003926 /* Try to read the source of the interrupt */
3927 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3928 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
3929 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02003930 drm_dp_dpcd_writeb(&intel_dp->aux,
3931 DP_DEVICE_SERVICE_IRQ_VECTOR,
3932 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003933
3934 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07003935 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003936 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
3937 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
3938 }
3939
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303940 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
3941 intel_dp_check_link_status(intel_dp);
3942 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05303943
3944 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003945}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003946
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003947/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003948static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07003949intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04003950{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003951 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003952 uint8_t type;
3953
3954 if (!intel_dp_get_dpcd(intel_dp))
3955 return connector_status_disconnected;
3956
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303957 if (is_edp(intel_dp))
3958 return connector_status_connected;
3959
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003960 /* if there's no downstream port, we're done */
3961 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07003962 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003963
3964 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03003965 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3966 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02003967
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303968 return intel_dp->sink_count ?
3969 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003970 }
3971
3972 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02003973 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003974 return connector_status_connected;
3975
3976 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03003977 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
3978 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
3979 if (type == DP_DS_PORT_TYPE_VGA ||
3980 type == DP_DS_PORT_TYPE_NON_EDID)
3981 return connector_status_unknown;
3982 } else {
3983 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3984 DP_DWN_STRM_PORT_TYPE_MASK;
3985 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
3986 type == DP_DWN_STRM_PORT_TYPE_OTHER)
3987 return connector_status_unknown;
3988 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003989
3990 /* Anything else is out of spec, warn and ignore */
3991 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07003992 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04003993}
3994
3995static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01003996edp_detect(struct intel_dp *intel_dp)
3997{
3998 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3999 enum drm_connector_status status;
4000
4001 status = intel_panel_detect(dev);
4002 if (status == connector_status_unknown)
4003 status = connector_status_connected;
4004
4005 return status;
4006}
4007
Jani Nikulab93433c2015-08-20 10:47:36 +03004008static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4009 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004010{
Jani Nikulab93433c2015-08-20 10:47:36 +03004011 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004012
Jani Nikula0df53b72015-08-20 10:47:40 +03004013 switch (port->port) {
4014 case PORT_A:
4015 return true;
4016 case PORT_B:
4017 bit = SDE_PORTB_HOTPLUG;
4018 break;
4019 case PORT_C:
4020 bit = SDE_PORTC_HOTPLUG;
4021 break;
4022 case PORT_D:
4023 bit = SDE_PORTD_HOTPLUG;
4024 break;
4025 default:
4026 MISSING_CASE(port->port);
4027 return false;
4028 }
4029
4030 return I915_READ(SDEISR) & bit;
4031}
4032
4033static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4034 struct intel_digital_port *port)
4035{
4036 u32 bit;
4037
4038 switch (port->port) {
4039 case PORT_A:
4040 return true;
4041 case PORT_B:
4042 bit = SDE_PORTB_HOTPLUG_CPT;
4043 break;
4044 case PORT_C:
4045 bit = SDE_PORTC_HOTPLUG_CPT;
4046 break;
4047 case PORT_D:
4048 bit = SDE_PORTD_HOTPLUG_CPT;
4049 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004050 case PORT_E:
4051 bit = SDE_PORTE_HOTPLUG_SPT;
4052 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004053 default:
4054 MISSING_CASE(port->port);
4055 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004056 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004057
Jani Nikulab93433c2015-08-20 10:47:36 +03004058 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004059}
4060
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004061static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004062 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004063{
Jani Nikula9642c812015-08-20 10:47:41 +03004064 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004065
Jani Nikula9642c812015-08-20 10:47:41 +03004066 switch (port->port) {
4067 case PORT_B:
4068 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4069 break;
4070 case PORT_C:
4071 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4072 break;
4073 case PORT_D:
4074 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4075 break;
4076 default:
4077 MISSING_CASE(port->port);
4078 return false;
4079 }
4080
4081 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4082}
4083
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004084static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4085 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004086{
4087 u32 bit;
4088
4089 switch (port->port) {
4090 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004091 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004092 break;
4093 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004094 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004095 break;
4096 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004097 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004098 break;
4099 default:
4100 MISSING_CASE(port->port);
4101 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004102 }
4103
Jani Nikula1d245982015-08-20 10:47:37 +03004104 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004105}
4106
Jani Nikulae464bfd2015-08-20 10:47:42 +03004107static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304108 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004109{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304110 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4111 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004112 u32 bit;
4113
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304114 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4115 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004116 case PORT_A:
4117 bit = BXT_DE_PORT_HP_DDIA;
4118 break;
4119 case PORT_B:
4120 bit = BXT_DE_PORT_HP_DDIB;
4121 break;
4122 case PORT_C:
4123 bit = BXT_DE_PORT_HP_DDIC;
4124 break;
4125 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304126 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004127 return false;
4128 }
4129
4130 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4131}
4132
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004133/*
4134 * intel_digital_port_connected - is the specified port connected?
4135 * @dev_priv: i915 private structure
4136 * @port: the port to test
4137 *
4138 * Return %true if @port is connected, %false otherwise.
4139 */
Sonika Jindal237ed862015-09-15 09:44:20 +05304140bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004141 struct intel_digital_port *port)
4142{
Jani Nikula0df53b72015-08-20 10:47:40 +03004143 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004144 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004145 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004146 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004147 else if (IS_BROXTON(dev_priv))
4148 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004149 else if (IS_GM45(dev_priv))
4150 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004151 else
4152 return g4x_digital_port_connected(dev_priv, port);
4153}
4154
Keith Packard8c241fe2011-09-28 16:38:44 -07004155static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004156intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004157{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004158 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004159
Jani Nikula9cd300e2012-10-19 14:51:52 +03004160 /* use cached edid if we have one */
4161 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004162 /* invalid edid */
4163 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004164 return NULL;
4165
Jani Nikula55e9ede2013-10-01 10:38:54 +03004166 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004167 } else
4168 return drm_get_edid(&intel_connector->base,
4169 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004170}
4171
Chris Wilsonbeb60602014-09-02 20:04:00 +01004172static void
4173intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004174{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004175 struct intel_connector *intel_connector = intel_dp->attached_connector;
4176 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004177
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304178 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004179 edid = intel_dp_get_edid(intel_dp);
4180 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004181
Chris Wilsonbeb60602014-09-02 20:04:00 +01004182 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4183 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4184 else
4185 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4186}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004187
Chris Wilsonbeb60602014-09-02 20:04:00 +01004188static void
4189intel_dp_unset_edid(struct intel_dp *intel_dp)
4190{
4191 struct intel_connector *intel_connector = intel_dp->attached_connector;
4192
4193 kfree(intel_connector->detect_edid);
4194 intel_connector->detect_edid = NULL;
4195
4196 intel_dp->has_audio = false;
4197}
4198
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304199static void
4200intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004201{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304202 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004203 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004204 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4205 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004206 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004207 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004208 enum intel_display_power_domain power_domain;
Dave Airlie0e32b392014-05-02 14:02:48 +10004209 bool ret;
Todd Previte09b1eb12015-04-20 15:27:34 -07004210 u8 sink_irq_vector;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004211
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004212 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4213 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004214
Chris Wilsond410b562014-09-02 20:03:59 +01004215 /* Can't disconnect eDP, but you can close the lid... */
4216 if (is_edp(intel_dp))
4217 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004218 else if (intel_digital_port_connected(to_i915(dev),
4219 dp_to_dig_port(intel_dp)))
4220 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004221 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004222 status = connector_status_disconnected;
4223
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304224 if (status != connector_status_connected) {
4225 intel_dp->compliance_test_active = 0;
4226 intel_dp->compliance_test_type = 0;
4227 intel_dp->compliance_test_data = 0;
4228
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004229 if (intel_dp->is_mst) {
4230 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4231 intel_dp->is_mst,
4232 intel_dp->mst_mgr.mst_state);
4233 intel_dp->is_mst = false;
4234 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4235 intel_dp->is_mst);
4236 }
4237
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004238 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304239 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004240
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304241 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4242 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4243
Adam Jackson0d198322012-05-14 16:05:47 -04004244 intel_dp_probe_oui(intel_dp);
4245
Dave Airlie0e32b392014-05-02 14:02:48 +10004246 ret = intel_dp_probe_mst(intel_dp);
4247 if (ret) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304248 /*
4249 * If we are in MST mode then this connector
4250 * won't appear connected or have anything
4251 * with EDID on it
4252 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004253 status = connector_status_disconnected;
4254 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304255 } else if (connector->status == connector_status_connected) {
4256 /*
4257 * If display was connected already and is still connected
4258 * check links status, there has been known issues of
4259 * link loss triggerring long pulse!!!!
4260 */
4261 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4262 intel_dp_check_link_status(intel_dp);
4263 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4264 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004265 }
4266
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304267 /*
4268 * Clearing NACK and defer counts to get their exact values
4269 * while reading EDID which are required by Compliance tests
4270 * 4.2.2.4 and 4.2.2.5
4271 */
4272 intel_dp->aux.i2c_nack_count = 0;
4273 intel_dp->aux.i2c_defer_count = 0;
4274
Chris Wilsonbeb60602014-09-02 20:04:00 +01004275 intel_dp_set_edid(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004276
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004277 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304278 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004279
Todd Previte09b1eb12015-04-20 15:27:34 -07004280 /* Try to read the source of the interrupt */
4281 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4282 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
4283 /* Clear interrupt source */
4284 drm_dp_dpcd_writeb(&intel_dp->aux,
4285 DP_DEVICE_SERVICE_IRQ_VECTOR,
4286 sink_irq_vector);
4287
4288 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4289 intel_dp_handle_test_request(intel_dp);
4290 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4291 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4292 }
4293
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004294out:
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004295 if ((status != connector_status_connected) &&
4296 (intel_dp->is_mst == false))
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304297 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304298
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004299 intel_display_power_put(to_i915(dev), power_domain);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304300 return;
4301}
4302
4303static enum drm_connector_status
4304intel_dp_detect(struct drm_connector *connector, bool force)
4305{
4306 struct intel_dp *intel_dp = intel_attached_dp(connector);
4307 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4308 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4309 struct intel_connector *intel_connector = to_intel_connector(connector);
4310
4311 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4312 connector->base.id, connector->name);
4313
4314 if (intel_dp->is_mst) {
4315 /* MST devices are disconnected from a monitor POV */
4316 intel_dp_unset_edid(intel_dp);
4317 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4318 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4319 return connector_status_disconnected;
4320 }
4321
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304322 /* If full detect is not performed yet, do a full detect */
4323 if (!intel_dp->detect_done)
4324 intel_dp_long_pulse(intel_dp->attached_connector);
4325
4326 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304327
4328 if (intel_connector->detect_edid)
4329 return connector_status_connected;
4330 else
4331 return connector_status_disconnected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004332}
4333
Chris Wilsonbeb60602014-09-02 20:04:00 +01004334static void
4335intel_dp_force(struct drm_connector *connector)
4336{
4337 struct intel_dp *intel_dp = intel_attached_dp(connector);
4338 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004339 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004340 enum intel_display_power_domain power_domain;
4341
4342 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4343 connector->base.id, connector->name);
4344 intel_dp_unset_edid(intel_dp);
4345
4346 if (connector->status != connector_status_connected)
4347 return;
4348
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004349 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4350 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004351
4352 intel_dp_set_edid(intel_dp);
4353
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004354 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004355
4356 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4357 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4358}
4359
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004360static int intel_dp_get_modes(struct drm_connector *connector)
4361{
Jani Nikuladd06f902012-10-19 14:51:50 +03004362 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004363 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004364
Chris Wilsonbeb60602014-09-02 20:04:00 +01004365 edid = intel_connector->detect_edid;
4366 if (edid) {
4367 int ret = intel_connector_update_modes(connector, edid);
4368 if (ret)
4369 return ret;
4370 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004371
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004372 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004373 if (is_edp(intel_attached_dp(connector)) &&
4374 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004375 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004376
4377 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004378 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004379 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004380 drm_mode_probed_add(connector, mode);
4381 return 1;
4382 }
4383 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004384
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004385 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004386}
4387
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004388static bool
4389intel_dp_detect_audio(struct drm_connector *connector)
4390{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004391 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004392 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004393
Chris Wilsonbeb60602014-09-02 20:04:00 +01004394 edid = to_intel_connector(connector)->detect_edid;
4395 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004396 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004397
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004398 return has_audio;
4399}
4400
Chris Wilsonf6849602010-09-19 09:29:33 +01004401static int
4402intel_dp_set_property(struct drm_connector *connector,
4403 struct drm_property *property,
4404 uint64_t val)
4405{
Chris Wilsone953fd72011-02-21 22:23:52 +00004406 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03004407 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004408 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4409 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004410 int ret;
4411
Rob Clark662595d2012-10-11 20:36:04 -05004412 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004413 if (ret)
4414 return ret;
4415
Chris Wilson3f43c482011-05-12 22:17:24 +01004416 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004417 int i = val;
4418 bool has_audio;
4419
4420 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004421 return 0;
4422
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004423 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004424
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004425 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004426 has_audio = intel_dp_detect_audio(connector);
4427 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004428 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004429
4430 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004431 return 0;
4432
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004433 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004434 goto done;
4435 }
4436
Chris Wilsone953fd72011-02-21 22:23:52 +00004437 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004438 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004439 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004440
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004441 switch (val) {
4442 case INTEL_BROADCAST_RGB_AUTO:
4443 intel_dp->color_range_auto = true;
4444 break;
4445 case INTEL_BROADCAST_RGB_FULL:
4446 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004447 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004448 break;
4449 case INTEL_BROADCAST_RGB_LIMITED:
4450 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004451 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004452 break;
4453 default:
4454 return -EINVAL;
4455 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004456
4457 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004458 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004459 return 0;
4460
Chris Wilsone953fd72011-02-21 22:23:52 +00004461 goto done;
4462 }
4463
Yuly Novikov53b41832012-10-26 12:04:00 +03004464 if (is_edp(intel_dp) &&
4465 property == connector->dev->mode_config.scaling_mode_property) {
4466 if (val == DRM_MODE_SCALE_NONE) {
4467 DRM_DEBUG_KMS("no scaling not supported\n");
4468 return -EINVAL;
4469 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004470 if (HAS_GMCH_DISPLAY(dev_priv) &&
4471 val == DRM_MODE_SCALE_CENTER) {
4472 DRM_DEBUG_KMS("centering not supported\n");
4473 return -EINVAL;
4474 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004475
4476 if (intel_connector->panel.fitting_mode == val) {
4477 /* the eDP scaling property is not changed */
4478 return 0;
4479 }
4480 intel_connector->panel.fitting_mode = val;
4481
4482 goto done;
4483 }
4484
Chris Wilsonf6849602010-09-19 09:29:33 +01004485 return -EINVAL;
4486
4487done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004488 if (intel_encoder->base.crtc)
4489 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004490
4491 return 0;
4492}
4493
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004494static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004495intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004496{
Jani Nikula1d508702012-10-19 14:51:49 +03004497 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004498
Chris Wilson10e972d2014-09-04 21:43:45 +01004499 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004500
Jani Nikula9cd300e2012-10-19 14:51:52 +03004501 if (!IS_ERR_OR_NULL(intel_connector->edid))
4502 kfree(intel_connector->edid);
4503
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004504 /* Can't call is_edp() since the encoder may have been destroyed
4505 * already. */
4506 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004507 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004508
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004509 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004510 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004511}
4512
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004513void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004514{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004515 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4516 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004517
Dave Airlie0e32b392014-05-02 14:02:48 +10004518 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004519 if (is_edp(intel_dp)) {
4520 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004521 /*
4522 * vdd might still be enabled do to the delayed vdd off.
4523 * Make sure vdd is actually turned off here.
4524 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004525 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004526 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004527 pps_unlock(intel_dp);
4528
Clint Taylor01527b32014-07-07 13:01:46 -07004529 if (intel_dp->edp_notifier.notifier_call) {
4530 unregister_reboot_notifier(&intel_dp->edp_notifier);
4531 intel_dp->edp_notifier.notifier_call = NULL;
4532 }
Keith Packardbd943152011-09-18 23:09:52 -07004533 }
Imre Deakc8bd0e42014-12-12 17:57:38 +02004534 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004535 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004536}
4537
Imre Deakbf93ba62016-04-18 10:04:21 +03004538void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004539{
4540 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4541
4542 if (!is_edp(intel_dp))
4543 return;
4544
Ville Syrjälä951468f2014-09-04 14:55:31 +03004545 /*
4546 * vdd might still be enabled do to the delayed vdd off.
4547 * Make sure vdd is actually turned off here.
4548 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004549 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004550 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004551 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004552 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004553}
4554
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004555static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4556{
4557 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4558 struct drm_device *dev = intel_dig_port->base.base.dev;
4559 struct drm_i915_private *dev_priv = dev->dev_private;
4560 enum intel_display_power_domain power_domain;
4561
4562 lockdep_assert_held(&dev_priv->pps_mutex);
4563
4564 if (!edp_have_panel_vdd(intel_dp))
4565 return;
4566
4567 /*
4568 * The VDD bit needs a power domain reference, so if the bit is
4569 * already enabled when we boot or resume, grab this reference and
4570 * schedule a vdd off, so we don't hold on to the reference
4571 * indefinitely.
4572 */
4573 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004574 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004575 intel_display_power_get(dev_priv, power_domain);
4576
4577 edp_panel_vdd_schedule_off(intel_dp);
4578}
4579
Imre Deakbf93ba62016-04-18 10:04:21 +03004580void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004581{
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004582 struct intel_dp *intel_dp;
4583
4584 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4585 return;
4586
4587 intel_dp = enc_to_intel_dp(encoder);
4588
4589 pps_lock(intel_dp);
4590
4591 /*
4592 * Read out the current power sequencer assignment,
4593 * in case the BIOS did something with it.
4594 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004595 if (IS_VALLEYVIEW(encoder->dev) || IS_CHERRYVIEW(encoder->dev))
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004596 vlv_initial_power_sequencer_setup(intel_dp);
4597
4598 intel_edp_panel_vdd_sanitize(intel_dp);
4599
4600 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004601}
4602
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004603static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004604 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004605 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004606 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004607 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004608 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004609 .atomic_get_property = intel_connector_atomic_get_property,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004610 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004611 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004612 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004613};
4614
4615static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4616 .get_modes = intel_dp_get_modes,
4617 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004618};
4619
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004620static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004621 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004622 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004623};
4624
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004625enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004626intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4627{
4628 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004629 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004630 struct drm_device *dev = intel_dig_port->base.base.dev;
4631 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak1c767b32014-08-18 14:42:42 +03004632 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004633 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004634
Takashi Iwai25400582015-11-19 12:09:56 +01004635 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4636 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Dave Airlie0e32b392014-05-02 14:02:48 +10004637 intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
Dave Airlie13cf5502014-06-18 11:29:35 +10004638
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004639 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4640 /*
4641 * vdd off can generate a long pulse on eDP which
4642 * would require vdd on to handle it, and thus we
4643 * would end up in an endless cycle of
4644 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4645 */
4646 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4647 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004648 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004649 }
4650
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004651 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4652 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004653 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004654
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004655 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004656 intel_display_power_get(dev_priv, power_domain);
4657
Dave Airlie0e32b392014-05-02 14:02:48 +10004658 if (long_hpd) {
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304659 intel_dp_long_pulse(intel_dp->attached_connector);
4660 if (intel_dp->is_mst)
4661 ret = IRQ_HANDLED;
4662 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004663
Dave Airlie0e32b392014-05-02 14:02:48 +10004664 } else {
4665 if (intel_dp->is_mst) {
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304666 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4667 /*
4668 * If we were in MST mode, and device is not
4669 * there, get out of MST mode
4670 */
4671 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4672 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4673 intel_dp->is_mst = false;
4674 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4675 intel_dp->is_mst);
4676 goto put_power;
4677 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004678 }
4679
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304680 if (!intel_dp->is_mst) {
4681 if (!intel_dp_short_pulse(intel_dp)) {
4682 intel_dp_long_pulse(intel_dp->attached_connector);
4683 goto put_power;
4684 }
4685 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004686 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004687
4688 ret = IRQ_HANDLED;
4689
Imre Deak1c767b32014-08-18 14:42:42 +03004690put_power:
4691 intel_display_power_put(dev_priv, power_domain);
4692
4693 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004694}
4695
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004696/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004697bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004698{
4699 struct drm_i915_private *dev_priv = dev->dev_private;
Zhao Yakui36e83a12010-06-12 14:32:21 +08004700
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004701 /*
4702 * eDP not supported on g4x. so bail out early just
4703 * for a bit extra safety in case the VBT is bonkers.
4704 */
4705 if (INTEL_INFO(dev)->gen < 5)
4706 return false;
4707
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004708 if (port == PORT_A)
4709 return true;
4710
Jani Nikula951d9ef2016-03-16 12:43:31 +02004711 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004712}
4713
Dave Airlie0e32b392014-05-02 14:02:48 +10004714void
Chris Wilsonf6849602010-09-19 09:29:33 +01004715intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4716{
Yuly Novikov53b41832012-10-26 12:04:00 +03004717 struct intel_connector *intel_connector = to_intel_connector(connector);
4718
Chris Wilson3f43c482011-05-12 22:17:24 +01004719 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004720 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004721 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004722
4723 if (is_edp(intel_dp)) {
4724 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004725 drm_object_attach_property(
4726 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004727 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004728 DRM_MODE_SCALE_ASPECT);
4729 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004730 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004731}
4732
Imre Deakdada1a92014-01-29 13:25:41 +02004733static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4734{
Abhay Kumard28d4732016-01-22 17:39:04 -08004735 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004736 intel_dp->last_power_on = jiffies;
4737 intel_dp->last_backlight_off = jiffies;
4738}
4739
Daniel Vetter67a54562012-10-20 20:57:45 +02004740static void
4741intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004742 struct intel_dp *intel_dp)
Daniel Vetter67a54562012-10-20 20:57:45 +02004743{
4744 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004745 struct edp_power_seq cur, vbt, spec,
4746 *final = &intel_dp->pps_delays;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304747 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004748 i915_reg_t pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07004749
Ville Syrjäläe39b9992014-09-04 14:53:14 +03004750 lockdep_assert_held(&dev_priv->pps_mutex);
4751
Ville Syrjälä81ddbc62014-10-16 21:27:31 +03004752 /* already initialized? */
4753 if (final->t11_t12 != 0)
4754 return;
4755
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304756 if (IS_BROXTON(dev)) {
Imre Deak78597992016-06-16 16:37:20 +03004757 int idx = bxt_power_sequencer_idx(intel_dp);
4758
4759 pp_ctrl_reg = BXT_PP_CONTROL(idx);
4760 pp_on_reg = BXT_PP_ON_DELAYS(idx);
4761 pp_off_reg = BXT_PP_OFF_DELAYS(idx);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304762 } else if (HAS_PCH_SPLIT(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03004763 pp_ctrl_reg = PCH_PP_CONTROL;
Jesse Barnes453c5422013-03-28 09:55:41 -07004764 pp_on_reg = PCH_PP_ON_DELAYS;
4765 pp_off_reg = PCH_PP_OFF_DELAYS;
4766 pp_div_reg = PCH_PP_DIVISOR;
4767 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03004768 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
4769
4770 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
4771 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
4772 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
4773 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07004774 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004775
4776 /* Workaround: Need to write PP_CONTROL with the unlock key as
4777 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304778 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004779
Jesse Barnes453c5422013-03-28 09:55:41 -07004780 pp_on = I915_READ(pp_on_reg);
4781 pp_off = I915_READ(pp_off_reg);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304782 if (!IS_BROXTON(dev)) {
4783 I915_WRITE(pp_ctrl_reg, pp_ctl);
4784 pp_div = I915_READ(pp_div_reg);
4785 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004786
4787 /* Pull timing values out of registers */
4788 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4789 PANEL_POWER_UP_DELAY_SHIFT;
4790
4791 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4792 PANEL_LIGHT_ON_DELAY_SHIFT;
4793
4794 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4795 PANEL_LIGHT_OFF_DELAY_SHIFT;
4796
4797 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4798 PANEL_POWER_DOWN_DELAY_SHIFT;
4799
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304800 if (IS_BROXTON(dev)) {
4801 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4802 BXT_POWER_CYCLE_DELAY_SHIFT;
4803 if (tmp > 0)
4804 cur.t11_t12 = (tmp - 1) * 1000;
4805 else
4806 cur.t11_t12 = 0;
4807 } else {
4808 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004809 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304810 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004811
4812 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4813 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
4814
Jani Nikula6aa23e62016-03-24 17:50:20 +02004815 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02004816
4817 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
4818 * our hw here, which are all in 100usec. */
4819 spec.t1_t3 = 210 * 10;
4820 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
4821 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
4822 spec.t10 = 500 * 10;
4823 /* This one is special and actually in units of 100ms, but zero
4824 * based in the hw (so we need to add 100 ms). But the sw vbt
4825 * table multiplies it with 1000 to make it in units of 100usec,
4826 * too. */
4827 spec.t11_t12 = (510 + 100) * 10;
4828
4829 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4830 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
4831
4832 /* Use the max of the register settings and vbt. If both are
4833 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004834#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02004835 spec.field : \
4836 max(cur.field, vbt.field))
4837 assign_final(t1_t3);
4838 assign_final(t8);
4839 assign_final(t9);
4840 assign_final(t10);
4841 assign_final(t11_t12);
4842#undef assign_final
4843
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004844#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02004845 intel_dp->panel_power_up_delay = get_delay(t1_t3);
4846 intel_dp->backlight_on_delay = get_delay(t8);
4847 intel_dp->backlight_off_delay = get_delay(t9);
4848 intel_dp->panel_power_down_delay = get_delay(t10);
4849 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
4850#undef get_delay
4851
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004852 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
4853 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
4854 intel_dp->panel_power_cycle_delay);
4855
4856 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
4857 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004858}
4859
4860static void
4861intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004862 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004863{
4864 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07004865 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02004866 int div = dev_priv->rawclk_freq / 1000;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004867 i915_reg_t pp_on_reg, pp_off_reg, pp_div_reg, pp_ctrl_reg;
Ville Syrjäläad933b52014-08-18 22:15:56 +03004868 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004869 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07004870
Ville Syrjäläe39b9992014-09-04 14:53:14 +03004871 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07004872
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304873 if (IS_BROXTON(dev)) {
Imre Deak78597992016-06-16 16:37:20 +03004874 int idx = bxt_power_sequencer_idx(intel_dp);
4875
4876 pp_ctrl_reg = BXT_PP_CONTROL(idx);
4877 pp_on_reg = BXT_PP_ON_DELAYS(idx);
4878 pp_off_reg = BXT_PP_OFF_DELAYS(idx);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304879
4880 } else if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes453c5422013-03-28 09:55:41 -07004881 pp_on_reg = PCH_PP_ON_DELAYS;
4882 pp_off_reg = PCH_PP_OFF_DELAYS;
4883 pp_div_reg = PCH_PP_DIVISOR;
4884 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03004885 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
4886
4887 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
4888 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
4889 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07004890 }
4891
Paulo Zanonib2f19d12013-12-19 14:29:44 -02004892 /*
4893 * And finally store the new values in the power sequencer. The
4894 * backlight delays are set to 1 because we do manual waits on them. For
4895 * T8, even BSpec recommends doing it. For T9, if we don't do this,
4896 * we'll end up waiting for the backlight off delay twice: once when we
4897 * do the manual sleep, and once when we disable the panel and wait for
4898 * the PP_STATUS bit to become zero.
4899 */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004900 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Paulo Zanonib2f19d12013-12-19 14:29:44 -02004901 (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
4902 pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004903 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02004904 /* Compute the divisor for the pp clock, simply match the Bspec
4905 * formula. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304906 if (IS_BROXTON(dev)) {
4907 pp_div = I915_READ(pp_ctrl_reg);
4908 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
4909 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
4910 << BXT_POWER_CYCLE_DELAY_SHIFT);
4911 } else {
4912 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
4913 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
4914 << PANEL_POWER_CYCLE_DELAY_SHIFT);
4915 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004916
4917 /* Haswell doesn't have any port selection bits for the panel
4918 * power sequencer any more. */
Wayne Boyer666a4532015-12-09 12:29:35 -08004919 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03004920 port_sel = PANEL_PORT_SELECT_VLV(port);
Imre Deakbc7d38a2013-05-16 14:40:36 +03004921 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03004922 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03004923 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02004924 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03004925 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02004926 }
4927
Jesse Barnes453c5422013-03-28 09:55:41 -07004928 pp_on |= port_sel;
4929
4930 I915_WRITE(pp_on_reg, pp_on);
4931 I915_WRITE(pp_off_reg, pp_off);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304932 if (IS_BROXTON(dev))
4933 I915_WRITE(pp_ctrl_reg, pp_div);
4934 else
4935 I915_WRITE(pp_div_reg, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02004936
Daniel Vetter67a54562012-10-20 20:57:45 +02004937 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07004938 I915_READ(pp_on_reg),
4939 I915_READ(pp_off_reg),
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304940 IS_BROXTON(dev) ?
4941 (I915_READ(pp_ctrl_reg) & BXT_POWER_CYCLE_DELAY_MASK) :
Jesse Barnes453c5422013-03-28 09:55:41 -07004942 I915_READ(pp_div_reg));
Zhenyu Wange3421a12010-04-08 09:43:27 +08004943}
4944
Vandana Kannanb33a2812015-02-13 15:33:03 +05304945/**
4946 * intel_dp_set_drrs_state - program registers for RR switch to take effect
4947 * @dev: DRM device
4948 * @refresh_rate: RR to be programmed
4949 *
4950 * This function gets called when refresh rate (RR) has to be changed from
4951 * one frequency to another. Switches can be between high and low RR
4952 * supported by the panel or to any other RR based on media playback (in
4953 * this case, RR value needs to be passed from user space).
4954 *
4955 * The caller of this function needs to take a lock on dev_priv->drrs.
4956 */
Vandana Kannan96178ee2015-01-10 02:25:56 +05304957static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304958{
4959 struct drm_i915_private *dev_priv = dev->dev_private;
4960 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05304961 struct intel_digital_port *dig_port = NULL;
4962 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02004963 struct intel_crtc_state *config = NULL;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304964 struct intel_crtc *intel_crtc = NULL;
Vandana Kannan96178ee2015-01-10 02:25:56 +05304965 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304966
4967 if (refresh_rate <= 0) {
4968 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
4969 return;
4970 }
4971
Vandana Kannan96178ee2015-01-10 02:25:56 +05304972 if (intel_dp == NULL) {
4973 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304974 return;
4975 }
4976
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07004977 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08004978 * FIXME: This needs proper synchronization with psr state for some
4979 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07004980 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304981
Vandana Kannan96178ee2015-01-10 02:25:56 +05304982 dig_port = dp_to_dig_port(intel_dp);
4983 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02004984 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304985
4986 if (!intel_crtc) {
4987 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
4988 return;
4989 }
4990
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02004991 config = intel_crtc->config;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304992
Vandana Kannan96178ee2015-01-10 02:25:56 +05304993 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05304994 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
4995 return;
4996 }
4997
Vandana Kannan96178ee2015-01-10 02:25:56 +05304998 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
4999 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305000 index = DRRS_LOW_RR;
5001
Vandana Kannan96178ee2015-01-10 02:25:56 +05305002 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305003 DRM_DEBUG_KMS(
5004 "DRRS requested for previously set RR...ignoring\n");
5005 return;
5006 }
5007
5008 if (!intel_crtc->active) {
5009 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5010 return;
5011 }
5012
Durgadoss R44395bf2015-02-13 15:33:02 +05305013 if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305014 switch (index) {
5015 case DRRS_HIGH_RR:
5016 intel_dp_set_m_n(intel_crtc, M1_N1);
5017 break;
5018 case DRRS_LOW_RR:
5019 intel_dp_set_m_n(intel_crtc, M2_N2);
5020 break;
5021 case DRRS_MAX_RR:
5022 default:
5023 DRM_ERROR("Unsupported refreshrate type\n");
5024 }
5025 } else if (INTEL_INFO(dev)->gen > 6) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005026 i915_reg_t reg = PIPECONF(intel_crtc->config->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005027 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305028
Ville Syrjälä649636e2015-09-22 19:50:01 +03005029 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305030 if (index > DRRS_HIGH_RR) {
Wayne Boyer666a4532015-12-09 12:29:35 -08005031 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305032 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5033 else
5034 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305035 } else {
Wayne Boyer666a4532015-12-09 12:29:35 -08005036 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305037 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5038 else
5039 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305040 }
5041 I915_WRITE(reg, val);
5042 }
5043
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305044 dev_priv->drrs.refresh_rate_type = index;
5045
5046 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5047}
5048
Vandana Kannanb33a2812015-02-13 15:33:03 +05305049/**
5050 * intel_edp_drrs_enable - init drrs struct if supported
5051 * @intel_dp: DP struct
5052 *
5053 * Initializes frontbuffer_bits and drrs.dp
5054 */
Vandana Kannanc3955782015-01-22 15:17:40 +05305055void intel_edp_drrs_enable(struct intel_dp *intel_dp)
5056{
5057 struct drm_device *dev = intel_dp_to_dev(intel_dp);
5058 struct drm_i915_private *dev_priv = dev->dev_private;
5059 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
5060 struct drm_crtc *crtc = dig_port->base.base.crtc;
5061 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5062
5063 if (!intel_crtc->config->has_drrs) {
5064 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5065 return;
5066 }
5067
5068 mutex_lock(&dev_priv->drrs.mutex);
5069 if (WARN_ON(dev_priv->drrs.dp)) {
5070 DRM_ERROR("DRRS already enabled\n");
5071 goto unlock;
5072 }
5073
5074 dev_priv->drrs.busy_frontbuffer_bits = 0;
5075
5076 dev_priv->drrs.dp = intel_dp;
5077
5078unlock:
5079 mutex_unlock(&dev_priv->drrs.mutex);
5080}
5081
Vandana Kannanb33a2812015-02-13 15:33:03 +05305082/**
5083 * intel_edp_drrs_disable - Disable DRRS
5084 * @intel_dp: DP struct
5085 *
5086 */
Vandana Kannanc3955782015-01-22 15:17:40 +05305087void intel_edp_drrs_disable(struct intel_dp *intel_dp)
5088{
5089 struct drm_device *dev = intel_dp_to_dev(intel_dp);
5090 struct drm_i915_private *dev_priv = dev->dev_private;
5091 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
5092 struct drm_crtc *crtc = dig_port->base.base.crtc;
5093 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5094
5095 if (!intel_crtc->config->has_drrs)
5096 return;
5097
5098 mutex_lock(&dev_priv->drrs.mutex);
5099 if (!dev_priv->drrs.dp) {
5100 mutex_unlock(&dev_priv->drrs.mutex);
5101 return;
5102 }
5103
5104 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5105 intel_dp_set_drrs_state(dev_priv->dev,
5106 intel_dp->attached_connector->panel.
5107 fixed_mode->vrefresh);
5108
5109 dev_priv->drrs.dp = NULL;
5110 mutex_unlock(&dev_priv->drrs.mutex);
5111
5112 cancel_delayed_work_sync(&dev_priv->drrs.work);
5113}
5114
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305115static void intel_edp_drrs_downclock_work(struct work_struct *work)
5116{
5117 struct drm_i915_private *dev_priv =
5118 container_of(work, typeof(*dev_priv), drrs.work.work);
5119 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305120
Vandana Kannan96178ee2015-01-10 02:25:56 +05305121 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305122
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305123 intel_dp = dev_priv->drrs.dp;
5124
5125 if (!intel_dp)
5126 goto unlock;
5127
5128 /*
5129 * The delayed work can race with an invalidate hence we need to
5130 * recheck.
5131 */
5132
5133 if (dev_priv->drrs.busy_frontbuffer_bits)
5134 goto unlock;
5135
5136 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
5137 intel_dp_set_drrs_state(dev_priv->dev,
5138 intel_dp->attached_connector->panel.
5139 downclock_mode->vrefresh);
5140
5141unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305142 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305143}
5144
Vandana Kannanb33a2812015-02-13 15:33:03 +05305145/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305146 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Vandana Kannanb33a2812015-02-13 15:33:03 +05305147 * @dev: DRM device
5148 * @frontbuffer_bits: frontbuffer plane tracking bits
5149 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305150 * This function gets called everytime rendering on the given planes start.
5151 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305152 *
5153 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5154 */
Vandana Kannana93fad02015-01-10 02:25:59 +05305155void intel_edp_drrs_invalidate(struct drm_device *dev,
5156 unsigned frontbuffer_bits)
5157{
5158 struct drm_i915_private *dev_priv = dev->dev_private;
5159 struct drm_crtc *crtc;
5160 enum pipe pipe;
5161
Daniel Vetter9da7d692015-04-09 16:44:15 +02005162 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305163 return;
5164
Daniel Vetter88f933a2015-04-09 16:44:16 +02005165 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305166
Vandana Kannana93fad02015-01-10 02:25:59 +05305167 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005168 if (!dev_priv->drrs.dp) {
5169 mutex_unlock(&dev_priv->drrs.mutex);
5170 return;
5171 }
5172
Vandana Kannana93fad02015-01-10 02:25:59 +05305173 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5174 pipe = to_intel_crtc(crtc)->pipe;
5175
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005176 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5177 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5178
Ramalingam C0ddfd202015-06-15 20:50:05 +05305179 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005180 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Vandana Kannana93fad02015-01-10 02:25:59 +05305181 intel_dp_set_drrs_state(dev_priv->dev,
5182 dev_priv->drrs.dp->attached_connector->panel.
5183 fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305184
Vandana Kannana93fad02015-01-10 02:25:59 +05305185 mutex_unlock(&dev_priv->drrs.mutex);
5186}
5187
Vandana Kannanb33a2812015-02-13 15:33:03 +05305188/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305189 * intel_edp_drrs_flush - Restart Idleness DRRS
Vandana Kannanb33a2812015-02-13 15:33:03 +05305190 * @dev: DRM device
5191 * @frontbuffer_bits: frontbuffer plane tracking bits
5192 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305193 * This function gets called every time rendering on the given planes has
5194 * completed or flip on a crtc is completed. So DRRS should be upclocked
5195 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5196 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305197 *
5198 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5199 */
Vandana Kannana93fad02015-01-10 02:25:59 +05305200void intel_edp_drrs_flush(struct drm_device *dev,
5201 unsigned frontbuffer_bits)
5202{
5203 struct drm_i915_private *dev_priv = dev->dev_private;
5204 struct drm_crtc *crtc;
5205 enum pipe pipe;
5206
Daniel Vetter9da7d692015-04-09 16:44:15 +02005207 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305208 return;
5209
Daniel Vetter88f933a2015-04-09 16:44:16 +02005210 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305211
Vandana Kannana93fad02015-01-10 02:25:59 +05305212 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005213 if (!dev_priv->drrs.dp) {
5214 mutex_unlock(&dev_priv->drrs.mutex);
5215 return;
5216 }
5217
Vandana Kannana93fad02015-01-10 02:25:59 +05305218 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5219 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005220
5221 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305222 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5223
Ramalingam C0ddfd202015-06-15 20:50:05 +05305224 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005225 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Ramalingam C0ddfd202015-06-15 20:50:05 +05305226 intel_dp_set_drrs_state(dev_priv->dev,
5227 dev_priv->drrs.dp->attached_connector->panel.
5228 fixed_mode->vrefresh);
5229
5230 /*
5231 * flush also means no more activity hence schedule downclock, if all
5232 * other fbs are quiescent too
5233 */
5234 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305235 schedule_delayed_work(&dev_priv->drrs.work,
5236 msecs_to_jiffies(1000));
5237 mutex_unlock(&dev_priv->drrs.mutex);
5238}
5239
Vandana Kannanb33a2812015-02-13 15:33:03 +05305240/**
5241 * DOC: Display Refresh Rate Switching (DRRS)
5242 *
5243 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5244 * which enables swtching between low and high refresh rates,
5245 * dynamically, based on the usage scenario. This feature is applicable
5246 * for internal panels.
5247 *
5248 * Indication that the panel supports DRRS is given by the panel EDID, which
5249 * would list multiple refresh rates for one resolution.
5250 *
5251 * DRRS is of 2 types - static and seamless.
5252 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5253 * (may appear as a blink on screen) and is used in dock-undock scenario.
5254 * Seamless DRRS involves changing RR without any visual effect to the user
5255 * and can be used during normal system usage. This is done by programming
5256 * certain registers.
5257 *
5258 * Support for static/seamless DRRS may be indicated in the VBT based on
5259 * inputs from the panel spec.
5260 *
5261 * DRRS saves power by switching to low RR based on usage scenarios.
5262 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005263 * The implementation is based on frontbuffer tracking implementation. When
5264 * there is a disturbance on the screen triggered by user activity or a periodic
5265 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5266 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5267 * made.
5268 *
5269 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5270 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305271 *
5272 * DRRS can be further extended to support other internal panels and also
5273 * the scenario of video playback wherein RR is set based on the rate
5274 * requested by userspace.
5275 */
5276
5277/**
5278 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5279 * @intel_connector: eDP connector
5280 * @fixed_mode: preferred mode of panel
5281 *
5282 * This function is called only once at driver load to initialize basic
5283 * DRRS stuff.
5284 *
5285 * Returns:
5286 * Downclock mode if panel supports it, else return NULL.
5287 * DRRS support is determined by the presence of downclock mode (apart
5288 * from VBT setting).
5289 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305290static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305291intel_dp_drrs_init(struct intel_connector *intel_connector,
5292 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305293{
5294 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305295 struct drm_device *dev = connector->dev;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305296 struct drm_i915_private *dev_priv = dev->dev_private;
5297 struct drm_display_mode *downclock_mode = NULL;
5298
Daniel Vetter9da7d692015-04-09 16:44:15 +02005299 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5300 mutex_init(&dev_priv->drrs.mutex);
5301
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305302 if (INTEL_INFO(dev)->gen <= 6) {
5303 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5304 return NULL;
5305 }
5306
5307 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005308 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305309 return NULL;
5310 }
5311
5312 downclock_mode = intel_find_panel_downclock
5313 (dev, fixed_mode, connector);
5314
5315 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305316 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305317 return NULL;
5318 }
5319
Vandana Kannan96178ee2015-01-10 02:25:56 +05305320 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305321
Vandana Kannan96178ee2015-01-10 02:25:56 +05305322 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005323 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305324 return downclock_mode;
5325}
5326
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005327static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005328 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005329{
5330 struct drm_connector *connector = &intel_connector->base;
5331 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005332 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5333 struct drm_device *dev = intel_encoder->base.dev;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005334 struct drm_i915_private *dev_priv = dev->dev_private;
5335 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305336 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005337 bool has_dpcd;
5338 struct drm_display_mode *scan;
5339 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005340 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005341
5342 if (!is_edp(intel_dp))
5343 return true;
5344
Imre Deak97a824e12016-06-21 11:51:47 +03005345 /*
5346 * On IBX/CPT we may get here with LVDS already registered. Since the
5347 * driver uses the only internal power sequencer available for both
5348 * eDP and LVDS bail out early in this case to prevent interfering
5349 * with an already powered-on LVDS power sequencer.
5350 */
5351 if (intel_get_lvds_encoder(dev)) {
5352 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5353 DRM_INFO("LVDS was detected, not registering eDP\n");
5354
5355 return false;
5356 }
5357
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005358 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005359
5360 intel_dp_init_panel_power_timestamps(intel_dp);
5361
5362 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
5363 vlv_initial_power_sequencer_setup(intel_dp);
5364 } else {
5365 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5366 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5367 }
5368
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005369 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005370
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005371 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005372
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005373 /* Cache DPCD and EDID for edp. */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005374 has_dpcd = intel_dp_get_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005375
5376 if (has_dpcd) {
5377 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
5378 dev_priv->no_aux_handshake =
5379 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
5380 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
5381 } else {
5382 /* if this fails, presume the device is a ghost */
5383 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005384 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005385 }
5386
Daniel Vetter060c8772014-03-21 23:22:35 +01005387 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005388 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005389 if (edid) {
5390 if (drm_add_edid_modes(connector, edid)) {
5391 drm_mode_connector_update_edid_property(connector,
5392 edid);
5393 drm_edid_to_eld(connector, edid);
5394 } else {
5395 kfree(edid);
5396 edid = ERR_PTR(-EINVAL);
5397 }
5398 } else {
5399 edid = ERR_PTR(-ENOENT);
5400 }
5401 intel_connector->edid = edid;
5402
5403 /* prefer fixed mode from EDID if available */
5404 list_for_each_entry(scan, &connector->probed_modes, head) {
5405 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5406 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305407 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305408 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005409 break;
5410 }
5411 }
5412
5413 /* fallback to VBT if available for eDP */
5414 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5415 fixed_mode = drm_mode_duplicate(dev,
5416 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005417 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005418 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005419 connector->display_info.width_mm = fixed_mode->width_mm;
5420 connector->display_info.height_mm = fixed_mode->height_mm;
5421 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005422 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005423 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005424
Wayne Boyer666a4532015-12-09 12:29:35 -08005425 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005426 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5427 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005428
5429 /*
5430 * Figure out the current pipe for the initial backlight setup.
5431 * If the current pipe isn't valid, try the PPS pipe, and if that
5432 * fails just assume pipe A.
5433 */
5434 if (IS_CHERRYVIEW(dev))
5435 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5436 else
5437 pipe = PORT_TO_PIPE(intel_dp->DP);
5438
5439 if (pipe != PIPE_A && pipe != PIPE_B)
5440 pipe = intel_dp->pps_pipe;
5441
5442 if (pipe != PIPE_A && pipe != PIPE_B)
5443 pipe = PIPE_A;
5444
5445 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5446 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005447 }
5448
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305449 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005450 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005451 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005452
5453 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005454
5455out_vdd_off:
5456 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5457 /*
5458 * vdd might still be enabled do to the delayed vdd off.
5459 * Make sure vdd is actually turned off here.
5460 */
5461 pps_lock(intel_dp);
5462 edp_panel_vdd_off_sync(intel_dp);
5463 pps_unlock(intel_dp);
5464
5465 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005466}
5467
Paulo Zanoni16c25532013-06-12 17:27:25 -03005468bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005469intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5470 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005471{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005472 struct drm_connector *connector = &intel_connector->base;
5473 struct intel_dp *intel_dp = &intel_dig_port->dp;
5474 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5475 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005476 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02005477 enum port port = intel_dig_port->port;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005478 int type, ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005479
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005480 if (WARN(intel_dig_port->max_lanes < 1,
5481 "Not enough lanes (%d) for DP on port %c\n",
5482 intel_dig_port->max_lanes, port_name(port)))
5483 return false;
5484
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005485 intel_dp->pps_pipe = INVALID_PIPE;
5486
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005487 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005488 if (INTEL_INFO(dev)->gen >= 9)
5489 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005490 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
5491 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
5492 else if (HAS_PCH_SPLIT(dev))
5493 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5494 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005495 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005496
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005497 if (INTEL_INFO(dev)->gen >= 9)
5498 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5499 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005500 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005501
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005502 if (HAS_DDI(dev))
5503 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5504
Daniel Vetter07679352012-09-06 22:15:42 +02005505 /* Preserve the current hw state. */
5506 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005507 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005508
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005509 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305510 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005511 else
5512 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005513
Imre Deakf7d24902013-05-08 13:14:05 +03005514 /*
5515 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5516 * for DP the encoder type can be set by the caller to
5517 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5518 */
5519 if (type == DRM_MODE_CONNECTOR_eDP)
5520 intel_encoder->type = INTEL_OUTPUT_EDP;
5521
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005522 /* eDP only on port B and/or C on vlv/chv */
Wayne Boyer666a4532015-12-09 12:29:35 -08005523 if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
5524 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005525 return false;
5526
Imre Deake7281ea2013-05-08 13:14:08 +03005527 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5528 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5529 port_name(port));
5530
Adam Jacksonb3295302010-07-16 14:46:28 -04005531 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005532 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5533
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005534 connector->interlace_allowed = true;
5535 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005536
Daniel Vetter66a92782012-07-12 20:08:18 +02005537 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005538 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005539
Chris Wilsondf0e9242010-09-09 16:20:55 +01005540 intel_connector_attach_encoder(intel_connector, intel_encoder);
Thomas Wood34ea3d32014-05-29 16:57:41 +01005541 drm_connector_register(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005542
Paulo Zanoniaffa9352012-11-23 15:30:39 -02005543 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005544 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5545 else
5546 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak80f65de2014-02-11 17:12:49 +02005547 intel_connector->unregister = intel_dp_connector_unregister;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005548
Jani Nikula0b998362014-03-14 16:51:17 +02005549 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005550 switch (port) {
5551 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005552 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005553 break;
5554 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005555 intel_encoder->hpd_pin = HPD_PORT_B;
Jani Nikulae87a0052015-10-20 15:22:02 +03005556 if (IS_BXT_REVID(dev, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305557 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005558 break;
5559 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005560 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005561 break;
5562 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005563 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005564 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005565 case PORT_E:
5566 intel_encoder->hpd_pin = HPD_PORT_E;
5567 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005568 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005569 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005570 }
5571
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005572 ret = intel_dp_aux_init(intel_dp, intel_connector);
5573 if (ret)
5574 goto fail;
Dave Airliec1f05262012-08-30 11:06:18 +10005575
Dave Airlie0e32b392014-05-02 14:02:48 +10005576 /* init MST on ports that can support it */
Jani Nikula0c9b3712015-05-18 17:10:01 +03005577 if (HAS_DP_MST(dev) &&
5578 (port == PORT_B || port == PORT_C || port == PORT_D))
5579 intel_dp_mst_encoder_init(intel_dig_port,
5580 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005581
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005582 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005583 intel_dp_aux_fini(intel_dp);
5584 intel_dp_mst_encoder_cleanup(intel_dig_port);
5585 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005586 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005587
Chris Wilsonf6849602010-09-19 09:29:33 +01005588 intel_dp_add_properties(intel_dp, connector);
5589
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005590 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5591 * 0xd. Failure to do so will result in spurious interrupts being
5592 * generated on the port when a cable is not attached.
5593 */
5594 if (IS_G4X(dev) && !IS_GM45(dev)) {
5595 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5596 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5597 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005598
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005599 i915_debugfs_connector_add(connector);
5600
Paulo Zanoni16c25532013-06-12 17:27:25 -03005601 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005602
5603fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005604 drm_connector_unregister(connector);
5605 drm_connector_cleanup(connector);
5606
5607 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005608}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005609
Chris Wilson457c52d2016-06-01 08:27:50 +01005610bool intel_dp_init(struct drm_device *dev,
5611 i915_reg_t output_reg,
5612 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005613{
Dave Airlie13cf5502014-06-18 11:29:35 +10005614 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005615 struct intel_digital_port *intel_dig_port;
5616 struct intel_encoder *intel_encoder;
5617 struct drm_encoder *encoder;
5618 struct intel_connector *intel_connector;
5619
Daniel Vetterb14c5672013-09-19 12:18:32 +02005620 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005621 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005622 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005623
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005624 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305625 if (!intel_connector)
5626 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005627
5628 intel_encoder = &intel_dig_port->base;
5629 encoder = &intel_encoder->base;
5630
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305631 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005632 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305633 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005634
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005635 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005636 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005637 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005638 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005639 intel_encoder->suspend = intel_dp_encoder_suspend;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005640 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005641 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005642 intel_encoder->pre_enable = chv_pre_enable_dp;
5643 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005644 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005645 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005646 } else if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005647 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005648 intel_encoder->pre_enable = vlv_pre_enable_dp;
5649 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005650 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005651 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005652 intel_encoder->pre_enable = g4x_pre_enable_dp;
5653 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005654 if (INTEL_INFO(dev)->gen >= 5)
5655 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005656 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005657
Paulo Zanoni174edf12012-10-26 19:05:50 -02005658 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005659 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005660 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005661
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005662 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Ville Syrjälä882ec382014-04-28 14:07:43 +03005663 if (IS_CHERRYVIEW(dev)) {
5664 if (port == PORT_D)
5665 intel_encoder->crtc_mask = 1 << 2;
5666 else
5667 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5668 } else {
5669 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5670 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005671 intel_encoder->cloneable = 0;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005672
Dave Airlie13cf5502014-06-18 11:29:35 +10005673 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005674 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005675
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305676 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5677 goto err_init_connector;
5678
Chris Wilson457c52d2016-06-01 08:27:50 +01005679 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305680
5681err_init_connector:
5682 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305683err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305684 kfree(intel_connector);
5685err_connector_alloc:
5686 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005687 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005688}
Dave Airlie0e32b392014-05-02 14:02:48 +10005689
5690void intel_dp_mst_suspend(struct drm_device *dev)
5691{
5692 struct drm_i915_private *dev_priv = dev->dev_private;
5693 int i;
5694
5695 /* disable MST */
5696 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005697 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Dave Airlie0e32b392014-05-02 14:02:48 +10005698 if (!intel_dig_port)
5699 continue;
5700
5701 if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
5702 if (!intel_dig_port->dp.can_mst)
5703 continue;
5704 if (intel_dig_port->dp.is_mst)
5705 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
5706 }
5707 }
5708}
5709
5710void intel_dp_mst_resume(struct drm_device *dev)
5711{
5712 struct drm_i915_private *dev_priv = dev->dev_private;
5713 int i;
5714
5715 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005716 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Dave Airlie0e32b392014-05-02 14:02:48 +10005717 if (!intel_dig_port)
5718 continue;
5719 if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
5720 int ret;
5721
5722 if (!intel_dig_port->dp.can_mst)
5723 continue;
5724
5725 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5726 if (ret != 0) {
5727 intel_dp_check_mst_status(&intel_dig_port->dp);
5728 }
5729 }
5730 }
5731}