blob: 4f0fad3cf138bb40f147cd0c118820016d70039d [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);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700132
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300133static unsigned int intel_dp_unused_lane_mask(int lane_count)
134{
135 return ~((1 << lane_count) - 1) & 0xf;
136}
137
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200138static int
139intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700140{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700141 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700142
143 switch (max_link_bw) {
144 case DP_LINK_BW_1_62:
145 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200146 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300147 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700148 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300149 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
150 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700151 max_link_bw = DP_LINK_BW_1_62;
152 break;
153 }
154 return max_link_bw;
155}
156
Paulo Zanonieeb63242014-05-06 14:56:50 +0300157static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
158{
159 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300160 u8 source_max, sink_max;
161
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200162 source_max = intel_dig_port->max_lanes;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300163 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
164
165 return min(source_max, sink_max);
166}
167
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400168/*
169 * The units on the numbers in the next two are... bizarre. Examples will
170 * make it clearer; this one parallels an example in the eDP spec.
171 *
172 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
173 *
174 * 270000 * 1 * 8 / 10 == 216000
175 *
176 * The actual data capacity of that configuration is 2.16Gbit/s, so the
177 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
178 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
179 * 119000. At 18bpp that's 2142000 kilobits per second.
180 *
181 * Thus the strange-looking division by 10 in intel_dp_link_required, to
182 * get the result in decakilobits instead of kilobits.
183 */
184
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185static int
Keith Packardc8982612012-01-25 08:16:25 -0800186intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700187{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400188 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700189}
190
191static int
Dave Airliefe27d532010-06-30 11:46:17 +1000192intel_dp_max_data_rate(int max_link_clock, int max_lanes)
193{
194 return (max_link_clock * max_lanes * 8) / 10;
195}
196
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000197static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700198intel_dp_mode_valid(struct drm_connector *connector,
199 struct drm_display_mode *mode)
200{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100201 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300202 struct intel_connector *intel_connector = to_intel_connector(connector);
203 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100204 int target_clock = mode->clock;
205 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola799487f2016-02-02 15:16:38 +0200206 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700207
Jani Nikuladd06f902012-10-19 14:51:50 +0300208 if (is_edp(intel_dp) && fixed_mode) {
209 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100210 return MODE_PANEL;
211
Jani Nikuladd06f902012-10-19 14:51:50 +0300212 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100213 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200214
215 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100216 }
217
Ville Syrjälä50fec212015-03-12 17:10:34 +0200218 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300219 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100220
221 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
222 mode_rate = intel_dp_link_required(target_clock, 18);
223
Mika Kahola799487f2016-02-02 15:16:38 +0200224 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200225 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700226
227 if (mode->clock < 10000)
228 return MODE_CLOCK_LOW;
229
Daniel Vetter0af78a22012-05-23 11:30:55 +0200230 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
231 return MODE_H_ILLEGAL;
232
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700233 return MODE_OK;
234}
235
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800236uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700237{
238 int i;
239 uint32_t v = 0;
240
241 if (src_bytes > 4)
242 src_bytes = 4;
243 for (i = 0; i < src_bytes; i++)
244 v |= ((uint32_t) src[i]) << ((3-i) * 8);
245 return v;
246}
247
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000248static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700249{
250 int i;
251 if (dst_bytes > 4)
252 dst_bytes = 4;
253 for (i = 0; i < dst_bytes; i++)
254 dst[i] = src >> ((3-i) * 8);
255}
256
Jani Nikulabf13e812013-09-06 07:40:05 +0300257static void
258intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300259 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300260static void
261intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300262 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300263
Ville Syrjälä773538e82014-09-04 14:54:56 +0300264static void pps_lock(struct intel_dp *intel_dp)
265{
266 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
267 struct intel_encoder *encoder = &intel_dig_port->base;
268 struct drm_device *dev = encoder->base.dev;
269 struct drm_i915_private *dev_priv = dev->dev_private;
270 enum intel_display_power_domain power_domain;
271
272 /*
273 * See vlv_power_sequencer_reset() why we need
274 * a power domain reference here.
275 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100276 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300277 intel_display_power_get(dev_priv, power_domain);
278
279 mutex_lock(&dev_priv->pps_mutex);
280}
281
282static void pps_unlock(struct intel_dp *intel_dp)
283{
284 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
285 struct intel_encoder *encoder = &intel_dig_port->base;
286 struct drm_device *dev = encoder->base.dev;
287 struct drm_i915_private *dev_priv = dev->dev_private;
288 enum intel_display_power_domain power_domain;
289
290 mutex_unlock(&dev_priv->pps_mutex);
291
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100292 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300293 intel_display_power_put(dev_priv, power_domain);
294}
295
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300296static void
297vlv_power_sequencer_kick(struct intel_dp *intel_dp)
298{
299 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
300 struct drm_device *dev = intel_dig_port->base.base.dev;
301 struct drm_i915_private *dev_priv = dev->dev_private;
302 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300303 bool pll_enabled, release_cl_override = false;
304 enum dpio_phy phy = DPIO_PHY(pipe);
305 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300306 uint32_t DP;
307
308 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
309 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
310 pipe_name(pipe), port_name(intel_dig_port->port)))
311 return;
312
313 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
314 pipe_name(pipe), port_name(intel_dig_port->port));
315
316 /* Preserve the BIOS-computed detected bit. This is
317 * supposed to be read-only.
318 */
319 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
320 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
321 DP |= DP_PORT_WIDTH(1);
322 DP |= DP_LINK_TRAIN_PAT_1;
323
324 if (IS_CHERRYVIEW(dev))
325 DP |= DP_PIPE_SELECT_CHV(pipe);
326 else if (pipe == PIPE_B)
327 DP |= DP_PIPEB_SELECT;
328
Ville Syrjäläd288f652014-10-28 13:20:22 +0200329 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
330
331 /*
332 * The DPLL for the pipe must be enabled for this to work.
333 * So enable temporarily it if it's not already enabled.
334 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300335 if (!pll_enabled) {
336 release_cl_override = IS_CHERRYVIEW(dev) &&
337 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
338
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000339 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
340 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
341 DRM_ERROR("Failed to force on pll for pipe %c!\n",
342 pipe_name(pipe));
343 return;
344 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300345 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200346
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300347 /*
348 * Similar magic as in intel_dp_enable_port().
349 * We _must_ do this port enable + disable trick
350 * to make this power seqeuencer lock onto the port.
351 * Otherwise even VDD force bit won't work.
352 */
353 I915_WRITE(intel_dp->output_reg, DP);
354 POSTING_READ(intel_dp->output_reg);
355
356 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
357 POSTING_READ(intel_dp->output_reg);
358
359 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
360 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200361
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300362 if (!pll_enabled) {
Ville Syrjäläd288f652014-10-28 13:20:22 +0200363 vlv_force_pll_off(dev, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300364
365 if (release_cl_override)
366 chv_phy_powergate_ch(dev_priv, phy, ch, false);
367 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300368}
369
Jani Nikulabf13e812013-09-06 07:40:05 +0300370static enum pipe
371vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
372{
373 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300374 struct drm_device *dev = intel_dig_port->base.base.dev;
375 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300376 struct intel_encoder *encoder;
377 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300378 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300379
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300380 lockdep_assert_held(&dev_priv->pps_mutex);
381
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300382 /* We should never land here with regular DP ports */
383 WARN_ON(!is_edp(intel_dp));
384
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300385 if (intel_dp->pps_pipe != INVALID_PIPE)
386 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300387
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300388 /*
389 * We don't have power sequencer currently.
390 * Pick one that's not used by other ports.
391 */
Jani Nikula19c80542015-12-16 12:48:16 +0200392 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300393 struct intel_dp *tmp;
394
395 if (encoder->type != INTEL_OUTPUT_EDP)
396 continue;
397
398 tmp = enc_to_intel_dp(&encoder->base);
399
400 if (tmp->pps_pipe != INVALID_PIPE)
401 pipes &= ~(1 << tmp->pps_pipe);
402 }
403
404 /*
405 * Didn't find one. This should not happen since there
406 * are two power sequencers and up to two eDP ports.
407 */
408 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300409 pipe = PIPE_A;
410 else
411 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300412
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300413 vlv_steal_power_sequencer(dev, pipe);
414 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300415
416 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
417 pipe_name(intel_dp->pps_pipe),
418 port_name(intel_dig_port->port));
419
420 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300421 intel_dp_init_panel_power_sequencer(dev, intel_dp);
422 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300423
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300424 /*
425 * Even vdd force doesn't work until we've made
426 * the power sequencer lock in on the port.
427 */
428 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300429
430 return intel_dp->pps_pipe;
431}
432
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300433typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
434 enum pipe pipe);
435
436static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
437 enum pipe pipe)
438{
439 return I915_READ(VLV_PIPE_PP_STATUS(pipe)) & PP_ON;
440}
441
442static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
443 enum pipe pipe)
444{
445 return I915_READ(VLV_PIPE_PP_CONTROL(pipe)) & EDP_FORCE_VDD;
446}
447
448static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
449 enum pipe pipe)
450{
451 return true;
452}
453
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300454static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300455vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
456 enum port port,
457 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300458{
Jani Nikulabf13e812013-09-06 07:40:05 +0300459 enum pipe pipe;
460
Jani Nikulabf13e812013-09-06 07:40:05 +0300461 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
462 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
463 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300464
465 if (port_sel != PANEL_PORT_SELECT_VLV(port))
466 continue;
467
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300468 if (!pipe_check(dev_priv, pipe))
469 continue;
470
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300471 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300472 }
473
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300474 return INVALID_PIPE;
475}
476
477static void
478vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
479{
480 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
481 struct drm_device *dev = intel_dig_port->base.base.dev;
482 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300483 enum port port = intel_dig_port->port;
484
485 lockdep_assert_held(&dev_priv->pps_mutex);
486
487 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300488 /* first pick one where the panel is on */
489 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
490 vlv_pipe_has_pp_on);
491 /* didn't find one? pick one where vdd is on */
492 if (intel_dp->pps_pipe == INVALID_PIPE)
493 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
494 vlv_pipe_has_vdd_on);
495 /* didn't find one? pick one with just the correct port */
496 if (intel_dp->pps_pipe == INVALID_PIPE)
497 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
498 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300499
500 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
501 if (intel_dp->pps_pipe == INVALID_PIPE) {
502 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
503 port_name(port));
504 return;
505 }
506
507 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
508 port_name(port), pipe_name(intel_dp->pps_pipe));
509
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300510 intel_dp_init_panel_power_sequencer(dev, intel_dp);
511 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300512}
513
Ville Syrjälä773538e82014-09-04 14:54:56 +0300514void vlv_power_sequencer_reset(struct drm_i915_private *dev_priv)
515{
516 struct drm_device *dev = dev_priv->dev;
517 struct intel_encoder *encoder;
518
Wayne Boyer666a4532015-12-09 12:29:35 -0800519 if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300520 return;
521
522 /*
523 * We can't grab pps_mutex here due to deadlock with power_domain
524 * mutex when power_domain functions are called while holding pps_mutex.
525 * That also means that in order to use pps_pipe the code needs to
526 * hold both a power domain reference and pps_mutex, and the power domain
527 * reference get/put must be done while _not_ holding pps_mutex.
528 * pps_{lock,unlock}() do these steps in the correct order, so one
529 * should use them always.
530 */
531
Jani Nikula19c80542015-12-16 12:48:16 +0200532 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300533 struct intel_dp *intel_dp;
534
535 if (encoder->type != INTEL_OUTPUT_EDP)
536 continue;
537
538 intel_dp = enc_to_intel_dp(&encoder->base);
539 intel_dp->pps_pipe = INVALID_PIPE;
540 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300541}
542
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200543static i915_reg_t
544_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300545{
546 struct drm_device *dev = intel_dp_to_dev(intel_dp);
547
Vandana Kannanb0a08be2015-06-18 11:00:55 +0530548 if (IS_BROXTON(dev))
549 return BXT_PP_CONTROL(0);
550 else if (HAS_PCH_SPLIT(dev))
Jani Nikulabf13e812013-09-06 07:40:05 +0300551 return PCH_PP_CONTROL;
552 else
553 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
554}
555
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200556static i915_reg_t
557_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300558{
559 struct drm_device *dev = intel_dp_to_dev(intel_dp);
560
Vandana Kannanb0a08be2015-06-18 11:00:55 +0530561 if (IS_BROXTON(dev))
562 return BXT_PP_STATUS(0);
563 else if (HAS_PCH_SPLIT(dev))
Jani Nikulabf13e812013-09-06 07:40:05 +0300564 return PCH_PP_STATUS;
565 else
566 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
567}
568
Clint Taylor01527b32014-07-07 13:01:46 -0700569/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
570 This function only applicable when panel PM state is not to be tracked */
571static int edp_notify_handler(struct notifier_block *this, unsigned long code,
572 void *unused)
573{
574 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
575 edp_notifier);
576 struct drm_device *dev = intel_dp_to_dev(intel_dp);
577 struct drm_i915_private *dev_priv = dev->dev_private;
Clint Taylor01527b32014-07-07 13:01:46 -0700578
579 if (!is_edp(intel_dp) || code != SYS_RESTART)
580 return 0;
581
Ville Syrjälä773538e82014-09-04 14:54:56 +0300582 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300583
Wayne Boyer666a4532015-12-09 12:29:35 -0800584 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300585 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200586 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300587 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300588
Clint Taylor01527b32014-07-07 13:01:46 -0700589 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
590 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
591 pp_div = I915_READ(pp_div_reg);
592 pp_div &= PP_REFERENCE_DIVIDER_MASK;
593
594 /* 0x1F write to PP_DIV_REG sets max cycle delay */
595 I915_WRITE(pp_div_reg, pp_div | 0x1F);
596 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
597 msleep(intel_dp->panel_power_cycle_delay);
598 }
599
Ville Syrjälä773538e82014-09-04 14:54:56 +0300600 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300601
Clint Taylor01527b32014-07-07 13:01:46 -0700602 return 0;
603}
604
Daniel Vetter4be73782014-01-17 14:39:48 +0100605static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700606{
Paulo Zanoni30add222012-10-26 19:05:45 -0200607 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700608 struct drm_i915_private *dev_priv = dev->dev_private;
609
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300610 lockdep_assert_held(&dev_priv->pps_mutex);
611
Wayne Boyer666a4532015-12-09 12:29:35 -0800612 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300613 intel_dp->pps_pipe == INVALID_PIPE)
614 return false;
615
Jani Nikulabf13e812013-09-06 07:40:05 +0300616 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700617}
618
Daniel Vetter4be73782014-01-17 14:39:48 +0100619static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700620{
Paulo Zanoni30add222012-10-26 19:05:45 -0200621 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700622 struct drm_i915_private *dev_priv = dev->dev_private;
623
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300624 lockdep_assert_held(&dev_priv->pps_mutex);
625
Wayne Boyer666a4532015-12-09 12:29:35 -0800626 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300627 intel_dp->pps_pipe == INVALID_PIPE)
628 return false;
629
Ville Syrjälä773538e82014-09-04 14:54:56 +0300630 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700631}
632
Keith Packard9b984da2011-09-19 13:54:47 -0700633static void
634intel_dp_check_edp(struct intel_dp *intel_dp)
635{
Paulo Zanoni30add222012-10-26 19:05:45 -0200636 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700637 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700638
Keith Packard9b984da2011-09-19 13:54:47 -0700639 if (!is_edp(intel_dp))
640 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700641
Daniel Vetter4be73782014-01-17 14:39:48 +0100642 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700643 WARN(1, "eDP powered off while attempting aux channel communication.\n");
644 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300645 I915_READ(_pp_stat_reg(intel_dp)),
646 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700647 }
648}
649
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100650static uint32_t
651intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
652{
653 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
654 struct drm_device *dev = intel_dig_port->base.base.dev;
655 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200656 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100657 uint32_t status;
658 bool done;
659
Daniel Vetteref04f002012-12-01 21:03:59 +0100660#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100661 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300662 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300663 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100664 else
665 done = wait_for_atomic(C, 10) == 0;
666 if (!done)
667 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
668 has_aux_irq);
669#undef C
670
671 return status;
672}
673
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200674static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000675{
676 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200677 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000678
Ville Syrjäläa457f542016-03-02 17:22:17 +0200679 if (index)
680 return 0;
681
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000682 /*
683 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200684 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000685 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200686 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000687}
688
689static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
690{
691 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200692 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000693
694 if (index)
695 return 0;
696
Ville Syrjäläa457f542016-03-02 17:22:17 +0200697 /*
698 * The clock divider is based off the cdclk or PCH rawclk, and would
699 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
700 * divide by 2000 and use that
701 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200702 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200703 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200704 else
705 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000706}
707
708static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300709{
710 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200711 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300712
Ville Syrjäläa457f542016-03-02 17:22:17 +0200713 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300714 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100715 switch (index) {
716 case 0: return 63;
717 case 1: return 72;
718 default: return 0;
719 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300720 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200721
722 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300723}
724
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000725static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
726{
727 /*
728 * SKL doesn't need us to program the AUX clock divider (Hardware will
729 * derive the clock from CDCLK automatically). We still implement the
730 * get_aux_clock_divider vfunc to plug-in into the existing code.
731 */
732 return index ? 0 : 1;
733}
734
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200735static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
736 bool has_aux_irq,
737 int send_bytes,
738 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000739{
740 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
741 struct drm_device *dev = intel_dig_port->base.base.dev;
742 uint32_t precharge, timeout;
743
744 if (IS_GEN6(dev))
745 precharge = 3;
746 else
747 precharge = 5;
748
Ville Syrjäläf3c6a3a2015-11-11 20:34:10 +0200749 if (IS_BROADWELL(dev) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000750 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
751 else
752 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
753
754 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000755 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000756 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000757 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000758 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000759 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000760 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
761 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000762 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000763}
764
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000765static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
766 bool has_aux_irq,
767 int send_bytes,
768 uint32_t unused)
769{
770 return DP_AUX_CH_CTL_SEND_BUSY |
771 DP_AUX_CH_CTL_DONE |
772 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
773 DP_AUX_CH_CTL_TIME_OUT_ERROR |
774 DP_AUX_CH_CTL_TIME_OUT_1600us |
775 DP_AUX_CH_CTL_RECEIVE_ERROR |
776 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
777 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
778}
779
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700780static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100781intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200782 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700783 uint8_t *recv, int recv_size)
784{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200785 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
786 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700787 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200788 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100789 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100790 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700791 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000792 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100793 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200794 bool vdd;
795
Ville Syrjälä773538e82014-09-04 14:54:56 +0300796 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300797
Ville Syrjälä72c35002014-08-18 22:16:00 +0300798 /*
799 * We will be called with VDD already enabled for dpcd/edid/oui reads.
800 * In such cases we want to leave VDD enabled and it's up to upper layers
801 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
802 * ourselves.
803 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300804 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100805
806 /* dp aux is extremely sensitive to irq latency, hence request the
807 * lowest possible wakeup latency and so prevent the cpu from going into
808 * deep sleep states.
809 */
810 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700811
Keith Packard9b984da2011-09-19 13:54:47 -0700812 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800813
Jesse Barnes11bee432011-08-01 15:02:20 -0700814 /* Try to wait for any previous AUX channel activity */
815 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100816 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700817 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
818 break;
819 msleep(1);
820 }
821
822 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300823 static u32 last_status = -1;
824 const u32 status = I915_READ(ch_ctl);
825
826 if (status != last_status) {
827 WARN(1, "dp_aux_ch not started status 0x%08x\n",
828 status);
829 last_status = status;
830 }
831
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100832 ret = -EBUSY;
833 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100834 }
835
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300836 /* Only 5 data registers! */
837 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
838 ret = -E2BIG;
839 goto out;
840 }
841
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000842 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000843 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
844 has_aux_irq,
845 send_bytes,
846 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000847
Chris Wilsonbc866252013-07-21 16:00:03 +0100848 /* Must try at least 3 times according to DP spec */
849 for (try = 0; try < 5; try++) {
850 /* Load the send data into the aux channel data registers */
851 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200852 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800853 intel_dp_pack_aux(send + i,
854 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400855
Chris Wilsonbc866252013-07-21 16:00:03 +0100856 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000857 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100858
Chris Wilsonbc866252013-07-21 16:00:03 +0100859 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400860
Chris Wilsonbc866252013-07-21 16:00:03 +0100861 /* Clear done status and any errors */
862 I915_WRITE(ch_ctl,
863 status |
864 DP_AUX_CH_CTL_DONE |
865 DP_AUX_CH_CTL_TIME_OUT_ERROR |
866 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400867
Todd Previte74ebf292015-04-15 08:38:41 -0700868 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +0100869 continue;
Todd Previte74ebf292015-04-15 08:38:41 -0700870
871 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
872 * 400us delay required for errors and timeouts
873 * Timeout errors from the HW already meet this
874 * requirement so skip to next iteration
875 */
876 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
877 usleep_range(400, 500);
878 continue;
879 }
Chris Wilsonbc866252013-07-21 16:00:03 +0100880 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -0700881 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +0100882 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700883 }
884
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700885 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700886 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100887 ret = -EBUSY;
888 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700889 }
890
Jim Bridee058c942015-05-27 10:21:48 -0700891done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700892 /* Check for timeout or receive error.
893 * Timeouts occur when the sink is not connected
894 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700895 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700896 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100897 ret = -EIO;
898 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700899 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700900
901 /* Timeouts occur when the device isn't connected, so they're
902 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700903 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800904 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100905 ret = -ETIMEDOUT;
906 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700907 }
908
909 /* Unload any bytes sent back from the other side */
910 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
911 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -0800912
913 /*
914 * By BSpec: "Message sizes of 0 or >20 are not allowed."
915 * We have no idea of what happened so we return -EBUSY so
916 * drm layer takes care for the necessary retries.
917 */
918 if (recv_bytes == 0 || recv_bytes > 20) {
919 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
920 recv_bytes);
921 /*
922 * FIXME: This patch was created on top of a series that
923 * organize the retries at drm level. There EBUSY should
924 * also take care for 1ms wait before retrying.
925 * That aux retries re-org is still needed and after that is
926 * merged we remove this sleep from here.
927 */
928 usleep_range(1000, 1500);
929 ret = -EBUSY;
930 goto out;
931 }
932
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700933 if (recv_bytes > recv_size)
934 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400935
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100936 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200937 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800938 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700939
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100940 ret = recv_bytes;
941out:
942 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
943
Jani Nikula884f19e2014-03-14 16:51:14 +0200944 if (vdd)
945 edp_panel_vdd_off(intel_dp, false);
946
Ville Syrjälä773538e82014-09-04 14:54:56 +0300947 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300948
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100949 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700950}
951
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300952#define BARE_ADDRESS_SIZE 3
953#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +0200954static ssize_t
955intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700956{
Jani Nikula9d1a1032014-03-14 16:51:15 +0200957 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
958 uint8_t txbuf[20], rxbuf[20];
959 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700960 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700961
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +0200962 txbuf[0] = (msg->request << 4) |
963 ((msg->address >> 16) & 0xf);
964 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +0200965 txbuf[2] = msg->address & 0xff;
966 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300967
Jani Nikula9d1a1032014-03-14 16:51:15 +0200968 switch (msg->request & ~DP_AUX_I2C_MOT) {
969 case DP_AUX_NATIVE_WRITE:
970 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +0300971 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300972 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +0200973 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +0200974
Jani Nikula9d1a1032014-03-14 16:51:15 +0200975 if (WARN_ON(txsize > 20))
976 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700977
Imre Deakd81a67c2016-01-29 14:52:26 +0200978 if (msg->buffer)
979 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
980 else
981 WARN_ON(msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700982
Jani Nikula9d1a1032014-03-14 16:51:15 +0200983 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
984 if (ret > 0) {
985 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700986
Jani Nikulaa1ddefd2015-03-17 17:18:54 +0200987 if (ret > 1) {
988 /* Number of bytes written in a short write. */
989 ret = clamp_t(int, rxbuf[1], 0, msg->size);
990 } else {
991 /* Return payload size. */
992 ret = msg->size;
993 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700994 }
Jani Nikula9d1a1032014-03-14 16:51:15 +0200995 break;
996
997 case DP_AUX_NATIVE_READ:
998 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300999 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001000 rxsize = msg->size + 1;
1001
1002 if (WARN_ON(rxsize > 20))
1003 return -E2BIG;
1004
1005 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1006 if (ret > 0) {
1007 msg->reply = rxbuf[0] >> 4;
1008 /*
1009 * Assume happy day, and copy the data. The caller is
1010 * expected to check msg->reply before touching it.
1011 *
1012 * Return payload size.
1013 */
1014 ret--;
1015 memcpy(msg->buffer, rxbuf + 1, ret);
1016 }
1017 break;
1018
1019 default:
1020 ret = -EINVAL;
1021 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001022 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001023
Jani Nikula9d1a1032014-03-14 16:51:15 +02001024 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001025}
1026
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001027static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1028 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001029{
1030 switch (port) {
1031 case PORT_B:
1032 case PORT_C:
1033 case PORT_D:
1034 return DP_AUX_CH_CTL(port);
1035 default:
1036 MISSING_CASE(port);
1037 return DP_AUX_CH_CTL(PORT_B);
1038 }
1039}
1040
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001041static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1042 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001043{
1044 switch (port) {
1045 case PORT_B:
1046 case PORT_C:
1047 case PORT_D:
1048 return DP_AUX_CH_DATA(port, index);
1049 default:
1050 MISSING_CASE(port);
1051 return DP_AUX_CH_DATA(PORT_B, index);
1052 }
1053}
1054
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001055static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1056 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001057{
1058 switch (port) {
1059 case PORT_A:
1060 return DP_AUX_CH_CTL(port);
1061 case PORT_B:
1062 case PORT_C:
1063 case PORT_D:
1064 return PCH_DP_AUX_CH_CTL(port);
1065 default:
1066 MISSING_CASE(port);
1067 return DP_AUX_CH_CTL(PORT_A);
1068 }
1069}
1070
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001071static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1072 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001073{
1074 switch (port) {
1075 case PORT_A:
1076 return DP_AUX_CH_DATA(port, index);
1077 case PORT_B:
1078 case PORT_C:
1079 case PORT_D:
1080 return PCH_DP_AUX_CH_DATA(port, index);
1081 default:
1082 MISSING_CASE(port);
1083 return DP_AUX_CH_DATA(PORT_A, index);
1084 }
1085}
1086
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001087/*
1088 * On SKL we don't have Aux for port E so we rely
1089 * on VBT to set a proper alternate aux channel.
1090 */
1091static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
1092{
1093 const struct ddi_vbt_port_info *info =
1094 &dev_priv->vbt.ddi_port_info[PORT_E];
1095
1096 switch (info->alternate_aux_channel) {
1097 case DP_AUX_A:
1098 return PORT_A;
1099 case DP_AUX_B:
1100 return PORT_B;
1101 case DP_AUX_C:
1102 return PORT_C;
1103 case DP_AUX_D:
1104 return PORT_D;
1105 default:
1106 MISSING_CASE(info->alternate_aux_channel);
1107 return PORT_A;
1108 }
1109}
1110
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001111static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1112 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001113{
1114 if (port == PORT_E)
1115 port = skl_porte_aux_port(dev_priv);
1116
1117 switch (port) {
1118 case PORT_A:
1119 case PORT_B:
1120 case PORT_C:
1121 case PORT_D:
1122 return DP_AUX_CH_CTL(port);
1123 default:
1124 MISSING_CASE(port);
1125 return DP_AUX_CH_CTL(PORT_A);
1126 }
1127}
1128
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001129static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1130 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001131{
1132 if (port == PORT_E)
1133 port = skl_porte_aux_port(dev_priv);
1134
1135 switch (port) {
1136 case PORT_A:
1137 case PORT_B:
1138 case PORT_C:
1139 case PORT_D:
1140 return DP_AUX_CH_DATA(port, index);
1141 default:
1142 MISSING_CASE(port);
1143 return DP_AUX_CH_DATA(PORT_A, index);
1144 }
1145}
1146
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001147static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1148 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001149{
1150 if (INTEL_INFO(dev_priv)->gen >= 9)
1151 return skl_aux_ctl_reg(dev_priv, port);
1152 else if (HAS_PCH_SPLIT(dev_priv))
1153 return ilk_aux_ctl_reg(dev_priv, port);
1154 else
1155 return g4x_aux_ctl_reg(dev_priv, port);
1156}
1157
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001158static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1159 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001160{
1161 if (INTEL_INFO(dev_priv)->gen >= 9)
1162 return skl_aux_data_reg(dev_priv, port, index);
1163 else if (HAS_PCH_SPLIT(dev_priv))
1164 return ilk_aux_data_reg(dev_priv, port, index);
1165 else
1166 return g4x_aux_data_reg(dev_priv, port, index);
1167}
1168
1169static void intel_aux_reg_init(struct intel_dp *intel_dp)
1170{
1171 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1172 enum port port = dp_to_dig_port(intel_dp)->port;
1173 int i;
1174
1175 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1176 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1177 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1178}
1179
Jani Nikula9d1a1032014-03-14 16:51:15 +02001180static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001181intel_dp_aux_fini(struct intel_dp *intel_dp)
1182{
1183 drm_dp_aux_unregister(&intel_dp->aux);
1184 kfree(intel_dp->aux.name);
1185}
1186
1187static int
Jani Nikula9d1a1032014-03-14 16:51:15 +02001188intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001189{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001190 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jani Nikula33ad6622014-03-14 16:51:16 +02001191 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1192 enum port port = intel_dig_port->port;
Dave Airlieab2c0672009-12-04 10:55:24 +10001193 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001194
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001195 intel_aux_reg_init(intel_dp);
David Flynn8316f332010-12-08 16:10:21 +00001196
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001197 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
1198 if (!intel_dp->aux.name)
1199 return -ENOMEM;
1200
Jani Nikula9d1a1032014-03-14 16:51:15 +02001201 intel_dp->aux.dev = dev->dev;
1202 intel_dp->aux.transfer = intel_dp_aux_transfer;
David Flynn8316f332010-12-08 16:10:21 +00001203
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001204 DRM_DEBUG_KMS("registering %s bus for %s\n",
1205 intel_dp->aux.name,
Jani Nikula0b998362014-03-14 16:51:17 +02001206 connector->base.kdev->kobj.name);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001207
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001208 ret = drm_dp_aux_register(&intel_dp->aux);
Jani Nikula0b998362014-03-14 16:51:17 +02001209 if (ret < 0) {
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001210 DRM_ERROR("drm_dp_aux_register() for %s failed (%d)\n",
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001211 intel_dp->aux.name, ret);
1212 kfree(intel_dp->aux.name);
1213 return ret;
Dave Airlieab2c0672009-12-04 10:55:24 +10001214 }
David Flynn8316f332010-12-08 16:10:21 +00001215
Jani Nikula0b998362014-03-14 16:51:17 +02001216 ret = sysfs_create_link(&connector->base.kdev->kobj,
1217 &intel_dp->aux.ddc.dev.kobj,
1218 intel_dp->aux.ddc.dev.kobj.name);
1219 if (ret < 0) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001220 DRM_ERROR("sysfs_create_link() for %s failed (%d)\n",
1221 intel_dp->aux.name, ret);
1222 intel_dp_aux_fini(intel_dp);
1223 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001224 }
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001225
1226 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001227}
1228
Imre Deak80f65de2014-02-11 17:12:49 +02001229static void
1230intel_dp_connector_unregister(struct intel_connector *intel_connector)
1231{
1232 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
1233
Dave Airlie0e32b392014-05-02 14:02:48 +10001234 if (!intel_connector->mst_port)
1235 sysfs_remove_link(&intel_connector->base.kdev->kobj,
1236 intel_dp->aux.ddc.dev.kobj.name);
Imre Deak80f65de2014-02-11 17:12:49 +02001237 intel_connector_unregister(intel_connector);
1238}
1239
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001240static void
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001241skl_edp_set_pll_config(struct intel_crtc_state *pipe_config)
Damien Lespiau5416d872014-11-14 17:24:33 +00001242{
1243 u32 ctrl1;
1244
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03001245 memset(&pipe_config->dpll_hw_state, 0,
1246 sizeof(pipe_config->dpll_hw_state));
1247
Damien Lespiau5416d872014-11-14 17:24:33 +00001248 pipe_config->ddi_pll_sel = SKL_DPLL0;
1249 pipe_config->dpll_hw_state.cfgcr1 = 0;
1250 pipe_config->dpll_hw_state.cfgcr2 = 0;
1251
1252 ctrl1 = DPLL_CTRL1_OVERRIDE(SKL_DPLL0);
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001253 switch (pipe_config->port_clock / 2) {
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301254 case 81000:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001255 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810,
Damien Lespiau5416d872014-11-14 17:24:33 +00001256 SKL_DPLL0);
1257 break;
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301258 case 135000:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001259 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350,
Damien Lespiau5416d872014-11-14 17:24:33 +00001260 SKL_DPLL0);
1261 break;
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301262 case 270000:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001263 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700,
Damien Lespiau5416d872014-11-14 17:24:33 +00001264 SKL_DPLL0);
1265 break;
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301266 case 162000:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001267 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620,
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301268 SKL_DPLL0);
1269 break;
1270 /* TBD: For DP link rates 2.16 GHz and 4.32 GHz, VCO is 8640 which
1271 results in CDCLK change. Need to handle the change of CDCLK by
1272 disabling pipes and re-enabling them */
1273 case 108000:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001274 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080,
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301275 SKL_DPLL0);
1276 break;
1277 case 216000:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001278 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160,
Sonika Jindalc3346ef2015-02-21 11:12:13 +05301279 SKL_DPLL0);
1280 break;
1281
Damien Lespiau5416d872014-11-14 17:24:33 +00001282 }
1283 pipe_config->dpll_hw_state.ctrl1 = ctrl1;
1284}
1285
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301286static int
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001287intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301288{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001289 if (intel_dp->num_sink_rates) {
1290 *sink_rates = intel_dp->sink_rates;
1291 return intel_dp->num_sink_rates;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301292 }
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001293
1294 *sink_rates = default_rates;
1295
1296 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301297}
1298
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001299bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301300{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001301 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1302 struct drm_device *dev = dig_port->base.base.dev;
1303
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301304 /* WaDisableHBR2:skl */
Jani Nikulae87a0052015-10-20 15:22:02 +03001305 if (IS_SKL_REVID(dev, 0, SKL_REVID_B0))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301306 return false;
1307
1308 if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) ||
1309 (INTEL_INFO(dev)->gen >= 9))
1310 return true;
1311 else
1312 return false;
1313}
1314
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301315static int
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001316intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301317{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001318 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1319 struct drm_device *dev = dig_port->base.base.dev;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301320 int size;
1321
Sonika Jindal64987fc2015-05-26 17:50:13 +05301322 if (IS_BROXTON(dev)) {
1323 *source_rates = bxt_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301324 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001325 } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Sonika Jindal637a9c62015-05-07 09:52:08 +05301326 *source_rates = skl_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301327 size = ARRAY_SIZE(skl_rates);
1328 } else {
1329 *source_rates = default_rates;
1330 size = ARRAY_SIZE(default_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301331 }
Ville Syrjälä636280b2015-03-12 17:10:29 +02001332
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301333 /* This depends on the fact that 5.4 is last value in the array */
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001334 if (!intel_dp_source_supports_hbr2(intel_dp))
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301335 size--;
Ville Syrjälä636280b2015-03-12 17:10:29 +02001336
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301337 return size;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301338}
1339
Daniel Vetter0e503382014-07-04 11:26:04 -03001340static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001341intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001342 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001343{
1344 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001345 const struct dp_link_dpll *divisor = NULL;
1346 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001347
1348 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001349 divisor = gen4_dpll;
1350 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001351 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001352 divisor = pch_dpll;
1353 count = ARRAY_SIZE(pch_dpll);
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001354 } else if (IS_CHERRYVIEW(dev)) {
1355 divisor = chv_dpll;
1356 count = ARRAY_SIZE(chv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001357 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001358 divisor = vlv_dpll;
1359 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001360 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001361
1362 if (divisor && count) {
1363 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001364 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001365 pipe_config->dpll = divisor[i].dpll;
1366 pipe_config->clock_set = true;
1367 break;
1368 }
1369 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001370 }
1371}
1372
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001373static int intersect_rates(const int *source_rates, int source_len,
1374 const int *sink_rates, int sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001375 int *common_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301376{
1377 int i = 0, j = 0, k = 0;
1378
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301379 while (i < source_len && j < sink_len) {
1380 if (source_rates[i] == sink_rates[j]) {
Ville Syrjäläe6bda3e2015-03-12 17:10:37 +02001381 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
1382 return k;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001383 common_rates[k] = source_rates[i];
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301384 ++k;
1385 ++i;
1386 ++j;
1387 } else if (source_rates[i] < sink_rates[j]) {
1388 ++i;
1389 } else {
1390 ++j;
1391 }
1392 }
1393 return k;
1394}
1395
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001396static int intel_dp_common_rates(struct intel_dp *intel_dp,
1397 int *common_rates)
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001398{
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001399 const int *source_rates, *sink_rates;
1400 int source_len, sink_len;
1401
1402 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001403 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001404
1405 return intersect_rates(source_rates, source_len,
1406 sink_rates, sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001407 common_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001408}
1409
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001410static void snprintf_int_array(char *str, size_t len,
1411 const int *array, int nelem)
1412{
1413 int i;
1414
1415 str[0] = '\0';
1416
1417 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001418 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001419 if (r >= len)
1420 return;
1421 str += r;
1422 len -= r;
1423 }
1424}
1425
1426static void intel_dp_print_rates(struct intel_dp *intel_dp)
1427{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001428 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001429 int source_len, sink_len, common_len;
1430 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001431 char str[128]; /* FIXME: too big for stack? */
1432
1433 if ((drm_debug & DRM_UT_KMS) == 0)
1434 return;
1435
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001436 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001437 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1438 DRM_DEBUG_KMS("source rates: %s\n", str);
1439
1440 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1441 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1442 DRM_DEBUG_KMS("sink rates: %s\n", str);
1443
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001444 common_len = intel_dp_common_rates(intel_dp, common_rates);
1445 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1446 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001447}
1448
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001449static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301450{
1451 int i = 0;
1452
1453 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1454 if (find == rates[i])
1455 break;
1456
1457 return i;
1458}
1459
Ville Syrjälä50fec212015-03-12 17:10:34 +02001460int
1461intel_dp_max_link_rate(struct intel_dp *intel_dp)
1462{
1463 int rates[DP_MAX_SUPPORTED_RATES] = {};
1464 int len;
1465
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001466 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001467 if (WARN_ON(len <= 0))
1468 return 162000;
1469
1470 return rates[rate_to_index(0, rates) - 1];
1471}
1472
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001473int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1474{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001475 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001476}
1477
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001478void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1479 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001480{
1481 if (intel_dp->num_sink_rates) {
1482 *link_bw = 0;
1483 *rate_select =
1484 intel_dp_rate_select(intel_dp, port_clock);
1485 } else {
1486 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1487 *rate_select = 0;
1488 }
1489}
1490
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001491bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001492intel_dp_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001493 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001494{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001495 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +01001496 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001497 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001498 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001499 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001500 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001501 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001502 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001503 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001504 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001505 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001506 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301507 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001508 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001509 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001510 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1511 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001512 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301513
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001514 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301515
1516 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001517 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301518
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001519 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001520
Imre Deakbc7d38a2013-05-16 14:40:36 +03001521 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001522 pipe_config->has_pch_encoder = true;
1523
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001524 pipe_config->has_dp_encoder = true;
Vandana Kannanf769cd22014-08-05 07:51:22 -07001525 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001526 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001527
Jani Nikuladd06f902012-10-19 14:51:50 +03001528 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1529 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1530 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001531
1532 if (INTEL_INFO(dev)->gen >= 9) {
1533 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001534 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001535 if (ret)
1536 return ret;
1537 }
1538
Matt Roperb56676272015-11-04 09:05:27 -08001539 if (HAS_GMCH_DISPLAY(dev))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001540 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1541 intel_connector->panel.fitting_mode);
1542 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001543 intel_pch_panel_fitting(intel_crtc, pipe_config,
1544 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001545 }
1546
Daniel Vettercb1793c2012-06-04 18:39:21 +02001547 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001548 return false;
1549
Daniel Vetter083f9562012-04-20 20:23:49 +02001550 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301551 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001552 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001553 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001554
Daniel Vetter36008362013-03-27 00:44:59 +01001555 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1556 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +02001557 bpp = pipe_config->pipe_bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001558 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301559
1560 /* Get bpp from vbt only for panels that dont have bpp in edid */
1561 if (intel_connector->base.display_info.bpc == 0 &&
1562 (dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001563 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1564 dev_priv->vbt.edp_bpp);
1565 bpp = dev_priv->vbt.edp_bpp;
1566 }
1567
Jani Nikula344c5bb2014-09-09 11:25:13 +03001568 /*
1569 * Use the maximum clock and number of lanes the eDP panel
1570 * advertizes being capable of. The panels are generally
1571 * designed to support only a single clock and lane
1572 * configuration, and typically these values correspond to the
1573 * native resolution of the panel.
1574 */
1575 min_lane_count = max_lane_count;
1576 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001577 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001578
Daniel Vetter36008362013-03-27 00:44:59 +01001579 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001580 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1581 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001582
Dave Airliec6930992014-07-14 11:04:39 +10001583 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301584 for (lane_count = min_lane_count;
1585 lane_count <= max_lane_count;
1586 lane_count <<= 1) {
1587
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001588 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001589 link_avail = intel_dp_max_data_rate(link_clock,
1590 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001591
Daniel Vetter36008362013-03-27 00:44:59 +01001592 if (mode_rate <= link_avail) {
1593 goto found;
1594 }
1595 }
1596 }
1597 }
1598
1599 return false;
1600
1601found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001602 if (intel_dp->color_range_auto) {
1603 /*
1604 * See:
1605 * CEA-861-E - 5.1 Default Encoding Parameters
1606 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1607 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001608 pipe_config->limited_color_range =
1609 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1610 } else {
1611 pipe_config->limited_color_range =
1612 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001613 }
1614
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001615 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301616
Daniel Vetter657445f2013-05-04 10:09:18 +02001617 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001618 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001619
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001620 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1621 &link_bw, &rate_select);
1622
1623 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1624 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001625 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001626 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1627 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001628
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001629 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001630 adjusted_mode->crtc_clock,
1631 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001632 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001633
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301634 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301635 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001636 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301637 intel_link_compute_m_n(bpp, lane_count,
1638 intel_connector->panel.downclock_mode->clock,
1639 pipe_config->port_clock,
1640 &pipe_config->dp_m2_n2);
1641 }
1642
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001643 if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && is_edp(intel_dp))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001644 skl_edp_set_pll_config(pipe_config);
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02001645 else if (IS_BROXTON(dev) || IS_HASWELL(dev) || IS_BROADWELL(dev))
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301646 /* handled in ddi */;
Daniel Vetter0e503382014-07-04 11:26:04 -03001647 else
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001648 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001649
Daniel Vetter36008362013-03-27 00:44:59 +01001650 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001651}
1652
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001653void intel_dp_set_link_params(struct intel_dp *intel_dp,
1654 const struct intel_crtc_state *pipe_config)
1655{
1656 intel_dp->link_rate = pipe_config->port_clock;
1657 intel_dp->lane_count = pipe_config->lane_count;
1658}
1659
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02001660static void intel_dp_prepare(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001661{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001662 struct drm_device *dev = encoder->base.dev;
Keith Packard417e8222011-11-01 19:54:11 -07001663 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001664 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001665 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001666 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03001667 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001668
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001669 intel_dp_set_link_params(intel_dp, crtc->config);
1670
Keith Packard417e8222011-11-01 19:54:11 -07001671 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001672 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001673 *
1674 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001675 * SNB CPU
1676 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001677 * CPT PCH
1678 *
1679 * IBX PCH and CPU are the same for almost everything,
1680 * except that the CPU DP PLL is configured in this
1681 * register
1682 *
1683 * CPT PCH is quite different, having many bits moved
1684 * to the TRANS_DP_CTL register instead. That
1685 * configuration happens (oddly) in ironlake_pch_enable
1686 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001687
Keith Packard417e8222011-11-01 19:54:11 -07001688 /* Preserve the BIOS-computed detected bit. This is
1689 * supposed to be read-only.
1690 */
1691 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001692
Keith Packard417e8222011-11-01 19:54:11 -07001693 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001694 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001695 intel_dp->DP |= DP_PORT_WIDTH(crtc->config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001696
Keith Packard417e8222011-11-01 19:54:11 -07001697 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001698
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001699 if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001700 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1701 intel_dp->DP |= DP_SYNC_HS_HIGH;
1702 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1703 intel_dp->DP |= DP_SYNC_VS_HIGH;
1704 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1705
Jani Nikula6aba5b62013-10-04 15:08:10 +03001706 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001707 intel_dp->DP |= DP_ENHANCED_FRAMING;
1708
Daniel Vetter7c62a162013-06-01 17:16:20 +02001709 intel_dp->DP |= crtc->pipe << 29;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001710 } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001711 u32 trans_dp;
1712
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001713 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001714
1715 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1716 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1717 trans_dp |= TRANS_DP_ENH_FRAMING;
1718 else
1719 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1720 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001721 } else {
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001722 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08001723 !IS_CHERRYVIEW(dev) && crtc->config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001724 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001725
1726 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1727 intel_dp->DP |= DP_SYNC_HS_HIGH;
1728 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1729 intel_dp->DP |= DP_SYNC_VS_HIGH;
1730 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1731
Jani Nikula6aba5b62013-10-04 15:08:10 +03001732 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001733 intel_dp->DP |= DP_ENHANCED_FRAMING;
1734
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001735 if (IS_CHERRYVIEW(dev))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001736 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001737 else if (crtc->pipe == PIPE_B)
1738 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001739 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001740}
1741
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001742#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1743#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001744
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001745#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1746#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001747
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001748#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1749#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001750
Daniel Vetter4be73782014-01-17 14:39:48 +01001751static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001752 u32 mask,
1753 u32 value)
1754{
Paulo Zanoni30add222012-10-26 19:05:45 -02001755 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001756 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001757 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001758
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001759 lockdep_assert_held(&dev_priv->pps_mutex);
1760
Jani Nikulabf13e812013-09-06 07:40:05 +03001761 pp_stat_reg = _pp_stat_reg(intel_dp);
1762 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001763
1764 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001765 mask, value,
1766 I915_READ(pp_stat_reg),
1767 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001768
Tvrtko Ursulin3f177622016-03-03 14:36:41 +00001769 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value,
1770 5 * USEC_PER_SEC, 10 * USEC_PER_MSEC))
Keith Packard99ea7122011-11-01 19:57:50 -07001771 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001772 I915_READ(pp_stat_reg),
1773 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001774
1775 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001776}
1777
Daniel Vetter4be73782014-01-17 14:39:48 +01001778static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001779{
1780 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001781 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001782}
1783
Daniel Vetter4be73782014-01-17 14:39:48 +01001784static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001785{
Keith Packardbd943152011-09-18 23:09:52 -07001786 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001787 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001788}
Keith Packardbd943152011-09-18 23:09:52 -07001789
Daniel Vetter4be73782014-01-17 14:39:48 +01001790static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001791{
Abhay Kumard28d4732016-01-22 17:39:04 -08001792 ktime_t panel_power_on_time;
1793 s64 panel_power_off_duration;
1794
Keith Packard99ea7122011-11-01 19:57:50 -07001795 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001796
Abhay Kumard28d4732016-01-22 17:39:04 -08001797 /* take the difference of currrent time and panel power off time
1798 * and then make panel wait for t11_t12 if needed. */
1799 panel_power_on_time = ktime_get_boottime();
1800 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1801
Paulo Zanonidce56b32013-12-19 14:29:40 -02001802 /* When we disable the VDD override bit last we have to do the manual
1803 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001804 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1805 wait_remaining_ms_from_jiffies(jiffies,
1806 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001807
Daniel Vetter4be73782014-01-17 14:39:48 +01001808 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001809}
Keith Packardbd943152011-09-18 23:09:52 -07001810
Daniel Vetter4be73782014-01-17 14:39:48 +01001811static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001812{
1813 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1814 intel_dp->backlight_on_delay);
1815}
1816
Daniel Vetter4be73782014-01-17 14:39:48 +01001817static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001818{
1819 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1820 intel_dp->backlight_off_delay);
1821}
Keith Packard99ea7122011-11-01 19:57:50 -07001822
Keith Packard832dd3c2011-11-01 19:34:06 -07001823/* Read the current pp_control value, unlocking the register if it
1824 * is locked
1825 */
1826
Jesse Barnes453c5422013-03-28 09:55:41 -07001827static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001828{
Jesse Barnes453c5422013-03-28 09:55:41 -07001829 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1830 struct drm_i915_private *dev_priv = dev->dev_private;
1831 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001832
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001833 lockdep_assert_held(&dev_priv->pps_mutex);
1834
Jani Nikulabf13e812013-09-06 07:40:05 +03001835 control = I915_READ(_pp_ctrl_reg(intel_dp));
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301836 if (!IS_BROXTON(dev)) {
1837 control &= ~PANEL_UNLOCK_MASK;
1838 control |= PANEL_UNLOCK_REGS;
1839 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001840 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001841}
1842
Ville Syrjälä951468f2014-09-04 14:55:31 +03001843/*
1844 * Must be paired with edp_panel_vdd_off().
1845 * Must hold pps_mutex around the whole on/off sequence.
1846 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1847 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001848static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001849{
Paulo Zanoni30add222012-10-26 19:05:45 -02001850 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001851 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1852 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Jesse Barnes5d613502011-01-24 17:10:54 -08001853 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak4e6e1a52014-03-27 17:45:11 +02001854 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001855 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001856 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001857 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001858
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001859 lockdep_assert_held(&dev_priv->pps_mutex);
1860
Keith Packard97af61f572011-09-28 16:23:51 -07001861 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001862 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001863
Egbert Eich2c623c12014-11-25 12:54:57 +01001864 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001865 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001866
Daniel Vetter4be73782014-01-17 14:39:48 +01001867 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001868 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001869
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001870 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001871 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001872
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001873 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1874 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001875
Daniel Vetter4be73782014-01-17 14:39:48 +01001876 if (!edp_have_panel_power(intel_dp))
1877 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001878
Jesse Barnes453c5422013-03-28 09:55:41 -07001879 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001880 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001881
Jani Nikulabf13e812013-09-06 07:40:05 +03001882 pp_stat_reg = _pp_stat_reg(intel_dp);
1883 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001884
1885 I915_WRITE(pp_ctrl_reg, pp);
1886 POSTING_READ(pp_ctrl_reg);
1887 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1888 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001889 /*
1890 * If the panel wasn't on, delay before accessing aux channel
1891 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001892 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001893 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1894 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001895 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001896 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001897
1898 return need_to_disable;
1899}
1900
Ville Syrjälä951468f2014-09-04 14:55:31 +03001901/*
1902 * Must be paired with intel_edp_panel_vdd_off() or
1903 * intel_edp_panel_off().
1904 * Nested calls to these functions are not allowed since
1905 * we drop the lock. Caller must use some higher level
1906 * locking to prevent nested calls from other threads.
1907 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001908void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001909{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001910 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001911
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001912 if (!is_edp(intel_dp))
1913 return;
1914
Ville Syrjälä773538e82014-09-04 14:54:56 +03001915 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001916 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001917 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001918
Rob Clarke2c719b2014-12-15 13:56:32 -05001919 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001920 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08001921}
1922
Daniel Vetter4be73782014-01-17 14:39:48 +01001923static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001924{
Paulo Zanoni30add222012-10-26 19:05:45 -02001925 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001926 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001927 struct intel_digital_port *intel_dig_port =
1928 dp_to_dig_port(intel_dp);
1929 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1930 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001931 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001932 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001933
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001934 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01001935
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001936 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001937
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001938 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001939 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001940
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001941 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
1942 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07001943
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001944 pp = ironlake_get_pp_control(intel_dp);
1945 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07001946
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001947 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1948 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001949
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001950 I915_WRITE(pp_ctrl_reg, pp);
1951 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02001952
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001953 /* Make sure sequencer is idle before allowing subsequent activity */
1954 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1955 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001956
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001957 if ((pp & POWER_TARGET_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08001958 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001959
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001960 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001961 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07001962}
1963
Daniel Vetter4be73782014-01-17 14:39:48 +01001964static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07001965{
1966 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1967 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001968
Ville Syrjälä773538e82014-09-04 14:54:56 +03001969 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001970 if (!intel_dp->want_panel_vdd)
1971 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001972 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001973}
1974
Imre Deakaba86892014-07-30 15:57:31 +03001975static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
1976{
1977 unsigned long delay;
1978
1979 /*
1980 * Queue the timer to fire a long time from now (relative to the power
1981 * down delay) to keep the panel power up across a sequence of
1982 * operations.
1983 */
1984 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
1985 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
1986}
1987
Ville Syrjälä951468f2014-09-04 14:55:31 +03001988/*
1989 * Must be paired with edp_panel_vdd_on().
1990 * Must hold pps_mutex around the whole on/off sequence.
1991 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1992 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001993static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001994{
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001995 struct drm_i915_private *dev_priv =
1996 intel_dp_to_dev(intel_dp)->dev_private;
1997
1998 lockdep_assert_held(&dev_priv->pps_mutex);
1999
Keith Packard97af61f572011-09-28 16:23:51 -07002000 if (!is_edp(intel_dp))
2001 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002002
Rob Clarke2c719b2014-12-15 13:56:32 -05002003 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002004 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002005
Keith Packardbd943152011-09-18 23:09:52 -07002006 intel_dp->want_panel_vdd = false;
2007
Imre Deakaba86892014-07-30 15:57:31 +03002008 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002009 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002010 else
2011 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002012}
2013
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002014static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002015{
Paulo Zanoni30add222012-10-26 19:05:45 -02002016 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002017 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07002018 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002019 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002020
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002021 lockdep_assert_held(&dev_priv->pps_mutex);
2022
Keith Packard97af61f572011-09-28 16:23:51 -07002023 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002024 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002025
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002026 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2027 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002028
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002029 if (WARN(edp_have_panel_power(intel_dp),
2030 "eDP port %c panel power already on\n",
2031 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002032 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002033
Daniel Vetter4be73782014-01-17 14:39:48 +01002034 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002035
Jani Nikulabf13e812013-09-06 07:40:05 +03002036 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002037 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07002038 if (IS_GEN5(dev)) {
2039 /* ILK workaround: disable reset around power sequence */
2040 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002041 I915_WRITE(pp_ctrl_reg, pp);
2042 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002043 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002044
Keith Packard1c0ae802011-09-19 13:59:29 -07002045 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07002046 if (!IS_GEN5(dev))
2047 pp |= PANEL_POWER_RESET;
2048
Jesse Barnes453c5422013-03-28 09:55:41 -07002049 I915_WRITE(pp_ctrl_reg, pp);
2050 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002051
Daniel Vetter4be73782014-01-17 14:39:48 +01002052 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002053 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002054
Keith Packard05ce1a42011-09-29 16:33:01 -07002055 if (IS_GEN5(dev)) {
2056 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002057 I915_WRITE(pp_ctrl_reg, pp);
2058 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002059 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002060}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002061
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002062void intel_edp_panel_on(struct intel_dp *intel_dp)
2063{
2064 if (!is_edp(intel_dp))
2065 return;
2066
2067 pps_lock(intel_dp);
2068 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002069 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002070}
2071
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002072
2073static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002074{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002075 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2076 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002077 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002078 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak4e6e1a52014-03-27 17:45:11 +02002079 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002080 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002081 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002082
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002083 lockdep_assert_held(&dev_priv->pps_mutex);
2084
Keith Packard97af61f572011-09-28 16:23:51 -07002085 if (!is_edp(intel_dp))
2086 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002087
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002088 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2089 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002090
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002091 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2092 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002093
Jesse Barnes453c5422013-03-28 09:55:41 -07002094 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002095 /* We need to switch off panel power _and_ force vdd, for otherwise some
2096 * panels get very unhappy and cease to work. */
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002097 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
2098 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002099
Jani Nikulabf13e812013-09-06 07:40:05 +03002100 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002101
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002102 intel_dp->want_panel_vdd = false;
2103
Jesse Barnes453c5422013-03-28 09:55:41 -07002104 I915_WRITE(pp_ctrl_reg, pp);
2105 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002106
Abhay Kumard28d4732016-01-22 17:39:04 -08002107 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002108 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002109
2110 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002111 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002112 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002113}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002114
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002115void intel_edp_panel_off(struct intel_dp *intel_dp)
2116{
2117 if (!is_edp(intel_dp))
2118 return;
2119
2120 pps_lock(intel_dp);
2121 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002122 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002123}
2124
Jani Nikula1250d102014-08-12 17:11:39 +03002125/* Enable backlight in the panel power control. */
2126static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002127{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002128 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2129 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002130 struct drm_i915_private *dev_priv = dev->dev_private;
2131 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002132 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002133
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002134 /*
2135 * If we enable the backlight right away following a panel power
2136 * on, we may see slight flicker as the panel syncs with the eDP
2137 * link. So delay a bit to make sure the image is solid before
2138 * allowing it to appear.
2139 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002140 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002141
Ville Syrjälä773538e82014-09-04 14:54:56 +03002142 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002143
Jesse Barnes453c5422013-03-28 09:55:41 -07002144 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002145 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002146
Jani Nikulabf13e812013-09-06 07:40:05 +03002147 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002148
2149 I915_WRITE(pp_ctrl_reg, pp);
2150 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002151
Ville Syrjälä773538e82014-09-04 14:54:56 +03002152 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002153}
2154
Jani Nikula1250d102014-08-12 17:11:39 +03002155/* Enable backlight PWM and backlight PP control. */
2156void intel_edp_backlight_on(struct intel_dp *intel_dp)
2157{
2158 if (!is_edp(intel_dp))
2159 return;
2160
2161 DRM_DEBUG_KMS("\n");
2162
2163 intel_panel_enable_backlight(intel_dp->attached_connector);
2164 _intel_edp_backlight_on(intel_dp);
2165}
2166
2167/* Disable backlight in the panel power control. */
2168static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002169{
Paulo Zanoni30add222012-10-26 19:05:45 -02002170 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002171 struct drm_i915_private *dev_priv = dev->dev_private;
2172 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002173 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002174
Keith Packardf01eca22011-09-28 16:48:10 -07002175 if (!is_edp(intel_dp))
2176 return;
2177
Ville Syrjälä773538e82014-09-04 14:54:56 +03002178 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002179
Jesse Barnes453c5422013-03-28 09:55:41 -07002180 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002181 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002182
Jani Nikulabf13e812013-09-06 07:40:05 +03002183 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002184
2185 I915_WRITE(pp_ctrl_reg, pp);
2186 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002187
Ville Syrjälä773538e82014-09-04 14:54:56 +03002188 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002189
Paulo Zanonidce56b32013-12-19 14:29:40 -02002190 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002191 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002192}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002193
Jani Nikula1250d102014-08-12 17:11:39 +03002194/* Disable backlight PP control and backlight PWM. */
2195void intel_edp_backlight_off(struct intel_dp *intel_dp)
2196{
2197 if (!is_edp(intel_dp))
2198 return;
2199
2200 DRM_DEBUG_KMS("\n");
2201
2202 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002203 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002204}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002205
Jani Nikula73580fb72014-08-12 17:11:41 +03002206/*
2207 * Hook for controlling the panel power control backlight through the bl_power
2208 * sysfs attribute. Take care to handle multiple calls.
2209 */
2210static void intel_edp_backlight_power(struct intel_connector *connector,
2211 bool enable)
2212{
2213 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002214 bool is_enabled;
2215
Ville Syrjälä773538e82014-09-04 14:54:56 +03002216 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002217 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002218 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002219
2220 if (is_enabled == enable)
2221 return;
2222
Jani Nikula23ba9372014-08-27 14:08:43 +03002223 DRM_DEBUG_KMS("panel power control backlight %s\n",
2224 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002225
2226 if (enable)
2227 _intel_edp_backlight_on(intel_dp);
2228 else
2229 _intel_edp_backlight_off(intel_dp);
2230}
2231
Ville Syrjälä64e10772015-10-29 21:26:01 +02002232static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2233{
2234 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2235 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2236 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2237
2238 I915_STATE_WARN(cur_state != state,
2239 "DP port %c state assertion failure (expected %s, current %s)\n",
2240 port_name(dig_port->port),
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_dp_port_disabled(d) assert_dp_port((d), false)
2244
2245static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2246{
2247 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2248
2249 I915_STATE_WARN(cur_state != state,
2250 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002251 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002252}
2253#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2254#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2255
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002256static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002257{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002258 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002259 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2260 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002261
Ville Syrjälä64e10772015-10-29 21:26:01 +02002262 assert_pipe_disabled(dev_priv, crtc->pipe);
2263 assert_dp_port_disabled(intel_dp);
2264 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002265
Ville Syrjäläabfce942015-10-29 21:26:03 +02002266 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
2267 crtc->config->port_clock);
2268
2269 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2270
2271 if (crtc->config->port_clock == 162000)
2272 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2273 else
2274 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2275
2276 I915_WRITE(DP_A, intel_dp->DP);
2277 POSTING_READ(DP_A);
2278 udelay(500);
2279
Daniel Vetter07679352012-09-06 22:15:42 +02002280 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002281
Daniel Vetter07679352012-09-06 22:15:42 +02002282 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002283 POSTING_READ(DP_A);
2284 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002285}
2286
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002287static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002288{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002289 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002290 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2291 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002292
Ville Syrjälä64e10772015-10-29 21:26:01 +02002293 assert_pipe_disabled(dev_priv, crtc->pipe);
2294 assert_dp_port_disabled(intel_dp);
2295 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002296
Ville Syrjäläabfce942015-10-29 21:26:03 +02002297 DRM_DEBUG_KMS("disabling eDP PLL\n");
2298
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002299 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002300
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002301 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002302 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002303 udelay(200);
2304}
2305
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002306/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002307void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002308{
2309 int ret, i;
2310
2311 /* Should have a valid DPCD by this point */
2312 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2313 return;
2314
2315 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002316 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2317 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002318 } else {
2319 /*
2320 * When turning on, we need to retry for 1ms to give the sink
2321 * time to wake up.
2322 */
2323 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002324 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2325 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002326 if (ret == 1)
2327 break;
2328 msleep(1);
2329 }
2330 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002331
2332 if (ret != 1)
2333 DRM_DEBUG_KMS("failed to %s sink power state\n",
2334 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002335}
2336
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002337static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2338 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002339{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002340 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002341 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002342 struct drm_device *dev = encoder->base.dev;
2343 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +02002344 enum intel_display_power_domain power_domain;
2345 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002346 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002347
2348 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002349 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002350 return false;
2351
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002352 ret = false;
2353
Imre Deak6d129be2014-03-05 16:20:54 +02002354 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002355
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002356 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002357 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002358
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002359 if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002360 *pipe = PORT_TO_PIPE_CPT(tmp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002361 } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002362 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002363
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002364 for_each_pipe(dev_priv, p) {
2365 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2366 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2367 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002368 ret = true;
2369
2370 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002371 }
2372 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002373
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002374 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002375 i915_mmio_reg_offset(intel_dp->output_reg));
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002376 } else if (IS_CHERRYVIEW(dev)) {
2377 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2378 } else {
2379 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002380 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002381
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002382 ret = true;
2383
2384out:
2385 intel_display_power_put(dev_priv, power_domain);
2386
2387 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002388}
2389
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002390static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002391 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002392{
2393 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002394 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002395 struct drm_device *dev = encoder->base.dev;
2396 struct drm_i915_private *dev_priv = dev->dev_private;
2397 enum port port = dp_to_dig_port(intel_dp)->port;
2398 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002399
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002400 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002401
2402 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002403
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002404 if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002405 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2406
2407 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002408 flags |= DRM_MODE_FLAG_PHSYNC;
2409 else
2410 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002411
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002412 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002413 flags |= DRM_MODE_FLAG_PVSYNC;
2414 else
2415 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002416 } else {
2417 if (tmp & DP_SYNC_HS_HIGH)
2418 flags |= DRM_MODE_FLAG_PHSYNC;
2419 else
2420 flags |= DRM_MODE_FLAG_NHSYNC;
2421
2422 if (tmp & DP_SYNC_VS_HIGH)
2423 flags |= DRM_MODE_FLAG_PVSYNC;
2424 else
2425 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002426 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002427
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002428 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002429
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002430 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08002431 !IS_CHERRYVIEW(dev) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002432 pipe_config->limited_color_range = true;
2433
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002434 pipe_config->has_dp_encoder = true;
2435
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002436 pipe_config->lane_count =
2437 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2438
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002439 intel_dp_get_m_n(crtc, pipe_config);
2440
Ville Syrjälä18442d02013-09-13 16:00:08 +03002441 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002442 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002443 pipe_config->port_clock = 162000;
2444 else
2445 pipe_config->port_clock = 270000;
2446 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002447
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002448 pipe_config->base.adjusted_mode.crtc_clock =
2449 intel_dotclock_calculate(pipe_config->port_clock,
2450 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002451
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002452 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
2453 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
2454 /*
2455 * This is a big fat ugly hack.
2456 *
2457 * Some machines in UEFI boot mode provide us a VBT that has 18
2458 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2459 * unknown we fail to light up. Yet the same BIOS boots up with
2460 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2461 * max, not what it tells us to use.
2462 *
2463 * Note: This will still be broken if the eDP panel is not lit
2464 * up by the BIOS, and thus we can't get the mode at module
2465 * load.
2466 */
2467 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2468 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
2469 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
2470 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002471}
2472
Daniel Vettere8cb4552012-07-01 13:05:48 +02002473static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002474{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002475 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002476 struct drm_device *dev = encoder->base.dev;
Jani Nikula495a5bb2014-10-27 16:26:55 +02002477 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
2478
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002479 if (crtc->config->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002480 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002481
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002482 if (HAS_PSR(dev) && !HAS_DDI(dev))
2483 intel_psr_disable(intel_dp);
2484
Daniel Vetter6cb49832012-05-20 17:14:50 +02002485 /* Make sure the panel is off before trying to change the mode. But also
2486 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002487 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002488 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002489 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002490 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002491
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002492 /* disable the port before the pipe on g4x */
2493 if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002494 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002495}
2496
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002497static void ilk_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002498{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002499 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002500 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002501
Ville Syrjälä49277c32014-03-31 18:21:26 +03002502 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002503
2504 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002505 if (port == PORT_A)
2506 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002507}
2508
2509static void vlv_post_disable_dp(struct intel_encoder *encoder)
2510{
2511 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2512
2513 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002514}
2515
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002516static void chv_data_lane_soft_reset(struct intel_encoder *encoder,
2517 bool reset)
2518{
2519 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2520 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
2521 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
2522 enum pipe pipe = crtc->pipe;
2523 uint32_t val;
2524
2525 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
2526 if (reset)
2527 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
2528 else
2529 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
2530 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
2531
2532 if (crtc->config->lane_count > 2) {
2533 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
2534 if (reset)
2535 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
2536 else
2537 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
2538 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
2539 }
2540
2541 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
2542 val |= CHV_PCS_REQ_SOFTRESET_EN;
2543 if (reset)
2544 val &= ~DPIO_PCS_CLK_SOFT_RESET;
2545 else
2546 val |= DPIO_PCS_CLK_SOFT_RESET;
2547 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
2548
2549 if (crtc->config->lane_count > 2) {
2550 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
2551 val |= CHV_PCS_REQ_SOFTRESET_EN;
2552 if (reset)
2553 val &= ~DPIO_PCS_CLK_SOFT_RESET;
2554 else
2555 val |= DPIO_PCS_CLK_SOFT_RESET;
2556 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
2557 }
2558}
2559
Ville Syrjälä580d3812014-04-09 13:29:00 +03002560static void chv_post_disable_dp(struct intel_encoder *encoder)
2561{
2562 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002563 struct drm_device *dev = encoder->base.dev;
2564 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä580d3812014-04-09 13:29:00 +03002565
2566 intel_dp_link_down(intel_dp);
2567
Ville Syrjäläa5805162015-05-26 20:42:30 +03002568 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002569
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002570 /* Assert data lane reset */
2571 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002572
Ville Syrjäläa5805162015-05-26 20:42:30 +03002573 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002574}
2575
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002576static void
2577_intel_dp_set_link_train(struct intel_dp *intel_dp,
2578 uint32_t *DP,
2579 uint8_t dp_train_pat)
2580{
2581 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2582 struct drm_device *dev = intel_dig_port->base.base.dev;
2583 struct drm_i915_private *dev_priv = dev->dev_private;
2584 enum port port = intel_dig_port->port;
2585
2586 if (HAS_DDI(dev)) {
2587 uint32_t temp = I915_READ(DP_TP_CTL(port));
2588
2589 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2590 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2591 else
2592 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2593
2594 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2595 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2596 case DP_TRAINING_PATTERN_DISABLE:
2597 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2598
2599 break;
2600 case DP_TRAINING_PATTERN_1:
2601 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2602 break;
2603 case DP_TRAINING_PATTERN_2:
2604 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2605 break;
2606 case DP_TRAINING_PATTERN_3:
2607 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2608 break;
2609 }
2610 I915_WRITE(DP_TP_CTL(port), temp);
2611
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002612 } else if ((IS_GEN7(dev) && port == PORT_A) ||
2613 (HAS_PCH_CPT(dev) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002614 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2615
2616 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2617 case DP_TRAINING_PATTERN_DISABLE:
2618 *DP |= DP_LINK_TRAIN_OFF_CPT;
2619 break;
2620 case DP_TRAINING_PATTERN_1:
2621 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2622 break;
2623 case DP_TRAINING_PATTERN_2:
2624 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2625 break;
2626 case DP_TRAINING_PATTERN_3:
2627 DRM_ERROR("DP training pattern 3 not supported\n");
2628 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2629 break;
2630 }
2631
2632 } else {
2633 if (IS_CHERRYVIEW(dev))
2634 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2635 else
2636 *DP &= ~DP_LINK_TRAIN_MASK;
2637
2638 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2639 case DP_TRAINING_PATTERN_DISABLE:
2640 *DP |= DP_LINK_TRAIN_OFF;
2641 break;
2642 case DP_TRAINING_PATTERN_1:
2643 *DP |= DP_LINK_TRAIN_PAT_1;
2644 break;
2645 case DP_TRAINING_PATTERN_2:
2646 *DP |= DP_LINK_TRAIN_PAT_2;
2647 break;
2648 case DP_TRAINING_PATTERN_3:
2649 if (IS_CHERRYVIEW(dev)) {
2650 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2651 } else {
2652 DRM_ERROR("DP training pattern 3 not supported\n");
2653 *DP |= DP_LINK_TRAIN_PAT_2;
2654 }
2655 break;
2656 }
2657 }
2658}
2659
2660static void intel_dp_enable_port(struct intel_dp *intel_dp)
2661{
2662 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2663 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002664 struct intel_crtc *crtc =
2665 to_intel_crtc(dp_to_dig_port(intel_dp)->base.base.crtc);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002666
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002667 /* enable with pattern 1 (as per spec) */
2668 _intel_dp_set_link_train(intel_dp, &intel_dp->DP,
2669 DP_TRAINING_PATTERN_1);
2670
2671 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2672 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002673
2674 /*
2675 * Magic for VLV/CHV. We _must_ first set up the register
2676 * without actually enabling the port, and then do another
2677 * write to enable the port. Otherwise link training will
2678 * fail when the power sequencer is freshly used for this port.
2679 */
2680 intel_dp->DP |= DP_PORT_EN;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002681 if (crtc->config->has_audio)
2682 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002683
2684 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2685 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002686}
2687
Daniel Vettere8cb4552012-07-01 13:05:48 +02002688static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002689{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002690 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2691 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002692 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulac1dec792014-10-27 16:26:56 +02002693 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002694 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002695 enum port port = dp_to_dig_port(intel_dp)->port;
2696 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002697
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002698 if (WARN_ON(dp_reg & DP_PORT_EN))
2699 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002700
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002701 pps_lock(intel_dp);
2702
Wayne Boyer666a4532015-12-09 12:29:35 -08002703 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002704 vlv_init_panel_power_sequencer(intel_dp);
2705
Ville Syrjälä78645782015-11-20 22:09:19 +02002706 /*
2707 * We get an occasional spurious underrun between the port
2708 * enable and vdd enable, when enabling port A eDP.
2709 *
2710 * FIXME: Not sure if this applies to (PCH) port D eDP as well
2711 */
2712 if (port == PORT_A)
2713 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2714
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002715 intel_dp_enable_port(intel_dp);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002716
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002717 if (port == PORT_A && IS_GEN5(dev_priv)) {
2718 /*
2719 * Underrun reporting for the other pipe was disabled in
2720 * g4x_pre_enable_dp(). The eDP PLL and port have now been
2721 * enabled, so it's now safe to re-enable underrun reporting.
2722 */
2723 intel_wait_for_vblank_if_active(dev_priv->dev, !pipe);
2724 intel_set_cpu_fifo_underrun_reporting(dev_priv, !pipe, true);
2725 intel_set_pch_fifo_underrun_reporting(dev_priv, !pipe, true);
2726 }
2727
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002728 edp_panel_vdd_on(intel_dp);
2729 edp_panel_on(intel_dp);
2730 edp_panel_vdd_off(intel_dp, true);
2731
Ville Syrjälä78645782015-11-20 22:09:19 +02002732 if (port == PORT_A)
2733 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2734
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002735 pps_unlock(intel_dp);
2736
Wayne Boyer666a4532015-12-09 12:29:35 -08002737 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002738 unsigned int lane_mask = 0x0;
2739
2740 if (IS_CHERRYVIEW(dev))
2741 lane_mask = intel_dp_unused_lane_mask(crtc->config->lane_count);
2742
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002743 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2744 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002745 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002746
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002747 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2748 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002749 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002750
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002751 if (crtc->config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002752 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002753 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002754 intel_audio_codec_enable(encoder);
2755 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002756}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002757
Jani Nikulaecff4f32013-09-06 07:38:29 +03002758static void g4x_enable_dp(struct intel_encoder *encoder)
2759{
Jani Nikula828f5c62013-09-05 16:44:45 +03002760 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2761
Jani Nikulaecff4f32013-09-06 07:38:29 +03002762 intel_enable_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01002763 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002764}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002765
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002766static void vlv_enable_dp(struct intel_encoder *encoder)
2767{
Jani Nikula828f5c62013-09-05 16:44:45 +03002768 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2769
Daniel Vetter4be73782014-01-17 14:39:48 +01002770 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002771 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002772}
2773
Jani Nikulaecff4f32013-09-06 07:38:29 +03002774static void g4x_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002775{
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002776 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002777 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002778 enum port port = dp_to_dig_port(intel_dp)->port;
2779 enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002780
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002781 intel_dp_prepare(encoder);
2782
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002783 if (port == PORT_A && IS_GEN5(dev_priv)) {
2784 /*
2785 * We get FIFO underruns on the other pipe when
2786 * enabling the CPU eDP PLL, and when enabling CPU
2787 * eDP port. We could potentially avoid the PLL
2788 * underrun with a vblank wait just prior to enabling
2789 * the PLL, but that doesn't appear to help the port
2790 * enable case. Just sweep it all under the rug.
2791 */
2792 intel_set_cpu_fifo_underrun_reporting(dev_priv, !pipe, false);
2793 intel_set_pch_fifo_underrun_reporting(dev_priv, !pipe, false);
2794 }
2795
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002796 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002797 if (port == PORT_A)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002798 ironlake_edp_pll_on(intel_dp);
2799}
2800
Ville Syrjälä83b84592014-10-16 21:29:51 +03002801static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2802{
2803 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2804 struct drm_i915_private *dev_priv = intel_dig_port->base.base.dev->dev_private;
2805 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002806 i915_reg_t pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002807
2808 edp_panel_vdd_off_sync(intel_dp);
2809
2810 /*
2811 * VLV seems to get confused when multiple power seqeuencers
2812 * have the same port selected (even if only one has power/vdd
2813 * enabled). The failure manifests as vlv_wait_port_ready() failing
2814 * CHV on the other hand doesn't seem to mind having the same port
2815 * selected in multiple power seqeuencers, but let's clear the
2816 * port select always when logically disconnecting a power sequencer
2817 * from a port.
2818 */
2819 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2820 pipe_name(pipe), port_name(intel_dig_port->port));
2821 I915_WRITE(pp_on_reg, 0);
2822 POSTING_READ(pp_on_reg);
2823
2824 intel_dp->pps_pipe = INVALID_PIPE;
2825}
2826
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002827static void vlv_steal_power_sequencer(struct drm_device *dev,
2828 enum pipe pipe)
2829{
2830 struct drm_i915_private *dev_priv = dev->dev_private;
2831 struct intel_encoder *encoder;
2832
2833 lockdep_assert_held(&dev_priv->pps_mutex);
2834
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002835 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2836 return;
2837
Jani Nikula19c80542015-12-16 12:48:16 +02002838 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002839 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002840 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002841
2842 if (encoder->type != INTEL_OUTPUT_EDP)
2843 continue;
2844
2845 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002846 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002847
2848 if (intel_dp->pps_pipe != pipe)
2849 continue;
2850
2851 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002852 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002853
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002854 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002855 "stealing pipe %c power sequencer from active eDP port %c\n",
2856 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002857
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002858 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002859 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002860 }
2861}
2862
2863static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2864{
2865 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2866 struct intel_encoder *encoder = &intel_dig_port->base;
2867 struct drm_device *dev = encoder->base.dev;
2868 struct drm_i915_private *dev_priv = dev->dev_private;
2869 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002870
2871 lockdep_assert_held(&dev_priv->pps_mutex);
2872
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002873 if (!is_edp(intel_dp))
2874 return;
2875
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002876 if (intel_dp->pps_pipe == crtc->pipe)
2877 return;
2878
2879 /*
2880 * If another power sequencer was being used on this
2881 * port previously make sure to turn off vdd there while
2882 * we still have control of it.
2883 */
2884 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002885 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002886
2887 /*
2888 * We may be stealing the power
2889 * sequencer from another port.
2890 */
2891 vlv_steal_power_sequencer(dev, crtc->pipe);
2892
2893 /* now it's all ours */
2894 intel_dp->pps_pipe = crtc->pipe;
2895
2896 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2897 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2898
2899 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002900 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2901 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002902}
2903
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002904static void vlv_pre_enable_dp(struct intel_encoder *encoder)
2905{
2906 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2907 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07002908 struct drm_device *dev = encoder->base.dev;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002909 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002910 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08002911 enum dpio_channel port = vlv_dport_to_channel(dport);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002912 int pipe = intel_crtc->pipe;
2913 u32 val;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002914
Ville Syrjäläa5805162015-05-26 20:42:30 +03002915 mutex_lock(&dev_priv->sb_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002916
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002917 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002918 val = 0;
2919 if (pipe)
2920 val |= (1<<21);
2921 else
2922 val &= ~(1<<21);
2923 val |= 0x001000c4;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002924 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
2925 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
2926 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002927
Ville Syrjäläa5805162015-05-26 20:42:30 +03002928 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002929
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002930 intel_enable_dp(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002931}
2932
Jani Nikulaecff4f32013-09-06 07:38:29 +03002933static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002934{
2935 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
2936 struct drm_device *dev = encoder->base.dev;
2937 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002938 struct intel_crtc *intel_crtc =
2939 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08002940 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002941 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002942
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002943 intel_dp_prepare(encoder);
2944
Jesse Barnes89b667f2013-04-18 14:51:36 -07002945 /* Program Tx lane resets to default */
Ville Syrjäläa5805162015-05-26 20:42:30 +03002946 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002947 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07002948 DPIO_PCS_TX_LANE2_RESET |
2949 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002950 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07002951 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
2952 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
2953 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
2954 DPIO_PCS_CLK_SOFT_RESET);
2955
2956 /* Fix up inter-pair skew failure */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002957 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
2958 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
2959 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03002960 mutex_unlock(&dev_priv->sb_lock);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002961}
2962
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002963static void chv_pre_enable_dp(struct intel_encoder *encoder)
2964{
2965 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2966 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2967 struct drm_device *dev = encoder->base.dev;
2968 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002969 struct intel_crtc *intel_crtc =
2970 to_intel_crtc(encoder->base.crtc);
2971 enum dpio_channel ch = vlv_dport_to_channel(dport);
2972 int pipe = intel_crtc->pipe;
Ville Syrjälä2e523e92015-04-10 18:21:27 +03002973 int data, i, stagger;
Ville Syrjälä949c1d42014-04-09 13:28:58 +03002974 u32 val;
2975
Ville Syrjäläa5805162015-05-26 20:42:30 +03002976 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä949c1d42014-04-09 13:28:58 +03002977
Ville Syrjälä570e2a72014-08-18 14:42:46 +03002978 /* allow hardware to manage TX FIFO reset source */
2979 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
2980 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2981 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
2982
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002983 if (intel_crtc->config->lane_count > 2) {
2984 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
2985 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2986 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
2987 }
Ville Syrjälä570e2a72014-08-18 14:42:46 +03002988
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002989 /* Program Tx lane latency optimal setting*/
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002990 for (i = 0; i < intel_crtc->config->lane_count; i++) {
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002991 /* Set the upar bit */
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002992 if (intel_crtc->config->lane_count == 1)
2993 data = 0x0;
2994 else
2995 data = (i == 1) ? 0x0 : 0x1;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002996 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
2997 data << DPIO_UPAR_SHIFT);
2998 }
2999
3000 /* Data lane stagger programming */
Ville Syrjälä2e523e92015-04-10 18:21:27 +03003001 if (intel_crtc->config->port_clock > 270000)
3002 stagger = 0x18;
3003 else if (intel_crtc->config->port_clock > 135000)
3004 stagger = 0xd;
3005 else if (intel_crtc->config->port_clock > 67500)
3006 stagger = 0x7;
3007 else if (intel_crtc->config->port_clock > 33750)
3008 stagger = 0x4;
3009 else
3010 stagger = 0x2;
3011
3012 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
3013 val |= DPIO_TX2_STAGGER_MASK(0x1f);
3014 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
3015
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003016 if (intel_crtc->config->lane_count > 2) {
3017 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
3018 val |= DPIO_TX2_STAGGER_MASK(0x1f);
3019 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
3020 }
Ville Syrjälä2e523e92015-04-10 18:21:27 +03003021
3022 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
3023 DPIO_LANESTAGGER_STRAP(stagger) |
3024 DPIO_LANESTAGGER_STRAP_OVRD |
3025 DPIO_TX1_STAGGER_MASK(0x1f) |
3026 DPIO_TX1_STAGGER_MULT(6) |
3027 DPIO_TX2_STAGGER_MULT(0));
3028
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003029 if (intel_crtc->config->lane_count > 2) {
3030 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
3031 DPIO_LANESTAGGER_STRAP(stagger) |
3032 DPIO_LANESTAGGER_STRAP_OVRD |
3033 DPIO_TX1_STAGGER_MASK(0x1f) |
3034 DPIO_TX1_STAGGER_MULT(7) |
3035 DPIO_TX2_STAGGER_MULT(5));
3036 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003037
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03003038 /* Deassert data lane reset */
3039 chv_data_lane_soft_reset(encoder, false);
3040
Ville Syrjäläa5805162015-05-26 20:42:30 +03003041 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003042
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003043 intel_enable_dp(encoder);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003044
3045 /* Second common lane will stay alive on its own now */
3046 if (dport->release_cl2_override) {
3047 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
3048 dport->release_cl2_override = false;
3049 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003050}
3051
Ville Syrjälä9197c882014-04-09 13:29:05 +03003052static void chv_dp_pre_pll_enable(struct intel_encoder *encoder)
3053{
3054 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
3055 struct drm_device *dev = encoder->base.dev;
3056 struct drm_i915_private *dev_priv = dev->dev_private;
3057 struct intel_crtc *intel_crtc =
3058 to_intel_crtc(encoder->base.crtc);
3059 enum dpio_channel ch = vlv_dport_to_channel(dport);
3060 enum pipe pipe = intel_crtc->pipe;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003061 unsigned int lane_mask =
3062 intel_dp_unused_lane_mask(intel_crtc->config->lane_count);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003063 u32 val;
3064
Ville Syrjälä625695f2014-06-28 02:04:02 +03003065 intel_dp_prepare(encoder);
3066
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003067 /*
3068 * Must trick the second common lane into life.
3069 * Otherwise we can't even access the PLL.
3070 */
3071 if (ch == DPIO_CH0 && pipe == PIPE_B)
3072 dport->release_cl2_override =
3073 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
3074
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003075 chv_phy_powergate_lanes(encoder, true, lane_mask);
3076
Ville Syrjäläa5805162015-05-26 20:42:30 +03003077 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003078
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03003079 /* Assert data lane reset */
3080 chv_data_lane_soft_reset(encoder, true);
3081
Ville Syrjäläb9e5ac32014-05-27 16:30:18 +03003082 /* program left/right clock distribution */
3083 if (pipe != PIPE_B) {
3084 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
3085 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
3086 if (ch == DPIO_CH0)
3087 val |= CHV_BUFLEFTENA1_FORCE;
3088 if (ch == DPIO_CH1)
3089 val |= CHV_BUFRIGHTENA1_FORCE;
3090 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
3091 } else {
3092 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
3093 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
3094 if (ch == DPIO_CH0)
3095 val |= CHV_BUFLEFTENA2_FORCE;
3096 if (ch == DPIO_CH1)
3097 val |= CHV_BUFRIGHTENA2_FORCE;
3098 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
3099 }
3100
Ville Syrjälä9197c882014-04-09 13:29:05 +03003101 /* program clock channel usage */
3102 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
3103 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
3104 if (pipe != PIPE_B)
3105 val &= ~CHV_PCS_USEDCLKCHANNEL;
3106 else
3107 val |= CHV_PCS_USEDCLKCHANNEL;
3108 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
3109
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003110 if (intel_crtc->config->lane_count > 2) {
3111 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
3112 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
3113 if (pipe != PIPE_B)
3114 val &= ~CHV_PCS_USEDCLKCHANNEL;
3115 else
3116 val |= CHV_PCS_USEDCLKCHANNEL;
3117 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
3118 }
Ville Syrjälä9197c882014-04-09 13:29:05 +03003119
3120 /*
3121 * This a a bit weird since generally CL
3122 * matches the pipe, but here we need to
3123 * pick the CL based on the port.
3124 */
3125 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
3126 if (pipe != PIPE_B)
3127 val &= ~CHV_CMN_USEDCLKCHANNEL;
3128 else
3129 val |= CHV_CMN_USEDCLKCHANNEL;
3130 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
3131
Ville Syrjäläa5805162015-05-26 20:42:30 +03003132 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003133}
3134
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003135static void chv_dp_post_pll_disable(struct intel_encoder *encoder)
3136{
3137 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3138 enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
3139 u32 val;
3140
3141 mutex_lock(&dev_priv->sb_lock);
3142
3143 /* disable left/right clock distribution */
3144 if (pipe != PIPE_B) {
3145 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
3146 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
3147 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
3148 } else {
3149 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
3150 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
3151 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
3152 }
3153
3154 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003155
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003156 /*
3157 * Leave the power down bit cleared for at least one
3158 * lane so that chv_powergate_phy_ch() will power
3159 * on something when the channel is otherwise unused.
3160 * When the port is off and the override is removed
3161 * the lanes power down anyway, so otherwise it doesn't
3162 * really matter what the state of power down bits is
3163 * after this.
3164 */
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003165 chv_phy_powergate_lanes(encoder, false, 0x0);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003166}
3167
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003168/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07003169 * Native read with retry for link status and receiver capability reads for
3170 * cases where the sink may still be asleep.
Jani Nikula9d1a1032014-03-14 16:51:15 +02003171 *
3172 * Sinks are *supposed* to come up within 1ms from an off state, but we're also
3173 * supposed to retry 3 times per the spec.
Jesse Barnesdf0c2372011-07-07 11:11:02 -07003174 */
Jani Nikula9d1a1032014-03-14 16:51:15 +02003175static ssize_t
3176intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset,
3177 void *buffer, size_t size)
Jesse Barnesdf0c2372011-07-07 11:11:02 -07003178{
Jani Nikula9d1a1032014-03-14 16:51:15 +02003179 ssize_t ret;
3180 int i;
Jesse Barnesdf0c2372011-07-07 11:11:02 -07003181
Ville Syrjäläf6a19062014-10-16 20:46:09 +03003182 /*
3183 * Sometime we just get the same incorrect byte repeated
3184 * over the entire buffer. Doing just one throw away read
3185 * initially seems to "solve" it.
3186 */
3187 drm_dp_dpcd_read(aux, DP_DPCD_REV, buffer, 1);
3188
Jesse Barnesdf0c2372011-07-07 11:11:02 -07003189 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02003190 ret = drm_dp_dpcd_read(aux, offset, buffer, size);
3191 if (ret == size)
3192 return ret;
Jesse Barnesdf0c2372011-07-07 11:11:02 -07003193 msleep(1);
3194 }
3195
Jani Nikula9d1a1032014-03-14 16:51:15 +02003196 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003197}
3198
3199/*
3200 * Fetch AUX CH registers 0x202 - 0x207 which contain
3201 * link status information
3202 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003203bool
Keith Packard93f62da2011-11-01 19:45:03 -07003204intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003205{
Jani Nikula9d1a1032014-03-14 16:51:15 +02003206 return intel_dp_dpcd_read_wake(&intel_dp->aux,
3207 DP_LANE0_1_STATUS,
3208 link_status,
3209 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003210}
3211
Paulo Zanoni11002442014-06-13 18:45:41 -03003212/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003213uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003214intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003215{
Paulo Zanoni30add222012-10-26 19:05:45 -02003216 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303217 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003218 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003219
Vandana Kannan93147262014-11-18 15:45:29 +05303220 if (IS_BROXTON(dev))
3221 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3222 else if (INTEL_INFO(dev)->gen >= 9) {
Sonika Jindal9e458032015-05-06 17:35:48 +05303223 if (dev_priv->edp_low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303224 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003225 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Wayne Boyer666a4532015-12-09 12:29:35 -08003226 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Sonika Jindalbd600182014-08-08 16:23:41 +05303227 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003228 else if (IS_GEN7(dev) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003230 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303231 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003232 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303233 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003234}
3235
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003236uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003237intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3238{
Paulo Zanoni30add222012-10-26 19:05:45 -02003239 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003240 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003241
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003242 if (INTEL_INFO(dev)->gen >= 9) {
3243 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3244 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3245 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3246 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3247 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3248 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3249 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3251 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003252 default:
3253 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3254 }
3255 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003256 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3258 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3259 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3260 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3261 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3262 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3263 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003264 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303265 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003266 }
Wayne Boyer666a4532015-12-09 12:29:35 -08003267 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003268 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3270 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3272 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3273 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3274 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3275 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003276 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303277 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003278 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03003279 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003280 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3282 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3285 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003286 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003288 }
3289 } else {
3290 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3292 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3294 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3296 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3297 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003298 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003300 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003301 }
3302}
3303
Daniel Vetter5829975c2015-04-16 11:36:52 +02003304static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003305{
3306 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3307 struct drm_i915_private *dev_priv = dev->dev_private;
3308 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08003309 struct intel_crtc *intel_crtc =
3310 to_intel_crtc(dport->base.base.crtc);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003311 unsigned long demph_reg_value, preemph_reg_value,
3312 uniqtranscale_reg_value;
3313 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4607fc2013-11-06 14:36:35 +08003314 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08003315 int pipe = intel_crtc->pipe;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003316
3317 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003319 preemph_reg_value = 0x0004000;
3320 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003322 demph_reg_value = 0x2B405555;
3323 uniqtranscale_reg_value = 0x552AB83A;
3324 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303325 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003326 demph_reg_value = 0x2B404040;
3327 uniqtranscale_reg_value = 0x5548B83A;
3328 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003330 demph_reg_value = 0x2B245555;
3331 uniqtranscale_reg_value = 0x5560B83A;
3332 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303333 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003334 demph_reg_value = 0x2B405555;
3335 uniqtranscale_reg_value = 0x5598DA3A;
3336 break;
3337 default:
3338 return 0;
3339 }
3340 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303341 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003342 preemph_reg_value = 0x0002000;
3343 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303344 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003345 demph_reg_value = 0x2B404040;
3346 uniqtranscale_reg_value = 0x5552B83A;
3347 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303348 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003349 demph_reg_value = 0x2B404848;
3350 uniqtranscale_reg_value = 0x5580B83A;
3351 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303352 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003353 demph_reg_value = 0x2B404040;
3354 uniqtranscale_reg_value = 0x55ADDA3A;
3355 break;
3356 default:
3357 return 0;
3358 }
3359 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003361 preemph_reg_value = 0x0000000;
3362 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303363 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003364 demph_reg_value = 0x2B305555;
3365 uniqtranscale_reg_value = 0x5570B83A;
3366 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303367 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003368 demph_reg_value = 0x2B2B4040;
3369 uniqtranscale_reg_value = 0x55ADDA3A;
3370 break;
3371 default:
3372 return 0;
3373 }
3374 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303375 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003376 preemph_reg_value = 0x0006000;
3377 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303378 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003379 demph_reg_value = 0x1B405555;
3380 uniqtranscale_reg_value = 0x55ADDA3A;
3381 break;
3382 default:
3383 return 0;
3384 }
3385 break;
3386 default:
3387 return 0;
3388 }
3389
Ville Syrjäläa5805162015-05-26 20:42:30 +03003390 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08003391 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
3392 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
3393 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003394 uniqtranscale_reg_value);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08003395 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
3396 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
3397 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
3398 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03003399 mutex_unlock(&dev_priv->sb_lock);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003400
3401 return 0;
3402}
3403
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03003404static bool chv_need_uniq_trans_scale(uint8_t train_set)
3405{
3406 return (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) == DP_TRAIN_PRE_EMPH_LEVEL_0 &&
3407 (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) == DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3408}
3409
Daniel Vetter5829975c2015-04-16 11:36:52 +02003410static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003411{
3412 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3413 struct drm_i915_private *dev_priv = dev->dev_private;
3414 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
3415 struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003416 u32 deemph_reg_value, margin_reg_value, val;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003417 uint8_t train_set = intel_dp->train_set[0];
3418 enum dpio_channel ch = vlv_dport_to_channel(dport);
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003419 enum pipe pipe = intel_crtc->pipe;
3420 int i;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003421
3422 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303423 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003424 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303425 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003426 deemph_reg_value = 128;
3427 margin_reg_value = 52;
3428 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003430 deemph_reg_value = 128;
3431 margin_reg_value = 77;
3432 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303433 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003434 deemph_reg_value = 128;
3435 margin_reg_value = 102;
3436 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303437 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003438 deemph_reg_value = 128;
3439 margin_reg_value = 154;
3440 /* FIXME extra to set for 1200 */
3441 break;
3442 default:
3443 return 0;
3444 }
3445 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303446 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003447 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303448 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003449 deemph_reg_value = 85;
3450 margin_reg_value = 78;
3451 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303452 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003453 deemph_reg_value = 85;
3454 margin_reg_value = 116;
3455 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303456 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003457 deemph_reg_value = 85;
3458 margin_reg_value = 154;
3459 break;
3460 default:
3461 return 0;
3462 }
3463 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303464 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003465 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303466 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003467 deemph_reg_value = 64;
3468 margin_reg_value = 104;
3469 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303470 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003471 deemph_reg_value = 64;
3472 margin_reg_value = 154;
3473 break;
3474 default:
3475 return 0;
3476 }
3477 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303478 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003479 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303480 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003481 deemph_reg_value = 43;
3482 margin_reg_value = 154;
3483 break;
3484 default:
3485 return 0;
3486 }
3487 break;
3488 default:
3489 return 0;
3490 }
3491
Ville Syrjäläa5805162015-05-26 20:42:30 +03003492 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003493
3494 /* Clear calc init */
Ville Syrjälä1966e592014-04-09 13:29:04 +03003495 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
3496 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03003497 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
3498 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03003499 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
3500
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003501 if (intel_crtc->config->lane_count > 2) {
3502 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
3503 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
3504 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
3505 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
3506 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
3507 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003508
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03003509 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
3510 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
3511 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
3512 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
3513
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003514 if (intel_crtc->config->lane_count > 2) {
3515 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
3516 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
3517 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
3518 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
3519 }
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03003520
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003521 /* Program swing deemph */
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003522 for (i = 0; i < intel_crtc->config->lane_count; i++) {
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003523 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
3524 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
3525 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
3526 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
3527 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003528
3529 /* Program swing margin */
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003530 for (i = 0; i < intel_crtc->config->lane_count; i++) {
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003531 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03003532
Ville Syrjälä1fb44502014-06-28 02:04:03 +03003533 val &= ~DPIO_SWING_MARGIN000_MASK;
3534 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03003535
3536 /*
3537 * Supposedly this value shouldn't matter when unique transition
3538 * scale is disabled, but in fact it does matter. Let's just
3539 * always program the same value and hope it's OK.
3540 */
3541 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
3542 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
3543
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003544 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
3545 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003546
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03003547 /*
3548 * The document said it needs to set bit 27 for ch0 and bit 26
3549 * for ch1. Might be a typo in the doc.
3550 * For now, for this unique transition scale selection, set bit
3551 * 27 for ch0 and ch1.
3552 */
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003553 for (i = 0; i < intel_crtc->config->lane_count; i++) {
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003554 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03003555 if (chv_need_uniq_trans_scale(train_set))
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003556 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03003557 else
3558 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
3559 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003560 }
3561
3562 /* Start swing calculation */
Ville Syrjälä1966e592014-04-09 13:29:04 +03003563 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
3564 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
3565 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
3566
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003567 if (intel_crtc->config->lane_count > 2) {
3568 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
3569 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
3570 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
3571 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003572
Ville Syrjäläa5805162015-05-26 20:42:30 +03003573 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003574
3575 return 0;
3576}
3577
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003578static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003579gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003580{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003581 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003582
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003583 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303584 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003585 default:
3586 signal_levels |= DP_VOLTAGE_0_4;
3587 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303588 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003589 signal_levels |= DP_VOLTAGE_0_6;
3590 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303591 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003592 signal_levels |= DP_VOLTAGE_0_8;
3593 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303594 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003595 signal_levels |= DP_VOLTAGE_1_2;
3596 break;
3597 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003598 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303599 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003600 default:
3601 signal_levels |= DP_PRE_EMPHASIS_0;
3602 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303603 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003604 signal_levels |= DP_PRE_EMPHASIS_3_5;
3605 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303606 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003607 signal_levels |= DP_PRE_EMPHASIS_6;
3608 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303609 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003610 signal_levels |= DP_PRE_EMPHASIS_9_5;
3611 break;
3612 }
3613 return signal_levels;
3614}
3615
Zhenyu Wange3421a12010-04-08 09:43:27 +08003616/* Gen6's DP voltage swing and pre-emphasis control */
3617static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003618gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003619{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003620 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3621 DP_TRAIN_PRE_EMPHASIS_MASK);
3622 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303623 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3624 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003625 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303626 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003627 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303628 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3629 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003630 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303631 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3632 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003633 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303634 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3635 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003636 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003637 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003638 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3639 "0x%x\n", signal_levels);
3640 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003641 }
3642}
3643
Keith Packard1a2eb462011-11-16 16:26:07 -08003644/* Gen7's DP voltage swing and pre-emphasis control */
3645static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003646gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003647{
3648 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3649 DP_TRAIN_PRE_EMPHASIS_MASK);
3650 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303651 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003652 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303653 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003654 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303655 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003656 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3657
Sonika Jindalbd600182014-08-08 16:23:41 +05303658 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003659 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303660 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003661 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3662
Sonika Jindalbd600182014-08-08 16:23:41 +05303663 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003664 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303665 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003666 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3667
3668 default:
3669 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3670 "0x%x\n", signal_levels);
3671 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3672 }
3673}
3674
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003675void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003676intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003677{
3678 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003679 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003680 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003681 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003682 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003683 uint8_t train_set = intel_dp->train_set[0];
3684
David Weinehallf8896f52015-06-25 11:11:03 +03003685 if (HAS_DDI(dev)) {
3686 signal_levels = ddi_signal_levels(intel_dp);
3687
3688 if (IS_BROXTON(dev))
3689 signal_levels = 0;
3690 else
3691 mask = DDI_BUF_EMP_MASK;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003692 } else if (IS_CHERRYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003693 signal_levels = chv_signal_levels(intel_dp);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003694 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003695 signal_levels = vlv_signal_levels(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003696 } else if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003697 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003698 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003699 } else if (IS_GEN6(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003700 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003701 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3702 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003703 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003704 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3705 }
3706
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303707 if (mask)
3708 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3709
3710 DRM_DEBUG_KMS("Using vswing level %d\n",
3711 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3712 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3713 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3714 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003715
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003716 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003717
3718 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3719 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003720}
3721
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003722void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003723intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3724 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003725{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003726 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003727 struct drm_i915_private *dev_priv =
3728 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003729
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003730 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003731
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003732 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003733 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003734}
3735
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003736void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003737{
3738 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3739 struct drm_device *dev = intel_dig_port->base.base.dev;
3740 struct drm_i915_private *dev_priv = dev->dev_private;
3741 enum port port = intel_dig_port->port;
3742 uint32_t val;
3743
3744 if (!HAS_DDI(dev))
3745 return;
3746
3747 val = I915_READ(DP_TP_CTL(port));
3748 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3749 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3750 I915_WRITE(DP_TP_CTL(port), val);
3751
3752 /*
3753 * On PORT_A we can have only eDP in SST mode. There the only reason
3754 * we need to set idle transmission mode is to work around a HW issue
3755 * where we enable the pipe while not in idle link-training mode.
3756 * In this case there is requirement to wait for a minimum number of
3757 * idle patterns to be sent.
3758 */
3759 if (port == PORT_A)
3760 return;
3761
3762 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
3763 1))
3764 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3765}
3766
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003767static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003768intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003769{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003770 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003771 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003772 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003773 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003774 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003775 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003776
Daniel Vetterbc76e322014-05-20 22:46:50 +02003777 if (WARN_ON(HAS_DDI(dev)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003778 return;
3779
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003780 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003781 return;
3782
Zhao Yakui28c97732009-10-09 11:39:41 +08003783 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003784
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03003785 if ((IS_GEN7(dev) && port == PORT_A) ||
3786 (HAS_PCH_CPT(dev) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003787 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003788 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003789 } else {
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003790 if (IS_CHERRYVIEW(dev))
3791 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3792 else
3793 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003794 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003795 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003796 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003797 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003798
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003799 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3800 I915_WRITE(intel_dp->output_reg, DP);
3801 POSTING_READ(intel_dp->output_reg);
3802
3803 /*
3804 * HW workaround for IBX, we need to move the port
3805 * to transcoder A after disabling it to allow the
3806 * matching HDMI port to be enabled on transcoder A.
3807 */
3808 if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003809 /*
3810 * We get CPU/PCH FIFO underruns on the other pipe when
3811 * doing the workaround. Sweep them under the rug.
3812 */
3813 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3814 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3815
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003816 /* always enable with pattern 1 (as per spec) */
3817 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3818 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3819 I915_WRITE(intel_dp->output_reg, DP);
3820 POSTING_READ(intel_dp->output_reg);
3821
3822 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003823 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003824 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003825
3826 intel_wait_for_vblank_if_active(dev_priv->dev, PIPE_A);
3827 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3828 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003829 }
3830
Keith Packardf01eca22011-09-28 16:48:10 -07003831 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003832
3833 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003834}
3835
Keith Packard26d61aa2011-07-25 20:01:09 -07003836static bool
3837intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003838{
Rodrigo Vivia031d702013-10-03 16:15:06 -03003839 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3840 struct drm_device *dev = dig_port->base.base.dev;
3841 struct drm_i915_private *dev_priv = dev->dev_private;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05303842 uint8_t rev;
Rodrigo Vivia031d702013-10-03 16:15:06 -03003843
Jani Nikula9d1a1032014-03-14 16:51:15 +02003844 if (intel_dp_dpcd_read_wake(&intel_dp->aux, 0x000, intel_dp->dpcd,
3845 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003846 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003847
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003848 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003849
Adam Jacksonedb39242012-09-18 10:58:49 -04003850 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
3851 return false; /* DPCD not present */
3852
Shobhit Kumar2293bb52013-07-11 18:44:56 -03003853 /* Check if the panel supports PSR */
3854 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
Jani Nikula50003932013-09-20 16:42:17 +03003855 if (is_edp(intel_dp)) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02003856 intel_dp_dpcd_read_wake(&intel_dp->aux, DP_PSR_SUPPORT,
3857 intel_dp->psr_dpcd,
3858 sizeof(intel_dp->psr_dpcd));
Rodrigo Vivia031d702013-10-03 16:15:06 -03003859 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3860 dev_priv->psr.sink_support = true;
Jani Nikula50003932013-09-20 16:42:17 +03003861 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
Rodrigo Vivia031d702013-10-03 16:15:06 -03003862 }
Sonika Jindal474d1ec2015-04-02 11:02:44 +05303863
3864 if (INTEL_INFO(dev)->gen >= 9 &&
3865 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3866 uint8_t frame_sync_cap;
3867
3868 dev_priv->psr.sink_support = true;
3869 intel_dp_dpcd_read_wake(&intel_dp->aux,
3870 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3871 &frame_sync_cap, 1);
3872 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3873 /* PSR2 needs frame sync as well */
3874 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3875 DRM_DEBUG_KMS("PSR2 %s on sink",
3876 dev_priv->psr.psr2_support ? "supported" : "not supported");
3877 }
Jani Nikula50003932013-09-20 16:42:17 +03003878 }
3879
Jani Nikulabc5133d2015-09-03 11:16:07 +03003880 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03003881 yesno(intel_dp_source_supports_hbr2(intel_dp)),
Jani Nikula742f4912015-09-03 11:16:09 +03003882 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
Todd Previte06ea66b2014-01-20 10:19:39 -07003883
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05303884 /* Intermediate frequency support */
3885 if (is_edp(intel_dp) &&
3886 (intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3887 (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_EDP_DPCD_REV, &rev, 1) == 1) &&
3888 (rev >= 0x03)) { /* eDp v1.4 or higher */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003889 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003890 int i;
3891
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05303892 intel_dp_dpcd_read_wake(&intel_dp->aux,
3893 DP_SUPPORTED_LINK_RATES,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003894 sink_rates,
3895 sizeof(sink_rates));
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003896
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003897 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3898 int val = le16_to_cpu(sink_rates[i]);
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003899
3900 if (val == 0)
3901 break;
3902
Sonika Jindalaf77b972015-05-07 13:59:28 +05303903 /* Value read is in kHz while drm clock is saved in deca-kHz */
3904 intel_dp->sink_rates[i] = (val * 200) / 10;
Ville Syrjäläea2d8a42015-03-12 17:10:28 +02003905 }
Ville Syrjälä94ca7192015-03-13 19:40:31 +02003906 intel_dp->num_sink_rates = i;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05303907 }
Ville Syrjälä0336400e2015-03-12 17:10:39 +02003908
3909 intel_dp_print_rates(intel_dp);
3910
Adam Jacksonedb39242012-09-18 10:58:49 -04003911 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3912 DP_DWN_STRM_PORT_PRESENT))
3913 return true; /* native DP sink */
3914
3915 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3916 return true; /* no per-port downstream info */
3917
Jani Nikula9d1a1032014-03-14 16:51:15 +02003918 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3919 intel_dp->downstream_ports,
3920 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003921 return false; /* downstream port status fetch failed */
3922
3923 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003924}
3925
Adam Jackson0d198322012-05-14 16:05:47 -04003926static void
3927intel_dp_probe_oui(struct intel_dp *intel_dp)
3928{
3929 u8 buf[3];
3930
3931 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3932 return;
3933
Jani Nikula9d1a1032014-03-14 16:51:15 +02003934 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003935 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3936 buf[0], buf[1], buf[2]);
3937
Jani Nikula9d1a1032014-03-14 16:51:15 +02003938 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003939 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3940 buf[0], buf[1], buf[2]);
3941}
3942
Dave Airlie0e32b392014-05-02 14:02:48 +10003943static bool
3944intel_dp_probe_mst(struct intel_dp *intel_dp)
3945{
3946 u8 buf[1];
3947
3948 if (!intel_dp->can_mst)
3949 return false;
3950
3951 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3952 return false;
3953
Dave Airlie0e32b392014-05-02 14:02:48 +10003954 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_MSTM_CAP, buf, 1)) {
3955 if (buf[0] & DP_MST_CAP) {
3956 DRM_DEBUG_KMS("Sink is MST capable\n");
3957 intel_dp->is_mst = true;
3958 } else {
3959 DRM_DEBUG_KMS("Sink is not MST capable\n");
3960 intel_dp->is_mst = false;
3961 }
3962 }
Dave Airlie0e32b392014-05-02 14:02:48 +10003963
3964 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3965 return intel_dp->is_mst;
3966}
3967
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003968static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003969{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003970 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003971 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003972 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003973 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003974 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003975 int count = 0;
3976 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003977
3978 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003979 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003980 ret = -EIO;
3981 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003982 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003983
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003984 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003985 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003986 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003987 ret = -EIO;
3988 goto out;
3989 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003990
Rodrigo Vivic6297842015-11-05 10:50:20 -08003991 do {
3992 intel_wait_for_vblank(dev, intel_crtc->pipe);
3993
3994 if (drm_dp_dpcd_readb(&intel_dp->aux,
3995 DP_TEST_SINK_MISC, &buf) < 0) {
3996 ret = -EIO;
3997 goto out;
3998 }
3999 count = buf & DP_TEST_COUNT_MASK;
4000 } while (--attempts && count);
4001
4002 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08004003 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08004004 ret = -ETIMEDOUT;
4005 }
4006
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07004007 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004008 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07004009 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004010}
4011
4012static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
4013{
4014 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08004015 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004016 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
4017 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07004018 int ret;
4019
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004020 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
4021 return -EIO;
4022
4023 if (!(buf & DP_TEST_CRC_SUPPORTED))
4024 return -ENOTTY;
4025
4026 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
4027 return -EIO;
4028
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08004029 if (buf & DP_TEST_SINK_START) {
4030 ret = intel_dp_sink_crc_stop(intel_dp);
4031 if (ret)
4032 return ret;
4033 }
4034
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004035 hsw_disable_ips(intel_crtc);
4036
4037 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
4038 buf | DP_TEST_SINK_START) < 0) {
4039 hsw_enable_ips(intel_crtc);
4040 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004041 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004042
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08004043 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004044 return 0;
4045}
4046
4047int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
4048{
4049 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
4050 struct drm_device *dev = dig_port->base.base.dev;
4051 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
4052 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004053 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004054 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004055
4056 ret = intel_dp_sink_crc_start(intel_dp);
4057 if (ret)
4058 return ret;
4059
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004060 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004061 intel_wait_for_vblank(dev, intel_crtc->pipe);
4062
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07004063 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004064 DP_TEST_SINK_MISC, &buf) < 0) {
4065 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004066 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004067 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07004068 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07004069
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004070 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004071
4072 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08004073 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4074 ret = -ETIMEDOUT;
4075 goto stop;
4076 }
4077
4078 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4079 ret = -EIO;
4080 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004081 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004082
Rodrigo Viviafe0d672015-07-23 16:35:45 -07004083stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07004084 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03004085 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004086}
4087
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004088static bool
4089intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4090{
Jani Nikula9d1a1032014-03-14 16:51:15 +02004091 return intel_dp_dpcd_read_wake(&intel_dp->aux,
4092 DP_DEVICE_SERVICE_IRQ_VECTOR,
4093 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004094}
4095
Dave Airlie0e32b392014-05-02 14:02:48 +10004096static bool
4097intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4098{
4099 int ret;
4100
4101 ret = intel_dp_dpcd_read_wake(&intel_dp->aux,
4102 DP_SINK_COUNT_ESI,
4103 sink_irq_vector, 14);
4104 if (ret != 14)
4105 return false;
4106
4107 return true;
4108}
4109
Todd Previtec5d5ab72015-04-15 08:38:38 -07004110static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004111{
Todd Previtec5d5ab72015-04-15 08:38:38 -07004112 uint8_t test_result = DP_TEST_ACK;
4113 return test_result;
4114}
4115
4116static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4117{
4118 uint8_t test_result = DP_TEST_NAK;
4119 return test_result;
4120}
4121
4122static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4123{
4124 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07004125 struct intel_connector *intel_connector = intel_dp->attached_connector;
4126 struct drm_connector *connector = &intel_connector->base;
4127
4128 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004129 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004130 intel_dp->aux.i2c_defer_count > 6) {
4131 /* Check EDID read for NACKs, DEFERs and corruption
4132 * (DP CTS 1.2 Core r1.1)
4133 * 4.2.2.4 : Failed EDID read, I2C_NAK
4134 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4135 * 4.2.2.6 : EDID corruption detected
4136 * Use failsafe mode for all cases
4137 */
4138 if (intel_dp->aux.i2c_nack_count > 0 ||
4139 intel_dp->aux.i2c_defer_count > 0)
4140 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4141 intel_dp->aux.i2c_nack_count,
4142 intel_dp->aux.i2c_defer_count);
4143 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
4144 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304145 struct edid *block = intel_connector->detect_edid;
4146
4147 /* We have to write the checksum
4148 * of the last block read
4149 */
4150 block += intel_connector->detect_edid->extensions;
4151
Todd Previte559be302015-05-04 07:48:20 -07004152 if (!drm_dp_dpcd_write(&intel_dp->aux,
4153 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304154 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004155 1))
Todd Previte559be302015-05-04 07:48:20 -07004156 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4157
4158 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
4159 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
4160 }
4161
4162 /* Set test active flag here so userspace doesn't interrupt things */
4163 intel_dp->compliance_test_active = 1;
4164
Todd Previtec5d5ab72015-04-15 08:38:38 -07004165 return test_result;
4166}
4167
4168static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4169{
4170 uint8_t test_result = DP_TEST_NAK;
4171 return test_result;
4172}
4173
4174static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4175{
4176 uint8_t response = DP_TEST_NAK;
4177 uint8_t rxdata = 0;
4178 int status = 0;
4179
Todd Previtec5d5ab72015-04-15 08:38:38 -07004180 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
4181 if (status <= 0) {
4182 DRM_DEBUG_KMS("Could not read test request from sink\n");
4183 goto update_status;
4184 }
4185
4186 switch (rxdata) {
4187 case DP_TEST_LINK_TRAINING:
4188 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
4189 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
4190 response = intel_dp_autotest_link_training(intel_dp);
4191 break;
4192 case DP_TEST_LINK_VIDEO_PATTERN:
4193 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
4194 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
4195 response = intel_dp_autotest_video_pattern(intel_dp);
4196 break;
4197 case DP_TEST_LINK_EDID_READ:
4198 DRM_DEBUG_KMS("EDID test requested\n");
4199 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
4200 response = intel_dp_autotest_edid(intel_dp);
4201 break;
4202 case DP_TEST_LINK_PHY_TEST_PATTERN:
4203 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
4204 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
4205 response = intel_dp_autotest_phy_pattern(intel_dp);
4206 break;
4207 default:
4208 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
4209 break;
4210 }
4211
4212update_status:
4213 status = drm_dp_dpcd_write(&intel_dp->aux,
4214 DP_TEST_RESPONSE,
4215 &response, 1);
4216 if (status <= 0)
4217 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004218}
4219
Dave Airlie0e32b392014-05-02 14:02:48 +10004220static int
4221intel_dp_check_mst_status(struct intel_dp *intel_dp)
4222{
4223 bool bret;
4224
4225 if (intel_dp->is_mst) {
4226 u8 esi[16] = { 0 };
4227 int ret = 0;
4228 int retry;
4229 bool handled;
4230 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4231go_again:
4232 if (bret == true) {
4233
4234 /* check link status - esi[10] = 0x200c */
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03004235 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004236 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004237 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4238 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004239 intel_dp_stop_link_train(intel_dp);
4240 }
4241
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004242 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004243 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4244
4245 if (handled) {
4246 for (retry = 0; retry < 3; retry++) {
4247 int wret;
4248 wret = drm_dp_dpcd_write(&intel_dp->aux,
4249 DP_SINK_COUNT_ESI+1,
4250 &esi[1], 3);
4251 if (wret == 3) {
4252 break;
4253 }
4254 }
4255
4256 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4257 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004258 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004259 goto go_again;
4260 }
4261 } else
4262 ret = 0;
4263
4264 return ret;
4265 } else {
4266 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4267 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4268 intel_dp->is_mst = false;
4269 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4270 /* send a hotplug event */
4271 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4272 }
4273 }
4274 return -EINVAL;
4275}
4276
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004277/*
4278 * According to DP spec
4279 * 5.1.2:
4280 * 1. Read DPCD
4281 * 2. Configure link according to Receiver Capabilities
4282 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4283 * 4. Check link status on receipt of hot-plug interrupt
4284 */
Damien Lespiaua5146202015-02-10 19:32:22 +00004285static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01004286intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004287{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004288 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004289 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004290 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07004291 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004292
Dave Airlie5b215bc2014-08-05 10:40:20 +10004293 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4294
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304295 /*
4296 * Clearing compliance test variables to allow capturing
4297 * of values for next automated test request.
4298 */
4299 intel_dp->compliance_test_active = 0;
4300 intel_dp->compliance_test_type = 0;
4301 intel_dp->compliance_test_data = 0;
4302
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02004303 if (!intel_encoder->base.crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004304 return;
4305
Imre Deak1a125d82014-08-18 14:42:46 +03004306 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4307 return;
4308
Keith Packard92fd8fd2011-07-25 19:50:10 -07004309 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07004310 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004311 return;
4312 }
4313
Keith Packard92fd8fd2011-07-25 19:50:10 -07004314 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07004315 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004316 return;
4317 }
4318
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004319 /* Try to read the source of the interrupt */
4320 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4321 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
4322 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004323 drm_dp_dpcd_writeb(&intel_dp->aux,
4324 DP_DEVICE_SERVICE_IRQ_VECTOR,
4325 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004326
4327 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004328 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004329 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4330 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4331 }
4332
Shubhangi Shrivastava14631e92015-10-14 14:56:49 +05304333 /* if link training is requested we should perform it always */
4334 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
4335 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07004336 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03004337 intel_encoder->base.name);
Jesse Barnes33a34e42010-09-08 12:42:02 -07004338 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03004339 intel_dp_stop_link_train(intel_dp);
Jesse Barnes33a34e42010-09-08 12:42:02 -07004340 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004341}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004342
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004343/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004344static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004345intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004346{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004347 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004348 uint8_t type;
4349
4350 if (!intel_dp_get_dpcd(intel_dp))
4351 return connector_status_disconnected;
4352
4353 /* if there's no downstream port, we're done */
4354 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07004355 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004356
4357 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004358 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4359 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Adam Jackson23235172012-09-20 16:42:45 -04004360 uint8_t reg;
Jani Nikula9d1a1032014-03-14 16:51:15 +02004361
4362 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT,
4363 &reg, 1) < 0)
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004364 return connector_status_unknown;
Jani Nikula9d1a1032014-03-14 16:51:15 +02004365
Adam Jackson23235172012-09-20 16:42:45 -04004366 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
4367 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004368 }
4369
4370 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004371 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004372 return connector_status_connected;
4373
4374 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004375 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4376 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4377 if (type == DP_DS_PORT_TYPE_VGA ||
4378 type == DP_DS_PORT_TYPE_NON_EDID)
4379 return connector_status_unknown;
4380 } else {
4381 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4382 DP_DWN_STRM_PORT_TYPE_MASK;
4383 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4384 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4385 return connector_status_unknown;
4386 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004387
4388 /* Anything else is out of spec, warn and ignore */
4389 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004390 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004391}
4392
4393static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004394edp_detect(struct intel_dp *intel_dp)
4395{
4396 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4397 enum drm_connector_status status;
4398
4399 status = intel_panel_detect(dev);
4400 if (status == connector_status_unknown)
4401 status = connector_status_connected;
4402
4403 return status;
4404}
4405
Jani Nikulab93433c2015-08-20 10:47:36 +03004406static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4407 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004408{
Jani Nikulab93433c2015-08-20 10:47:36 +03004409 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004410
Jani Nikula0df53b72015-08-20 10:47:40 +03004411 switch (port->port) {
4412 case PORT_A:
4413 return true;
4414 case PORT_B:
4415 bit = SDE_PORTB_HOTPLUG;
4416 break;
4417 case PORT_C:
4418 bit = SDE_PORTC_HOTPLUG;
4419 break;
4420 case PORT_D:
4421 bit = SDE_PORTD_HOTPLUG;
4422 break;
4423 default:
4424 MISSING_CASE(port->port);
4425 return false;
4426 }
4427
4428 return I915_READ(SDEISR) & bit;
4429}
4430
4431static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4432 struct intel_digital_port *port)
4433{
4434 u32 bit;
4435
4436 switch (port->port) {
4437 case PORT_A:
4438 return true;
4439 case PORT_B:
4440 bit = SDE_PORTB_HOTPLUG_CPT;
4441 break;
4442 case PORT_C:
4443 bit = SDE_PORTC_HOTPLUG_CPT;
4444 break;
4445 case PORT_D:
4446 bit = SDE_PORTD_HOTPLUG_CPT;
4447 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004448 case PORT_E:
4449 bit = SDE_PORTE_HOTPLUG_SPT;
4450 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004451 default:
4452 MISSING_CASE(port->port);
4453 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004454 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004455
Jani Nikulab93433c2015-08-20 10:47:36 +03004456 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004457}
4458
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004459static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004460 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004461{
Jani Nikula9642c812015-08-20 10:47:41 +03004462 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004463
Jani Nikula9642c812015-08-20 10:47:41 +03004464 switch (port->port) {
4465 case PORT_B:
4466 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4467 break;
4468 case PORT_C:
4469 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4470 break;
4471 case PORT_D:
4472 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4473 break;
4474 default:
4475 MISSING_CASE(port->port);
4476 return false;
4477 }
4478
4479 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4480}
4481
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004482static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4483 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004484{
4485 u32 bit;
4486
4487 switch (port->port) {
4488 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004489 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004490 break;
4491 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004492 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004493 break;
4494 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004495 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004496 break;
4497 default:
4498 MISSING_CASE(port->port);
4499 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004500 }
4501
Jani Nikula1d245982015-08-20 10:47:37 +03004502 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004503}
4504
Jani Nikulae464bfd2015-08-20 10:47:42 +03004505static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304506 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004507{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304508 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4509 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004510 u32 bit;
4511
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304512 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4513 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004514 case PORT_A:
4515 bit = BXT_DE_PORT_HP_DDIA;
4516 break;
4517 case PORT_B:
4518 bit = BXT_DE_PORT_HP_DDIB;
4519 break;
4520 case PORT_C:
4521 bit = BXT_DE_PORT_HP_DDIC;
4522 break;
4523 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304524 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004525 return false;
4526 }
4527
4528 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4529}
4530
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004531/*
4532 * intel_digital_port_connected - is the specified port connected?
4533 * @dev_priv: i915 private structure
4534 * @port: the port to test
4535 *
4536 * Return %true if @port is connected, %false otherwise.
4537 */
Sonika Jindal237ed862015-09-15 09:44:20 +05304538bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004539 struct intel_digital_port *port)
4540{
Jani Nikula0df53b72015-08-20 10:47:40 +03004541 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004542 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004543 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004544 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004545 else if (IS_BROXTON(dev_priv))
4546 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004547 else if (IS_GM45(dev_priv))
4548 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004549 else
4550 return g4x_digital_port_connected(dev_priv, port);
4551}
4552
Keith Packard8c241fe2011-09-28 16:38:44 -07004553static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004554intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004555{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004556 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004557
Jani Nikula9cd300e2012-10-19 14:51:52 +03004558 /* use cached edid if we have one */
4559 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004560 /* invalid edid */
4561 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004562 return NULL;
4563
Jani Nikula55e9ede2013-10-01 10:38:54 +03004564 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004565 } else
4566 return drm_get_edid(&intel_connector->base,
4567 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004568}
4569
Chris Wilsonbeb60602014-09-02 20:04:00 +01004570static void
4571intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004572{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004573 struct intel_connector *intel_connector = intel_dp->attached_connector;
4574 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004575
Chris Wilsonbeb60602014-09-02 20:04:00 +01004576 edid = intel_dp_get_edid(intel_dp);
4577 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004578
Chris Wilsonbeb60602014-09-02 20:04:00 +01004579 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4580 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4581 else
4582 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4583}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004584
Chris Wilsonbeb60602014-09-02 20:04:00 +01004585static void
4586intel_dp_unset_edid(struct intel_dp *intel_dp)
4587{
4588 struct intel_connector *intel_connector = intel_dp->attached_connector;
4589
4590 kfree(intel_connector->detect_edid);
4591 intel_connector->detect_edid = NULL;
4592
4593 intel_dp->has_audio = false;
4594}
4595
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004596static enum drm_connector_status
4597intel_dp_detect(struct drm_connector *connector, bool force)
4598{
4599 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004600 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4601 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004602 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004603 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004604 enum intel_display_power_domain power_domain;
Dave Airlie0e32b392014-05-02 14:02:48 +10004605 bool ret;
Todd Previte09b1eb12015-04-20 15:27:34 -07004606 u8 sink_irq_vector;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004607
Chris Wilson164c8592013-07-20 20:27:08 +01004608 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03004609 connector->base.id, connector->name);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004610 intel_dp_unset_edid(intel_dp);
Chris Wilson164c8592013-07-20 20:27:08 +01004611
Dave Airlie0e32b392014-05-02 14:02:48 +10004612 if (intel_dp->is_mst) {
4613 /* MST devices are disconnected from a monitor POV */
4614 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4615 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004616 return connector_status_disconnected;
Dave Airlie0e32b392014-05-02 14:02:48 +10004617 }
4618
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004619 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4620 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004621
Chris Wilsond410b562014-09-02 20:03:59 +01004622 /* Can't disconnect eDP, but you can close the lid... */
4623 if (is_edp(intel_dp))
4624 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004625 else if (intel_digital_port_connected(to_i915(dev),
4626 dp_to_dig_port(intel_dp)))
4627 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004628 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004629 status = connector_status_disconnected;
4630
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304631 if (status != connector_status_connected) {
4632 intel_dp->compliance_test_active = 0;
4633 intel_dp->compliance_test_type = 0;
4634 intel_dp->compliance_test_data = 0;
4635
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004636 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304637 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004638
Adam Jackson0d198322012-05-14 16:05:47 -04004639 intel_dp_probe_oui(intel_dp);
4640
Dave Airlie0e32b392014-05-02 14:02:48 +10004641 ret = intel_dp_probe_mst(intel_dp);
4642 if (ret) {
4643 /* if we are in MST mode then this connector
4644 won't appear connected or have anything with EDID on it */
4645 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4646 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4647 status = connector_status_disconnected;
4648 goto out;
4649 }
4650
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304651 /*
4652 * Clearing NACK and defer counts to get their exact values
4653 * while reading EDID which are required by Compliance tests
4654 * 4.2.2.4 and 4.2.2.5
4655 */
4656 intel_dp->aux.i2c_nack_count = 0;
4657 intel_dp->aux.i2c_defer_count = 0;
4658
Chris Wilsonbeb60602014-09-02 20:04:00 +01004659 intel_dp_set_edid(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004660
Paulo Zanonid63885d2012-10-26 19:05:49 -02004661 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4662 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004663 status = connector_status_connected;
4664
Todd Previte09b1eb12015-04-20 15:27:34 -07004665 /* Try to read the source of the interrupt */
4666 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4667 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
4668 /* Clear interrupt source */
4669 drm_dp_dpcd_writeb(&intel_dp->aux,
4670 DP_DEVICE_SERVICE_IRQ_VECTOR,
4671 sink_irq_vector);
4672
4673 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4674 intel_dp_handle_test_request(intel_dp);
4675 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4676 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4677 }
4678
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004679out:
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004680 intel_display_power_put(to_i915(dev), power_domain);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004681 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004682}
4683
Chris Wilsonbeb60602014-09-02 20:04:00 +01004684static void
4685intel_dp_force(struct drm_connector *connector)
4686{
4687 struct intel_dp *intel_dp = intel_attached_dp(connector);
4688 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004689 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004690 enum intel_display_power_domain power_domain;
4691
4692 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4693 connector->base.id, connector->name);
4694 intel_dp_unset_edid(intel_dp);
4695
4696 if (connector->status != connector_status_connected)
4697 return;
4698
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004699 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4700 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004701
4702 intel_dp_set_edid(intel_dp);
4703
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004704 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004705
4706 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4707 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4708}
4709
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004710static int intel_dp_get_modes(struct drm_connector *connector)
4711{
Jani Nikuladd06f902012-10-19 14:51:50 +03004712 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004713 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004714
Chris Wilsonbeb60602014-09-02 20:04:00 +01004715 edid = intel_connector->detect_edid;
4716 if (edid) {
4717 int ret = intel_connector_update_modes(connector, edid);
4718 if (ret)
4719 return ret;
4720 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004721
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004722 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004723 if (is_edp(intel_attached_dp(connector)) &&
4724 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004725 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004726
4727 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004728 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004729 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004730 drm_mode_probed_add(connector, mode);
4731 return 1;
4732 }
4733 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004734
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004735 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004736}
4737
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004738static bool
4739intel_dp_detect_audio(struct drm_connector *connector)
4740{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004741 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004742 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004743
Chris Wilsonbeb60602014-09-02 20:04:00 +01004744 edid = to_intel_connector(connector)->detect_edid;
4745 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004746 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004747
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004748 return has_audio;
4749}
4750
Chris Wilsonf6849602010-09-19 09:29:33 +01004751static int
4752intel_dp_set_property(struct drm_connector *connector,
4753 struct drm_property *property,
4754 uint64_t val)
4755{
Chris Wilsone953fd72011-02-21 22:23:52 +00004756 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03004757 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004758 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4759 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004760 int ret;
4761
Rob Clark662595d2012-10-11 20:36:04 -05004762 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004763 if (ret)
4764 return ret;
4765
Chris Wilson3f43c482011-05-12 22:17:24 +01004766 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004767 int i = val;
4768 bool has_audio;
4769
4770 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004771 return 0;
4772
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004773 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004774
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004775 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004776 has_audio = intel_dp_detect_audio(connector);
4777 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004778 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004779
4780 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004781 return 0;
4782
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004783 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004784 goto done;
4785 }
4786
Chris Wilsone953fd72011-02-21 22:23:52 +00004787 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004788 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004789 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004790
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004791 switch (val) {
4792 case INTEL_BROADCAST_RGB_AUTO:
4793 intel_dp->color_range_auto = true;
4794 break;
4795 case INTEL_BROADCAST_RGB_FULL:
4796 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004797 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004798 break;
4799 case INTEL_BROADCAST_RGB_LIMITED:
4800 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004801 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004802 break;
4803 default:
4804 return -EINVAL;
4805 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004806
4807 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004808 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004809 return 0;
4810
Chris Wilsone953fd72011-02-21 22:23:52 +00004811 goto done;
4812 }
4813
Yuly Novikov53b41832012-10-26 12:04:00 +03004814 if (is_edp(intel_dp) &&
4815 property == connector->dev->mode_config.scaling_mode_property) {
4816 if (val == DRM_MODE_SCALE_NONE) {
4817 DRM_DEBUG_KMS("no scaling not supported\n");
4818 return -EINVAL;
4819 }
4820
4821 if (intel_connector->panel.fitting_mode == val) {
4822 /* the eDP scaling property is not changed */
4823 return 0;
4824 }
4825 intel_connector->panel.fitting_mode = val;
4826
4827 goto done;
4828 }
4829
Chris Wilsonf6849602010-09-19 09:29:33 +01004830 return -EINVAL;
4831
4832done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004833 if (intel_encoder->base.crtc)
4834 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004835
4836 return 0;
4837}
4838
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004839static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004840intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004841{
Jani Nikula1d508702012-10-19 14:51:49 +03004842 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004843
Chris Wilson10e972d2014-09-04 21:43:45 +01004844 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004845
Jani Nikula9cd300e2012-10-19 14:51:52 +03004846 if (!IS_ERR_OR_NULL(intel_connector->edid))
4847 kfree(intel_connector->edid);
4848
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004849 /* Can't call is_edp() since the encoder may have been destroyed
4850 * already. */
4851 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004852 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004853
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004854 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004855 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004856}
4857
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004858void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004859{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004860 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4861 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004862
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02004863 intel_dp_aux_fini(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004864 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004865 if (is_edp(intel_dp)) {
4866 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004867 /*
4868 * vdd might still be enabled do to the delayed vdd off.
4869 * Make sure vdd is actually turned off here.
4870 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004871 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004872 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004873 pps_unlock(intel_dp);
4874
Clint Taylor01527b32014-07-07 13:01:46 -07004875 if (intel_dp->edp_notifier.notifier_call) {
4876 unregister_reboot_notifier(&intel_dp->edp_notifier);
4877 intel_dp->edp_notifier.notifier_call = NULL;
4878 }
Keith Packardbd943152011-09-18 23:09:52 -07004879 }
Imre Deakc8bd0e42014-12-12 17:57:38 +02004880 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004881 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004882}
4883
Imre Deak07f9cd02014-08-18 14:42:45 +03004884static void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
4885{
4886 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4887
4888 if (!is_edp(intel_dp))
4889 return;
4890
Ville Syrjälä951468f2014-09-04 14:55:31 +03004891 /*
4892 * vdd might still be enabled do to the delayed vdd off.
4893 * Make sure vdd is actually turned off here.
4894 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004895 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004896 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004897 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004898 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004899}
4900
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004901static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4902{
4903 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4904 struct drm_device *dev = intel_dig_port->base.base.dev;
4905 struct drm_i915_private *dev_priv = dev->dev_private;
4906 enum intel_display_power_domain power_domain;
4907
4908 lockdep_assert_held(&dev_priv->pps_mutex);
4909
4910 if (!edp_have_panel_vdd(intel_dp))
4911 return;
4912
4913 /*
4914 * The VDD bit needs a power domain reference, so if the bit is
4915 * already enabled when we boot or resume, grab this reference and
4916 * schedule a vdd off, so we don't hold on to the reference
4917 * indefinitely.
4918 */
4919 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004920 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004921 intel_display_power_get(dev_priv, power_domain);
4922
4923 edp_panel_vdd_schedule_off(intel_dp);
4924}
4925
Imre Deak6d93c0c2014-07-31 14:03:36 +03004926static void intel_dp_encoder_reset(struct drm_encoder *encoder)
4927{
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004928 struct intel_dp *intel_dp;
4929
4930 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4931 return;
4932
4933 intel_dp = enc_to_intel_dp(encoder);
4934
4935 pps_lock(intel_dp);
4936
4937 /*
4938 * Read out the current power sequencer assignment,
4939 * in case the BIOS did something with it.
4940 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004941 if (IS_VALLEYVIEW(encoder->dev) || IS_CHERRYVIEW(encoder->dev))
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004942 vlv_initial_power_sequencer_setup(intel_dp);
4943
4944 intel_edp_panel_vdd_sanitize(intel_dp);
4945
4946 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004947}
4948
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004949static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004950 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004951 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004952 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004953 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004954 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004955 .atomic_get_property = intel_connector_atomic_get_property,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004956 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004957 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004958 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004959};
4960
4961static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4962 .get_modes = intel_dp_get_modes,
4963 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01004964 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004965};
4966
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004967static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004968 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004969 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004970};
4971
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004972enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004973intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4974{
4975 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004976 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004977 struct drm_device *dev = intel_dig_port->base.base.dev;
4978 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak1c767b32014-08-18 14:42:42 +03004979 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004980 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004981
Takashi Iwai25400582015-11-19 12:09:56 +01004982 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4983 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Dave Airlie0e32b392014-05-02 14:02:48 +10004984 intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
Dave Airlie13cf5502014-06-18 11:29:35 +10004985
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004986 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4987 /*
4988 * vdd off can generate a long pulse on eDP which
4989 * would require vdd on to handle it, and thus we
4990 * would end up in an endless cycle of
4991 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4992 */
4993 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4994 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004995 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004996 }
4997
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004998 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4999 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005000 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005001
Ville Syrjälä25f78f52015-11-16 15:01:04 +01005002 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03005003 intel_display_power_get(dev_priv, power_domain);
5004
Dave Airlie0e32b392014-05-02 14:02:48 +10005005 if (long_hpd) {
Mika Kahola5fa836a2015-04-29 09:17:40 +03005006 /* indicate that we need to restart link training */
5007 intel_dp->train_set_valid = false;
Dave Airlie2a592be2014-09-01 16:58:12 +10005008
Jani Nikula7e66bcf2015-08-20 10:47:39 +03005009 if (!intel_digital_port_connected(dev_priv, intel_dig_port))
5010 goto mst_fail;
Dave Airlie0e32b392014-05-02 14:02:48 +10005011
5012 if (!intel_dp_get_dpcd(intel_dp)) {
5013 goto mst_fail;
5014 }
5015
5016 intel_dp_probe_oui(intel_dp);
5017
Ville Syrjäläd14e7b62015-08-20 19:37:29 +03005018 if (!intel_dp_probe_mst(intel_dp)) {
5019 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
5020 intel_dp_check_link_status(intel_dp);
5021 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Dave Airlie0e32b392014-05-02 14:02:48 +10005022 goto mst_fail;
Ville Syrjäläd14e7b62015-08-20 19:37:29 +03005023 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005024 } else {
5025 if (intel_dp->is_mst) {
Imre Deak1c767b32014-08-18 14:42:42 +03005026 if (intel_dp_check_mst_status(intel_dp) == -EINVAL)
Dave Airlie0e32b392014-05-02 14:02:48 +10005027 goto mst_fail;
5028 }
5029
5030 if (!intel_dp->is_mst) {
Dave Airlie5b215bc2014-08-05 10:40:20 +10005031 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
Dave Airlie0e32b392014-05-02 14:02:48 +10005032 intel_dp_check_link_status(intel_dp);
Dave Airlie5b215bc2014-08-05 10:40:20 +10005033 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Dave Airlie0e32b392014-05-02 14:02:48 +10005034 }
5035 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005036
5037 ret = IRQ_HANDLED;
5038
Imre Deak1c767b32014-08-18 14:42:42 +03005039 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005040mst_fail:
5041 /* if we were in MST mode, and device is not there get out of MST mode */
5042 if (intel_dp->is_mst) {
5043 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5044 intel_dp->is_mst = false;
5045 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
5046 }
Imre Deak1c767b32014-08-18 14:42:42 +03005047put_power:
5048 intel_display_power_put(dev_priv, power_domain);
5049
5050 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005051}
5052
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005053/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02005054bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005055{
5056 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni768f69c2013-09-11 18:02:47 -03005057 union child_device_config *p_child;
Zhao Yakui36e83a12010-06-12 14:32:21 +08005058 int i;
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02005059 static const short port_mapping[] = {
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005060 [PORT_B] = DVO_PORT_DPB,
5061 [PORT_C] = DVO_PORT_DPC,
5062 [PORT_D] = DVO_PORT_DPD,
5063 [PORT_E] = DVO_PORT_DPE,
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02005064 };
Zhao Yakui36e83a12010-06-12 14:32:21 +08005065
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005066 /*
5067 * eDP not supported on g4x. so bail out early just
5068 * for a bit extra safety in case the VBT is bonkers.
5069 */
5070 if (INTEL_INFO(dev)->gen < 5)
5071 return false;
5072
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005073 if (port == PORT_A)
5074 return true;
5075
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03005076 if (!dev_priv->vbt.child_dev_num)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005077 return false;
5078
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03005079 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
5080 p_child = dev_priv->vbt.child_dev + i;
Zhao Yakui36e83a12010-06-12 14:32:21 +08005081
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02005082 if (p_child->common.dvo_port == port_mapping[port] &&
Ville Syrjäläf02586d2013-11-01 20:32:08 +02005083 (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
5084 (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
Zhao Yakui36e83a12010-06-12 14:32:21 +08005085 return true;
5086 }
5087 return false;
5088}
5089
Dave Airlie0e32b392014-05-02 14:02:48 +10005090void
Chris Wilsonf6849602010-09-19 09:29:33 +01005091intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5092{
Yuly Novikov53b41832012-10-26 12:04:00 +03005093 struct intel_connector *intel_connector = to_intel_connector(connector);
5094
Chris Wilson3f43c482011-05-12 22:17:24 +01005095 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005096 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005097 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005098
5099 if (is_edp(intel_dp)) {
5100 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005101 drm_object_attach_property(
5102 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005103 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005104 DRM_MODE_SCALE_ASPECT);
5105 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005106 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005107}
5108
Imre Deakdada1a92014-01-29 13:25:41 +02005109static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5110{
Abhay Kumard28d4732016-01-22 17:39:04 -08005111 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005112 intel_dp->last_power_on = jiffies;
5113 intel_dp->last_backlight_off = jiffies;
5114}
5115
Daniel Vetter67a54562012-10-20 20:57:45 +02005116static void
5117intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005118 struct intel_dp *intel_dp)
Daniel Vetter67a54562012-10-20 20:57:45 +02005119{
5120 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005121 struct edp_power_seq cur, vbt, spec,
5122 *final = &intel_dp->pps_delays;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305123 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005124 i915_reg_t pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07005125
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005126 lockdep_assert_held(&dev_priv->pps_mutex);
5127
Ville Syrjälä81ddbc62014-10-16 21:27:31 +03005128 /* already initialized? */
5129 if (final->t11_t12 != 0)
5130 return;
5131
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305132 if (IS_BROXTON(dev)) {
5133 /*
5134 * TODO: BXT has 2 sets of PPS registers.
5135 * Correct Register for Broxton need to be identified
5136 * using VBT. hardcoding for now
5137 */
5138 pp_ctrl_reg = BXT_PP_CONTROL(0);
5139 pp_on_reg = BXT_PP_ON_DELAYS(0);
5140 pp_off_reg = BXT_PP_OFF_DELAYS(0);
5141 } else if (HAS_PCH_SPLIT(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03005142 pp_ctrl_reg = PCH_PP_CONTROL;
Jesse Barnes453c5422013-03-28 09:55:41 -07005143 pp_on_reg = PCH_PP_ON_DELAYS;
5144 pp_off_reg = PCH_PP_OFF_DELAYS;
5145 pp_div_reg = PCH_PP_DIVISOR;
5146 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03005147 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
5148
5149 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
5150 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
5151 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
5152 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07005153 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005154
5155 /* Workaround: Need to write PP_CONTROL with the unlock key as
5156 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305157 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005158
Jesse Barnes453c5422013-03-28 09:55:41 -07005159 pp_on = I915_READ(pp_on_reg);
5160 pp_off = I915_READ(pp_off_reg);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305161 if (!IS_BROXTON(dev)) {
5162 I915_WRITE(pp_ctrl_reg, pp_ctl);
5163 pp_div = I915_READ(pp_div_reg);
5164 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005165
5166 /* Pull timing values out of registers */
5167 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5168 PANEL_POWER_UP_DELAY_SHIFT;
5169
5170 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5171 PANEL_LIGHT_ON_DELAY_SHIFT;
5172
5173 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5174 PANEL_LIGHT_OFF_DELAY_SHIFT;
5175
5176 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5177 PANEL_POWER_DOWN_DELAY_SHIFT;
5178
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305179 if (IS_BROXTON(dev)) {
5180 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5181 BXT_POWER_CYCLE_DELAY_SHIFT;
5182 if (tmp > 0)
5183 cur.t11_t12 = (tmp - 1) * 1000;
5184 else
5185 cur.t11_t12 = 0;
5186 } else {
5187 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005188 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305189 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005190
5191 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5192 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
5193
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03005194 vbt = dev_priv->vbt.edp_pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005195
5196 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5197 * our hw here, which are all in 100usec. */
5198 spec.t1_t3 = 210 * 10;
5199 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5200 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5201 spec.t10 = 500 * 10;
5202 /* This one is special and actually in units of 100ms, but zero
5203 * based in the hw (so we need to add 100 ms). But the sw vbt
5204 * table multiplies it with 1000 to make it in units of 100usec,
5205 * too. */
5206 spec.t11_t12 = (510 + 100) * 10;
5207
5208 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5209 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
5210
5211 /* Use the max of the register settings and vbt. If both are
5212 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005213#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005214 spec.field : \
5215 max(cur.field, vbt.field))
5216 assign_final(t1_t3);
5217 assign_final(t8);
5218 assign_final(t9);
5219 assign_final(t10);
5220 assign_final(t11_t12);
5221#undef assign_final
5222
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005223#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005224 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5225 intel_dp->backlight_on_delay = get_delay(t8);
5226 intel_dp->backlight_off_delay = get_delay(t9);
5227 intel_dp->panel_power_down_delay = get_delay(t10);
5228 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5229#undef get_delay
5230
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005231 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5232 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5233 intel_dp->panel_power_cycle_delay);
5234
5235 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5236 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005237}
5238
5239static void
5240intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005241 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005242{
5243 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07005244 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005245 int div = dev_priv->rawclk_freq / 1000;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005246 i915_reg_t pp_on_reg, pp_off_reg, pp_div_reg, pp_ctrl_reg;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005247 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005248 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005249
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005250 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005251
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305252 if (IS_BROXTON(dev)) {
5253 /*
5254 * TODO: BXT has 2 sets of PPS registers.
5255 * Correct Register for Broxton need to be identified
5256 * using VBT. hardcoding for now
5257 */
5258 pp_ctrl_reg = BXT_PP_CONTROL(0);
5259 pp_on_reg = BXT_PP_ON_DELAYS(0);
5260 pp_off_reg = BXT_PP_OFF_DELAYS(0);
5261
5262 } else if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes453c5422013-03-28 09:55:41 -07005263 pp_on_reg = PCH_PP_ON_DELAYS;
5264 pp_off_reg = PCH_PP_OFF_DELAYS;
5265 pp_div_reg = PCH_PP_DIVISOR;
5266 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03005267 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
5268
5269 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
5270 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
5271 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07005272 }
5273
Paulo Zanonib2f19d12013-12-19 14:29:44 -02005274 /*
5275 * And finally store the new values in the power sequencer. The
5276 * backlight delays are set to 1 because we do manual waits on them. For
5277 * T8, even BSpec recommends doing it. For T9, if we don't do this,
5278 * we'll end up waiting for the backlight off delay twice: once when we
5279 * do the manual sleep, and once when we disable the panel and wait for
5280 * the PP_STATUS bit to become zero.
5281 */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005282 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Paulo Zanonib2f19d12013-12-19 14:29:44 -02005283 (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
5284 pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005285 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005286 /* Compute the divisor for the pp clock, simply match the Bspec
5287 * formula. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305288 if (IS_BROXTON(dev)) {
5289 pp_div = I915_READ(pp_ctrl_reg);
5290 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5291 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5292 << BXT_POWER_CYCLE_DELAY_SHIFT);
5293 } else {
5294 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5295 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5296 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5297 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005298
5299 /* Haswell doesn't have any port selection bits for the panel
5300 * power sequencer any more. */
Wayne Boyer666a4532015-12-09 12:29:35 -08005301 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005302 port_sel = PANEL_PORT_SELECT_VLV(port);
Imre Deakbc7d38a2013-05-16 14:40:36 +03005303 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005304 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005305 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005306 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005307 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005308 }
5309
Jesse Barnes453c5422013-03-28 09:55:41 -07005310 pp_on |= port_sel;
5311
5312 I915_WRITE(pp_on_reg, pp_on);
5313 I915_WRITE(pp_off_reg, pp_off);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305314 if (IS_BROXTON(dev))
5315 I915_WRITE(pp_ctrl_reg, pp_div);
5316 else
5317 I915_WRITE(pp_div_reg, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005318
Daniel Vetter67a54562012-10-20 20:57:45 +02005319 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 -07005320 I915_READ(pp_on_reg),
5321 I915_READ(pp_off_reg),
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305322 IS_BROXTON(dev) ?
5323 (I915_READ(pp_ctrl_reg) & BXT_POWER_CYCLE_DELAY_MASK) :
Jesse Barnes453c5422013-03-28 09:55:41 -07005324 I915_READ(pp_div_reg));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005325}
5326
Vandana Kannanb33a2812015-02-13 15:33:03 +05305327/**
5328 * intel_dp_set_drrs_state - program registers for RR switch to take effect
5329 * @dev: DRM device
5330 * @refresh_rate: RR to be programmed
5331 *
5332 * This function gets called when refresh rate (RR) has to be changed from
5333 * one frequency to another. Switches can be between high and low RR
5334 * supported by the panel or to any other RR based on media playback (in
5335 * this case, RR value needs to be passed from user space).
5336 *
5337 * The caller of this function needs to take a lock on dev_priv->drrs.
5338 */
Vandana Kannan96178ee2015-01-10 02:25:56 +05305339static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305340{
5341 struct drm_i915_private *dev_priv = dev->dev_private;
5342 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305343 struct intel_digital_port *dig_port = NULL;
5344 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02005345 struct intel_crtc_state *config = NULL;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305346 struct intel_crtc *intel_crtc = NULL;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305347 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305348
5349 if (refresh_rate <= 0) {
5350 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5351 return;
5352 }
5353
Vandana Kannan96178ee2015-01-10 02:25:56 +05305354 if (intel_dp == NULL) {
5355 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305356 return;
5357 }
5358
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005359 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005360 * FIXME: This needs proper synchronization with psr state for some
5361 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005362 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305363
Vandana Kannan96178ee2015-01-10 02:25:56 +05305364 dig_port = dp_to_dig_port(intel_dp);
5365 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005366 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305367
5368 if (!intel_crtc) {
5369 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5370 return;
5371 }
5372
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02005373 config = intel_crtc->config;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305374
Vandana Kannan96178ee2015-01-10 02:25:56 +05305375 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305376 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5377 return;
5378 }
5379
Vandana Kannan96178ee2015-01-10 02:25:56 +05305380 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5381 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305382 index = DRRS_LOW_RR;
5383
Vandana Kannan96178ee2015-01-10 02:25:56 +05305384 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305385 DRM_DEBUG_KMS(
5386 "DRRS requested for previously set RR...ignoring\n");
5387 return;
5388 }
5389
5390 if (!intel_crtc->active) {
5391 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5392 return;
5393 }
5394
Durgadoss R44395bf2015-02-13 15:33:02 +05305395 if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305396 switch (index) {
5397 case DRRS_HIGH_RR:
5398 intel_dp_set_m_n(intel_crtc, M1_N1);
5399 break;
5400 case DRRS_LOW_RR:
5401 intel_dp_set_m_n(intel_crtc, M2_N2);
5402 break;
5403 case DRRS_MAX_RR:
5404 default:
5405 DRM_ERROR("Unsupported refreshrate type\n");
5406 }
5407 } else if (INTEL_INFO(dev)->gen > 6) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005408 i915_reg_t reg = PIPECONF(intel_crtc->config->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005409 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305410
Ville Syrjälä649636e2015-09-22 19:50:01 +03005411 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305412 if (index > DRRS_HIGH_RR) {
Wayne Boyer666a4532015-12-09 12:29:35 -08005413 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305414 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5415 else
5416 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305417 } else {
Wayne Boyer666a4532015-12-09 12:29:35 -08005418 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305419 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5420 else
5421 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305422 }
5423 I915_WRITE(reg, val);
5424 }
5425
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305426 dev_priv->drrs.refresh_rate_type = index;
5427
5428 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5429}
5430
Vandana Kannanb33a2812015-02-13 15:33:03 +05305431/**
5432 * intel_edp_drrs_enable - init drrs struct if supported
5433 * @intel_dp: DP struct
5434 *
5435 * Initializes frontbuffer_bits and drrs.dp
5436 */
Vandana Kannanc3955782015-01-22 15:17:40 +05305437void intel_edp_drrs_enable(struct intel_dp *intel_dp)
5438{
5439 struct drm_device *dev = intel_dp_to_dev(intel_dp);
5440 struct drm_i915_private *dev_priv = dev->dev_private;
5441 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
5442 struct drm_crtc *crtc = dig_port->base.base.crtc;
5443 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5444
5445 if (!intel_crtc->config->has_drrs) {
5446 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5447 return;
5448 }
5449
5450 mutex_lock(&dev_priv->drrs.mutex);
5451 if (WARN_ON(dev_priv->drrs.dp)) {
5452 DRM_ERROR("DRRS already enabled\n");
5453 goto unlock;
5454 }
5455
5456 dev_priv->drrs.busy_frontbuffer_bits = 0;
5457
5458 dev_priv->drrs.dp = intel_dp;
5459
5460unlock:
5461 mutex_unlock(&dev_priv->drrs.mutex);
5462}
5463
Vandana Kannanb33a2812015-02-13 15:33:03 +05305464/**
5465 * intel_edp_drrs_disable - Disable DRRS
5466 * @intel_dp: DP struct
5467 *
5468 */
Vandana Kannanc3955782015-01-22 15:17:40 +05305469void intel_edp_drrs_disable(struct intel_dp *intel_dp)
5470{
5471 struct drm_device *dev = intel_dp_to_dev(intel_dp);
5472 struct drm_i915_private *dev_priv = dev->dev_private;
5473 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
5474 struct drm_crtc *crtc = dig_port->base.base.crtc;
5475 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5476
5477 if (!intel_crtc->config->has_drrs)
5478 return;
5479
5480 mutex_lock(&dev_priv->drrs.mutex);
5481 if (!dev_priv->drrs.dp) {
5482 mutex_unlock(&dev_priv->drrs.mutex);
5483 return;
5484 }
5485
5486 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5487 intel_dp_set_drrs_state(dev_priv->dev,
5488 intel_dp->attached_connector->panel.
5489 fixed_mode->vrefresh);
5490
5491 dev_priv->drrs.dp = NULL;
5492 mutex_unlock(&dev_priv->drrs.mutex);
5493
5494 cancel_delayed_work_sync(&dev_priv->drrs.work);
5495}
5496
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305497static void intel_edp_drrs_downclock_work(struct work_struct *work)
5498{
5499 struct drm_i915_private *dev_priv =
5500 container_of(work, typeof(*dev_priv), drrs.work.work);
5501 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305502
Vandana Kannan96178ee2015-01-10 02:25:56 +05305503 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305504
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305505 intel_dp = dev_priv->drrs.dp;
5506
5507 if (!intel_dp)
5508 goto unlock;
5509
5510 /*
5511 * The delayed work can race with an invalidate hence we need to
5512 * recheck.
5513 */
5514
5515 if (dev_priv->drrs.busy_frontbuffer_bits)
5516 goto unlock;
5517
5518 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
5519 intel_dp_set_drrs_state(dev_priv->dev,
5520 intel_dp->attached_connector->panel.
5521 downclock_mode->vrefresh);
5522
5523unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305524 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305525}
5526
Vandana Kannanb33a2812015-02-13 15:33:03 +05305527/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305528 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Vandana Kannanb33a2812015-02-13 15:33:03 +05305529 * @dev: DRM device
5530 * @frontbuffer_bits: frontbuffer plane tracking bits
5531 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305532 * This function gets called everytime rendering on the given planes start.
5533 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305534 *
5535 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5536 */
Vandana Kannana93fad02015-01-10 02:25:59 +05305537void intel_edp_drrs_invalidate(struct drm_device *dev,
5538 unsigned frontbuffer_bits)
5539{
5540 struct drm_i915_private *dev_priv = dev->dev_private;
5541 struct drm_crtc *crtc;
5542 enum pipe pipe;
5543
Daniel Vetter9da7d692015-04-09 16:44:15 +02005544 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305545 return;
5546
Daniel Vetter88f933a2015-04-09 16:44:16 +02005547 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305548
Vandana Kannana93fad02015-01-10 02:25:59 +05305549 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005550 if (!dev_priv->drrs.dp) {
5551 mutex_unlock(&dev_priv->drrs.mutex);
5552 return;
5553 }
5554
Vandana Kannana93fad02015-01-10 02:25:59 +05305555 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5556 pipe = to_intel_crtc(crtc)->pipe;
5557
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005558 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5559 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5560
Ramalingam C0ddfd202015-06-15 20:50:05 +05305561 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005562 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Vandana Kannana93fad02015-01-10 02:25:59 +05305563 intel_dp_set_drrs_state(dev_priv->dev,
5564 dev_priv->drrs.dp->attached_connector->panel.
5565 fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305566
Vandana Kannana93fad02015-01-10 02:25:59 +05305567 mutex_unlock(&dev_priv->drrs.mutex);
5568}
5569
Vandana Kannanb33a2812015-02-13 15:33:03 +05305570/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305571 * intel_edp_drrs_flush - Restart Idleness DRRS
Vandana Kannanb33a2812015-02-13 15:33:03 +05305572 * @dev: DRM device
5573 * @frontbuffer_bits: frontbuffer plane tracking bits
5574 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305575 * This function gets called every time rendering on the given planes has
5576 * completed or flip on a crtc is completed. So DRRS should be upclocked
5577 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5578 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305579 *
5580 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5581 */
Vandana Kannana93fad02015-01-10 02:25:59 +05305582void intel_edp_drrs_flush(struct drm_device *dev,
5583 unsigned frontbuffer_bits)
5584{
5585 struct drm_i915_private *dev_priv = dev->dev_private;
5586 struct drm_crtc *crtc;
5587 enum pipe pipe;
5588
Daniel Vetter9da7d692015-04-09 16:44:15 +02005589 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305590 return;
5591
Daniel Vetter88f933a2015-04-09 16:44:16 +02005592 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305593
Vandana Kannana93fad02015-01-10 02:25:59 +05305594 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005595 if (!dev_priv->drrs.dp) {
5596 mutex_unlock(&dev_priv->drrs.mutex);
5597 return;
5598 }
5599
Vandana Kannana93fad02015-01-10 02:25:59 +05305600 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5601 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005602
5603 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305604 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5605
Ramalingam C0ddfd202015-06-15 20:50:05 +05305606 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005607 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Ramalingam C0ddfd202015-06-15 20:50:05 +05305608 intel_dp_set_drrs_state(dev_priv->dev,
5609 dev_priv->drrs.dp->attached_connector->panel.
5610 fixed_mode->vrefresh);
5611
5612 /*
5613 * flush also means no more activity hence schedule downclock, if all
5614 * other fbs are quiescent too
5615 */
5616 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305617 schedule_delayed_work(&dev_priv->drrs.work,
5618 msecs_to_jiffies(1000));
5619 mutex_unlock(&dev_priv->drrs.mutex);
5620}
5621
Vandana Kannanb33a2812015-02-13 15:33:03 +05305622/**
5623 * DOC: Display Refresh Rate Switching (DRRS)
5624 *
5625 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5626 * which enables swtching between low and high refresh rates,
5627 * dynamically, based on the usage scenario. This feature is applicable
5628 * for internal panels.
5629 *
5630 * Indication that the panel supports DRRS is given by the panel EDID, which
5631 * would list multiple refresh rates for one resolution.
5632 *
5633 * DRRS is of 2 types - static and seamless.
5634 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5635 * (may appear as a blink on screen) and is used in dock-undock scenario.
5636 * Seamless DRRS involves changing RR without any visual effect to the user
5637 * and can be used during normal system usage. This is done by programming
5638 * certain registers.
5639 *
5640 * Support for static/seamless DRRS may be indicated in the VBT based on
5641 * inputs from the panel spec.
5642 *
5643 * DRRS saves power by switching to low RR based on usage scenarios.
5644 *
5645 * eDP DRRS:-
5646 * The implementation is based on frontbuffer tracking implementation.
5647 * When there is a disturbance on the screen triggered by user activity or a
5648 * periodic system activity, DRRS is disabled (RR is changed to high RR).
5649 * When there is no movement on screen, after a timeout of 1 second, a switch
5650 * to low RR is made.
5651 * For integration with frontbuffer tracking code,
5652 * intel_edp_drrs_invalidate() and intel_edp_drrs_flush() are called.
5653 *
5654 * DRRS can be further extended to support other internal panels and also
5655 * the scenario of video playback wherein RR is set based on the rate
5656 * requested by userspace.
5657 */
5658
5659/**
5660 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5661 * @intel_connector: eDP connector
5662 * @fixed_mode: preferred mode of panel
5663 *
5664 * This function is called only once at driver load to initialize basic
5665 * DRRS stuff.
5666 *
5667 * Returns:
5668 * Downclock mode if panel supports it, else return NULL.
5669 * DRRS support is determined by the presence of downclock mode (apart
5670 * from VBT setting).
5671 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305672static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305673intel_dp_drrs_init(struct intel_connector *intel_connector,
5674 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305675{
5676 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305677 struct drm_device *dev = connector->dev;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305678 struct drm_i915_private *dev_priv = dev->dev_private;
5679 struct drm_display_mode *downclock_mode = NULL;
5680
Daniel Vetter9da7d692015-04-09 16:44:15 +02005681 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5682 mutex_init(&dev_priv->drrs.mutex);
5683
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305684 if (INTEL_INFO(dev)->gen <= 6) {
5685 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5686 return NULL;
5687 }
5688
5689 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005690 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305691 return NULL;
5692 }
5693
5694 downclock_mode = intel_find_panel_downclock
5695 (dev, fixed_mode, connector);
5696
5697 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305698 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305699 return NULL;
5700 }
5701
Vandana Kannan96178ee2015-01-10 02:25:56 +05305702 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305703
Vandana Kannan96178ee2015-01-10 02:25:56 +05305704 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005705 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305706 return downclock_mode;
5707}
5708
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005709static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005710 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005711{
5712 struct drm_connector *connector = &intel_connector->base;
5713 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005714 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5715 struct drm_device *dev = intel_encoder->base.dev;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005716 struct drm_i915_private *dev_priv = dev->dev_private;
5717 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305718 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005719 bool has_dpcd;
5720 struct drm_display_mode *scan;
5721 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005722 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005723
5724 if (!is_edp(intel_dp))
5725 return true;
5726
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005727 pps_lock(intel_dp);
5728 intel_edp_panel_vdd_sanitize(intel_dp);
5729 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005730
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005731 /* Cache DPCD and EDID for edp. */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005732 has_dpcd = intel_dp_get_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005733
5734 if (has_dpcd) {
5735 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
5736 dev_priv->no_aux_handshake =
5737 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
5738 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
5739 } else {
5740 /* if this fails, presume the device is a ghost */
5741 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005742 return false;
5743 }
5744
5745 /* We now know it's not a ghost, init power sequence regs. */
Ville Syrjälä773538e82014-09-04 14:54:56 +03005746 pps_lock(intel_dp);
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005747 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005748 pps_unlock(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005749
Daniel Vetter060c8772014-03-21 23:22:35 +01005750 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005751 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005752 if (edid) {
5753 if (drm_add_edid_modes(connector, edid)) {
5754 drm_mode_connector_update_edid_property(connector,
5755 edid);
5756 drm_edid_to_eld(connector, edid);
5757 } else {
5758 kfree(edid);
5759 edid = ERR_PTR(-EINVAL);
5760 }
5761 } else {
5762 edid = ERR_PTR(-ENOENT);
5763 }
5764 intel_connector->edid = edid;
5765
5766 /* prefer fixed mode from EDID if available */
5767 list_for_each_entry(scan, &connector->probed_modes, head) {
5768 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5769 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305770 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305771 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005772 break;
5773 }
5774 }
5775
5776 /* fallback to VBT if available for eDP */
5777 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5778 fixed_mode = drm_mode_duplicate(dev,
5779 dev_priv->vbt.lfp_lvds_vbt_mode);
5780 if (fixed_mode)
5781 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
5782 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005783 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005784
Wayne Boyer666a4532015-12-09 12:29:35 -08005785 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005786 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5787 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005788
5789 /*
5790 * Figure out the current pipe for the initial backlight setup.
5791 * If the current pipe isn't valid, try the PPS pipe, and if that
5792 * fails just assume pipe A.
5793 */
5794 if (IS_CHERRYVIEW(dev))
5795 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5796 else
5797 pipe = PORT_TO_PIPE(intel_dp->DP);
5798
5799 if (pipe != PIPE_A && pipe != PIPE_B)
5800 pipe = intel_dp->pps_pipe;
5801
5802 if (pipe != PIPE_A && pipe != PIPE_B)
5803 pipe = PIPE_A;
5804
5805 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5806 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005807 }
5808
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305809 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005810 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005811 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005812
5813 return true;
5814}
5815
Paulo Zanoni16c25532013-06-12 17:27:25 -03005816bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005817intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5818 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005819{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005820 struct drm_connector *connector = &intel_connector->base;
5821 struct intel_dp *intel_dp = &intel_dig_port->dp;
5822 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5823 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005824 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02005825 enum port port = intel_dig_port->port;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005826 int type, ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005827
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005828 if (WARN(intel_dig_port->max_lanes < 1,
5829 "Not enough lanes (%d) for DP on port %c\n",
5830 intel_dig_port->max_lanes, port_name(port)))
5831 return false;
5832
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005833 intel_dp->pps_pipe = INVALID_PIPE;
5834
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005835 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005836 if (INTEL_INFO(dev)->gen >= 9)
5837 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005838 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
5839 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
5840 else if (HAS_PCH_SPLIT(dev))
5841 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5842 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005843 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005844
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005845 if (INTEL_INFO(dev)->gen >= 9)
5846 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5847 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005848 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005849
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005850 if (HAS_DDI(dev))
5851 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5852
Daniel Vetter07679352012-09-06 22:15:42 +02005853 /* Preserve the current hw state. */
5854 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005855 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005856
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005857 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305858 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005859 else
5860 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005861
Imre Deakf7d24902013-05-08 13:14:05 +03005862 /*
5863 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5864 * for DP the encoder type can be set by the caller to
5865 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5866 */
5867 if (type == DRM_MODE_CONNECTOR_eDP)
5868 intel_encoder->type = INTEL_OUTPUT_EDP;
5869
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005870 /* eDP only on port B and/or C on vlv/chv */
Wayne Boyer666a4532015-12-09 12:29:35 -08005871 if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
5872 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005873 return false;
5874
Imre Deake7281ea2013-05-08 13:14:08 +03005875 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5876 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5877 port_name(port));
5878
Adam Jacksonb3295302010-07-16 14:46:28 -04005879 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005880 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5881
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005882 connector->interlace_allowed = true;
5883 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005884
Daniel Vetter66a92782012-07-12 20:08:18 +02005885 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005886 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005887
Chris Wilsondf0e9242010-09-09 16:20:55 +01005888 intel_connector_attach_encoder(intel_connector, intel_encoder);
Thomas Wood34ea3d32014-05-29 16:57:41 +01005889 drm_connector_register(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005890
Paulo Zanoniaffa9352012-11-23 15:30:39 -02005891 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005892 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5893 else
5894 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak80f65de2014-02-11 17:12:49 +02005895 intel_connector->unregister = intel_dp_connector_unregister;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005896
Jani Nikula0b998362014-03-14 16:51:17 +02005897 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005898 switch (port) {
5899 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005900 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005901 break;
5902 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005903 intel_encoder->hpd_pin = HPD_PORT_B;
Jani Nikulae87a0052015-10-20 15:22:02 +03005904 if (IS_BXT_REVID(dev, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305905 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005906 break;
5907 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005908 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005909 break;
5910 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005911 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005912 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005913 case PORT_E:
5914 intel_encoder->hpd_pin = HPD_PORT_E;
5915 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005916 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005917 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005918 }
5919
Imre Deakdada1a92014-01-29 13:25:41 +02005920 if (is_edp(intel_dp)) {
Ville Syrjälä773538e82014-09-04 14:54:56 +03005921 pps_lock(intel_dp);
Ville Syrjälä1e74a322014-10-28 16:15:51 +02005922 intel_dp_init_panel_power_timestamps(intel_dp);
Wayne Boyer666a4532015-12-09 12:29:35 -08005923 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005924 vlv_initial_power_sequencer_setup(intel_dp);
Ville Syrjälä1e74a322014-10-28 16:15:51 +02005925 else
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005926 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005927 pps_unlock(intel_dp);
Imre Deakdada1a92014-01-29 13:25:41 +02005928 }
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02005929
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005930 ret = intel_dp_aux_init(intel_dp, intel_connector);
5931 if (ret)
5932 goto fail;
Dave Airliec1f05262012-08-30 11:06:18 +10005933
Dave Airlie0e32b392014-05-02 14:02:48 +10005934 /* init MST on ports that can support it */
Jani Nikula0c9b3712015-05-18 17:10:01 +03005935 if (HAS_DP_MST(dev) &&
5936 (port == PORT_B || port == PORT_C || port == PORT_D))
5937 intel_dp_mst_encoder_init(intel_dig_port,
5938 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005939
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005940 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005941 intel_dp_aux_fini(intel_dp);
5942 intel_dp_mst_encoder_cleanup(intel_dig_port);
5943 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005944 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005945
Chris Wilsonf6849602010-09-19 09:29:33 +01005946 intel_dp_add_properties(intel_dp, connector);
5947
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005948 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5949 * 0xd. Failure to do so will result in spurious interrupts being
5950 * generated on the port when a cable is not attached.
5951 */
5952 if (IS_G4X(dev) && !IS_GM45(dev)) {
5953 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5954 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5955 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005956
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005957 i915_debugfs_connector_add(connector);
5958
Paulo Zanoni16c25532013-06-12 17:27:25 -03005959 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005960
5961fail:
5962 if (is_edp(intel_dp)) {
5963 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5964 /*
5965 * vdd might still be enabled do to the delayed vdd off.
5966 * Make sure vdd is actually turned off here.
5967 */
5968 pps_lock(intel_dp);
5969 edp_panel_vdd_off_sync(intel_dp);
5970 pps_unlock(intel_dp);
5971 }
5972 drm_connector_unregister(connector);
5973 drm_connector_cleanup(connector);
5974
5975 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005976}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005977
5978void
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005979intel_dp_init(struct drm_device *dev,
5980 i915_reg_t output_reg, enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005981{
Dave Airlie13cf5502014-06-18 11:29:35 +10005982 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005983 struct intel_digital_port *intel_dig_port;
5984 struct intel_encoder *intel_encoder;
5985 struct drm_encoder *encoder;
5986 struct intel_connector *intel_connector;
5987
Daniel Vetterb14c5672013-09-19 12:18:32 +02005988 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005989 if (!intel_dig_port)
5990 return;
5991
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005992 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305993 if (!intel_connector)
5994 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005995
5996 intel_encoder = &intel_dig_port->base;
5997 encoder = &intel_encoder->base;
5998
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305999 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Dave Airlieade1ba72015-12-23 14:22:09 +10006000 DRM_MODE_ENCODER_TMDS, NULL))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306001 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006002
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006003 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006004 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006005 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006006 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006007 intel_encoder->suspend = intel_dp_encoder_suspend;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006008 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006009 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006010 intel_encoder->pre_enable = chv_pre_enable_dp;
6011 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006012 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006013 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006014 } else if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006015 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006016 intel_encoder->pre_enable = vlv_pre_enable_dp;
6017 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006018 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006019 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006020 intel_encoder->pre_enable = g4x_pre_enable_dp;
6021 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006022 if (INTEL_INFO(dev)->gen >= 5)
6023 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006024 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006025
Paulo Zanoni174edf12012-10-26 19:05:50 -02006026 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006027 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006028 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006029
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006030 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Ville Syrjälä882ec382014-04-28 14:07:43 +03006031 if (IS_CHERRYVIEW(dev)) {
6032 if (port == PORT_D)
6033 intel_encoder->crtc_mask = 1 << 2;
6034 else
6035 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6036 } else {
6037 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6038 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006039 intel_encoder->cloneable = 0;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006040
Dave Airlie13cf5502014-06-18 11:29:35 +10006041 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006042 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006043
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306044 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6045 goto err_init_connector;
6046
6047 return;
6048
6049err_init_connector:
6050 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306051err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306052 kfree(intel_connector);
6053err_connector_alloc:
6054 kfree(intel_dig_port);
6055
6056 return;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006057}
Dave Airlie0e32b392014-05-02 14:02:48 +10006058
6059void intel_dp_mst_suspend(struct drm_device *dev)
6060{
6061 struct drm_i915_private *dev_priv = dev->dev_private;
6062 int i;
6063
6064 /* disable MST */
6065 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006066 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Dave Airlie0e32b392014-05-02 14:02:48 +10006067 if (!intel_dig_port)
6068 continue;
6069
6070 if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
6071 if (!intel_dig_port->dp.can_mst)
6072 continue;
6073 if (intel_dig_port->dp.is_mst)
6074 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
6075 }
6076 }
6077}
6078
6079void intel_dp_mst_resume(struct drm_device *dev)
6080{
6081 struct drm_i915_private *dev_priv = dev->dev_private;
6082 int i;
6083
6084 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006085 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Dave Airlie0e32b392014-05-02 14:02:48 +10006086 if (!intel_dig_port)
6087 continue;
6088 if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
6089 int ret;
6090
6091 if (!intel_dig_port->dp.can_mst)
6092 continue;
6093
6094 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6095 if (ret != 0) {
6096 intel_dp_check_mst_status(&intel_dig_port->dp);
6097 }
6098 }
6099 }
6100}