blob: 8f17c882929b748d46388eb809986bebb56a224f [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300159 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
160
161 return min(source_max, sink_max);
162}
163
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400164/*
165 * The units on the numbers in the next two are... bizarre. Examples will
166 * make it clearer; this one parallels an example in the eDP spec.
167 *
168 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
169 *
170 * 270000 * 1 * 8 / 10 == 216000
171 *
172 * The actual data capacity of that configuration is 2.16Gbit/s, so the
173 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
174 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
175 * 119000. At 18bpp that's 2142000 kilobits per second.
176 *
177 * Thus the strange-looking division by 10 in intel_dp_link_required, to
178 * get the result in decakilobits instead of kilobits.
179 */
180
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181static int
Keith Packardc8982612012-01-25 08:16:25 -0800182intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700183{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400184 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185}
186
187static int
Dave Airliefe27d532010-06-30 11:46:17 +1000188intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189{
190 return (max_link_clock * max_lanes * 8) / 10;
191}
192
Mika Kahola70ec0642016-09-09 14:10:55 +0300193static int
194intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
195{
196 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
197 struct intel_encoder *encoder = &intel_dig_port->base;
198 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
199 int max_dotclk = dev_priv->max_dotclk_freq;
200 int ds_max_dotclk;
201
202 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
203
204 if (type != DP_DS_PORT_TYPE_VGA)
205 return max_dotclk;
206
207 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
208 intel_dp->downstream_ports);
209
210 if (ds_max_dotclk != 0)
211 max_dotclk = min(max_dotclk, ds_max_dotclk);
212
213 return max_dotclk;
214}
215
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000216static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700217intel_dp_mode_valid(struct drm_connector *connector,
218 struct drm_display_mode *mode)
219{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100220 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300221 struct intel_connector *intel_connector = to_intel_connector(connector);
222 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100223 int target_clock = mode->clock;
224 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300225 int max_dotclk;
226
227 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700228
Jani Nikuladd06f902012-10-19 14:51:50 +0300229 if (is_edp(intel_dp) && fixed_mode) {
230 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100231 return MODE_PANEL;
232
Jani Nikuladd06f902012-10-19 14:51:50 +0300233 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100234 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200235
236 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100237 }
238
Ville Syrjälä50fec212015-03-12 17:10:34 +0200239 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300240 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100241
242 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
243 mode_rate = intel_dp_link_required(target_clock, 18);
244
Mika Kahola799487f2016-02-02 15:16:38 +0200245 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200246 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700247
248 if (mode->clock < 10000)
249 return MODE_CLOCK_LOW;
250
Daniel Vetter0af78a22012-05-23 11:30:55 +0200251 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
252 return MODE_H_ILLEGAL;
253
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700254 return MODE_OK;
255}
256
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800257uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700258{
259 int i;
260 uint32_t v = 0;
261
262 if (src_bytes > 4)
263 src_bytes = 4;
264 for (i = 0; i < src_bytes; i++)
265 v |= ((uint32_t) src[i]) << ((3-i) * 8);
266 return v;
267}
268
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000269static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700270{
271 int i;
272 if (dst_bytes > 4)
273 dst_bytes = 4;
274 for (i = 0; i < dst_bytes; i++)
275 dst[i] = src >> ((3-i) * 8);
276}
277
Jani Nikulabf13e812013-09-06 07:40:05 +0300278static void
279intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300280 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300281static void
282intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300283 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300284static void
285intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300286
Ville Syrjälä773538e82014-09-04 14:54:56 +0300287static void pps_lock(struct intel_dp *intel_dp)
288{
289 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
290 struct intel_encoder *encoder = &intel_dig_port->base;
291 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100292 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300293 enum intel_display_power_domain power_domain;
294
295 /*
296 * See vlv_power_sequencer_reset() why we need
297 * a power domain reference here.
298 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100299 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300300 intel_display_power_get(dev_priv, power_domain);
301
302 mutex_lock(&dev_priv->pps_mutex);
303}
304
305static void pps_unlock(struct intel_dp *intel_dp)
306{
307 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
308 struct intel_encoder *encoder = &intel_dig_port->base;
309 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100310 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300311 enum intel_display_power_domain power_domain;
312
313 mutex_unlock(&dev_priv->pps_mutex);
314
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100315 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300316 intel_display_power_put(dev_priv, power_domain);
317}
318
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300319static void
320vlv_power_sequencer_kick(struct intel_dp *intel_dp)
321{
322 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
323 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100324 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300325 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300326 bool pll_enabled, release_cl_override = false;
327 enum dpio_phy phy = DPIO_PHY(pipe);
328 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300329 uint32_t DP;
330
331 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
332 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
333 pipe_name(pipe), port_name(intel_dig_port->port)))
334 return;
335
336 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
337 pipe_name(pipe), port_name(intel_dig_port->port));
338
339 /* Preserve the BIOS-computed detected bit. This is
340 * supposed to be read-only.
341 */
342 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
343 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
344 DP |= DP_PORT_WIDTH(1);
345 DP |= DP_LINK_TRAIN_PAT_1;
346
347 if (IS_CHERRYVIEW(dev))
348 DP |= DP_PIPE_SELECT_CHV(pipe);
349 else if (pipe == PIPE_B)
350 DP |= DP_PIPEB_SELECT;
351
Ville Syrjäläd288f652014-10-28 13:20:22 +0200352 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
353
354 /*
355 * The DPLL for the pipe must be enabled for this to work.
356 * So enable temporarily it if it's not already enabled.
357 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300358 if (!pll_enabled) {
359 release_cl_override = IS_CHERRYVIEW(dev) &&
360 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
361
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000362 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
363 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
364 DRM_ERROR("Failed to force on pll for pipe %c!\n",
365 pipe_name(pipe));
366 return;
367 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300368 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200369
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300370 /*
371 * Similar magic as in intel_dp_enable_port().
372 * We _must_ do this port enable + disable trick
373 * to make this power seqeuencer lock onto the port.
374 * Otherwise even VDD force bit won't work.
375 */
376 I915_WRITE(intel_dp->output_reg, DP);
377 POSTING_READ(intel_dp->output_reg);
378
379 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
380 POSTING_READ(intel_dp->output_reg);
381
382 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
383 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200384
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300385 if (!pll_enabled) {
Ville Syrjäläd288f652014-10-28 13:20:22 +0200386 vlv_force_pll_off(dev, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300387
388 if (release_cl_override)
389 chv_phy_powergate_ch(dev_priv, phy, ch, false);
390 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300391}
392
Jani Nikulabf13e812013-09-06 07:40:05 +0300393static enum pipe
394vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
395{
396 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300397 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100398 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300399 struct intel_encoder *encoder;
400 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300401 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300402
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300403 lockdep_assert_held(&dev_priv->pps_mutex);
404
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300405 /* We should never land here with regular DP ports */
406 WARN_ON(!is_edp(intel_dp));
407
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300408 if (intel_dp->pps_pipe != INVALID_PIPE)
409 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300410
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300411 /*
412 * We don't have power sequencer currently.
413 * Pick one that's not used by other ports.
414 */
Jani Nikula19c80542015-12-16 12:48:16 +0200415 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300416 struct intel_dp *tmp;
417
418 if (encoder->type != INTEL_OUTPUT_EDP)
419 continue;
420
421 tmp = enc_to_intel_dp(&encoder->base);
422
423 if (tmp->pps_pipe != INVALID_PIPE)
424 pipes &= ~(1 << tmp->pps_pipe);
425 }
426
427 /*
428 * Didn't find one. This should not happen since there
429 * are two power sequencers and up to two eDP ports.
430 */
431 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300432 pipe = PIPE_A;
433 else
434 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300435
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300436 vlv_steal_power_sequencer(dev, pipe);
437 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300438
439 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
440 pipe_name(intel_dp->pps_pipe),
441 port_name(intel_dig_port->port));
442
443 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300444 intel_dp_init_panel_power_sequencer(dev, intel_dp);
445 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300446
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300447 /*
448 * Even vdd force doesn't work until we've made
449 * the power sequencer lock in on the port.
450 */
451 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300452
453 return intel_dp->pps_pipe;
454}
455
Imre Deak78597992016-06-16 16:37:20 +0300456static int
457bxt_power_sequencer_idx(struct intel_dp *intel_dp)
458{
459 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
460 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100461 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300462
463 lockdep_assert_held(&dev_priv->pps_mutex);
464
465 /* We should never land here with regular DP ports */
466 WARN_ON(!is_edp(intel_dp));
467
468 /*
469 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
470 * mapping needs to be retrieved from VBT, for now just hard-code to
471 * use instance #0 always.
472 */
473 if (!intel_dp->pps_reset)
474 return 0;
475
476 intel_dp->pps_reset = false;
477
478 /*
479 * Only the HW needs to be reprogrammed, the SW state is fixed and
480 * has been setup during connector init.
481 */
482 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
483
484 return 0;
485}
486
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300487typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
488 enum pipe pipe);
489
490static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
491 enum pipe pipe)
492{
Imre Deak44cb7342016-08-10 14:07:29 +0300493 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300494}
495
496static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
497 enum pipe pipe)
498{
Imre Deak44cb7342016-08-10 14:07:29 +0300499 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300500}
501
502static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
503 enum pipe pipe)
504{
505 return true;
506}
507
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300508static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300509vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
510 enum port port,
511 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300512{
Jani Nikulabf13e812013-09-06 07:40:05 +0300513 enum pipe pipe;
514
Jani Nikulabf13e812013-09-06 07:40:05 +0300515 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300516 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300517 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300518
519 if (port_sel != PANEL_PORT_SELECT_VLV(port))
520 continue;
521
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300522 if (!pipe_check(dev_priv, pipe))
523 continue;
524
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300525 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300526 }
527
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300528 return INVALID_PIPE;
529}
530
531static void
532vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
533{
534 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
535 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100536 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300537 enum port port = intel_dig_port->port;
538
539 lockdep_assert_held(&dev_priv->pps_mutex);
540
541 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300542 /* first pick one where the panel is on */
543 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
544 vlv_pipe_has_pp_on);
545 /* didn't find one? pick one where vdd is on */
546 if (intel_dp->pps_pipe == INVALID_PIPE)
547 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
548 vlv_pipe_has_vdd_on);
549 /* didn't find one? pick one with just the correct port */
550 if (intel_dp->pps_pipe == INVALID_PIPE)
551 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
552 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300553
554 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
555 if (intel_dp->pps_pipe == INVALID_PIPE) {
556 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
557 port_name(port));
558 return;
559 }
560
561 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
562 port_name(port), pipe_name(intel_dp->pps_pipe));
563
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300564 intel_dp_init_panel_power_sequencer(dev, intel_dp);
565 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300566}
567
Imre Deak78597992016-06-16 16:37:20 +0300568void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300569{
Chris Wilson91c8a322016-07-05 10:40:23 +0100570 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300571 struct intel_encoder *encoder;
572
Imre Deak78597992016-06-16 16:37:20 +0300573 if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
574 !IS_BROXTON(dev)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300575 return;
576
577 /*
578 * We can't grab pps_mutex here due to deadlock with power_domain
579 * mutex when power_domain functions are called while holding pps_mutex.
580 * That also means that in order to use pps_pipe the code needs to
581 * hold both a power domain reference and pps_mutex, and the power domain
582 * reference get/put must be done while _not_ holding pps_mutex.
583 * pps_{lock,unlock}() do these steps in the correct order, so one
584 * should use them always.
585 */
586
Jani Nikula19c80542015-12-16 12:48:16 +0200587 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300588 struct intel_dp *intel_dp;
589
590 if (encoder->type != INTEL_OUTPUT_EDP)
591 continue;
592
593 intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak78597992016-06-16 16:37:20 +0300594 if (IS_BROXTON(dev))
595 intel_dp->pps_reset = true;
596 else
597 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300598 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300599}
600
Imre Deak8e8232d2016-06-16 16:37:21 +0300601struct pps_registers {
602 i915_reg_t pp_ctrl;
603 i915_reg_t pp_stat;
604 i915_reg_t pp_on;
605 i915_reg_t pp_off;
606 i915_reg_t pp_div;
607};
608
609static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
610 struct intel_dp *intel_dp,
611 struct pps_registers *regs)
612{
Imre Deak44cb7342016-08-10 14:07:29 +0300613 int pps_idx = 0;
614
Imre Deak8e8232d2016-06-16 16:37:21 +0300615 memset(regs, 0, sizeof(*regs));
616
Imre Deak44cb7342016-08-10 14:07:29 +0300617 if (IS_BROXTON(dev_priv))
618 pps_idx = bxt_power_sequencer_idx(intel_dp);
619 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
620 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300621
Imre Deak44cb7342016-08-10 14:07:29 +0300622 regs->pp_ctrl = PP_CONTROL(pps_idx);
623 regs->pp_stat = PP_STATUS(pps_idx);
624 regs->pp_on = PP_ON_DELAYS(pps_idx);
625 regs->pp_off = PP_OFF_DELAYS(pps_idx);
626 if (!IS_BROXTON(dev_priv))
627 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300628}
629
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200630static i915_reg_t
631_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300632{
Imre Deak8e8232d2016-06-16 16:37:21 +0300633 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300634
Imre Deak8e8232d2016-06-16 16:37:21 +0300635 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
636 &regs);
637
638 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300639}
640
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200641static i915_reg_t
642_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300643{
Imre Deak8e8232d2016-06-16 16:37:21 +0300644 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300645
Imre Deak8e8232d2016-06-16 16:37:21 +0300646 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
647 &regs);
648
649 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300650}
651
Clint Taylor01527b32014-07-07 13:01:46 -0700652/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
653 This function only applicable when panel PM state is not to be tracked */
654static int edp_notify_handler(struct notifier_block *this, unsigned long code,
655 void *unused)
656{
657 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
658 edp_notifier);
659 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100660 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700661
662 if (!is_edp(intel_dp) || code != SYS_RESTART)
663 return 0;
664
Ville Syrjälä773538e82014-09-04 14:54:56 +0300665 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300666
Wayne Boyer666a4532015-12-09 12:29:35 -0800667 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300668 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200669 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300670 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300671
Imre Deak44cb7342016-08-10 14:07:29 +0300672 pp_ctrl_reg = PP_CONTROL(pipe);
673 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700674 pp_div = I915_READ(pp_div_reg);
675 pp_div &= PP_REFERENCE_DIVIDER_MASK;
676
677 /* 0x1F write to PP_DIV_REG sets max cycle delay */
678 I915_WRITE(pp_div_reg, pp_div | 0x1F);
679 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
680 msleep(intel_dp->panel_power_cycle_delay);
681 }
682
Ville Syrjälä773538e82014-09-04 14:54:56 +0300683 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300684
Clint Taylor01527b32014-07-07 13:01:46 -0700685 return 0;
686}
687
Daniel Vetter4be73782014-01-17 14:39:48 +0100688static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700689{
Paulo Zanoni30add222012-10-26 19:05:45 -0200690 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100691 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700692
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300693 lockdep_assert_held(&dev_priv->pps_mutex);
694
Wayne Boyer666a4532015-12-09 12:29:35 -0800695 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300696 intel_dp->pps_pipe == INVALID_PIPE)
697 return false;
698
Jani Nikulabf13e812013-09-06 07:40:05 +0300699 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700700}
701
Daniel Vetter4be73782014-01-17 14:39:48 +0100702static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700703{
Paulo Zanoni30add222012-10-26 19:05:45 -0200704 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100705 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700706
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300707 lockdep_assert_held(&dev_priv->pps_mutex);
708
Wayne Boyer666a4532015-12-09 12:29:35 -0800709 if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300710 intel_dp->pps_pipe == INVALID_PIPE)
711 return false;
712
Ville Syrjälä773538e82014-09-04 14:54:56 +0300713 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700714}
715
Keith Packard9b984da2011-09-19 13:54:47 -0700716static void
717intel_dp_check_edp(struct intel_dp *intel_dp)
718{
Paulo Zanoni30add222012-10-26 19:05:45 -0200719 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100720 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700721
Keith Packard9b984da2011-09-19 13:54:47 -0700722 if (!is_edp(intel_dp))
723 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700724
Daniel Vetter4be73782014-01-17 14:39:48 +0100725 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700726 WARN(1, "eDP powered off while attempting aux channel communication.\n");
727 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300728 I915_READ(_pp_stat_reg(intel_dp)),
729 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700730 }
731}
732
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100733static uint32_t
734intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
735{
736 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
737 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100738 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200739 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100740 uint32_t status;
741 bool done;
742
Daniel Vetteref04f002012-12-01 21:03:59 +0100743#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100744 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300745 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300746 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100747 else
Imre Deak713a6b62016-06-28 13:37:33 +0300748 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100749 if (!done)
750 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
751 has_aux_irq);
752#undef C
753
754 return status;
755}
756
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200757static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000758{
759 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200760 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000761
Ville Syrjäläa457f542016-03-02 17:22:17 +0200762 if (index)
763 return 0;
764
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000765 /*
766 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200767 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000768 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200769 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000770}
771
772static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
773{
774 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200775 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000776
777 if (index)
778 return 0;
779
Ville Syrjäläa457f542016-03-02 17:22:17 +0200780 /*
781 * The clock divider is based off the cdclk or PCH rawclk, and would
782 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
783 * divide by 2000 and use that
784 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200785 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200786 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200787 else
788 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000789}
790
791static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300792{
793 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200794 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300795
Ville Syrjäläa457f542016-03-02 17:22:17 +0200796 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300797 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100798 switch (index) {
799 case 0: return 63;
800 case 1: return 72;
801 default: return 0;
802 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300803 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200804
805 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300806}
807
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000808static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
809{
810 /*
811 * SKL doesn't need us to program the AUX clock divider (Hardware will
812 * derive the clock from CDCLK automatically). We still implement the
813 * get_aux_clock_divider vfunc to plug-in into the existing code.
814 */
815 return index ? 0 : 1;
816}
817
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200818static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
819 bool has_aux_irq,
820 int send_bytes,
821 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000822{
823 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
824 struct drm_device *dev = intel_dig_port->base.base.dev;
825 uint32_t precharge, timeout;
826
827 if (IS_GEN6(dev))
828 precharge = 3;
829 else
830 precharge = 5;
831
Ville Syrjäläf3c6a3a2015-11-11 20:34:10 +0200832 if (IS_BROADWELL(dev) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000833 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
834 else
835 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
836
837 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000838 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000839 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000840 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000841 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000842 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000843 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
844 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000845 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000846}
847
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000848static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
849 bool has_aux_irq,
850 int send_bytes,
851 uint32_t unused)
852{
853 return DP_AUX_CH_CTL_SEND_BUSY |
854 DP_AUX_CH_CTL_DONE |
855 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
856 DP_AUX_CH_CTL_TIME_OUT_ERROR |
857 DP_AUX_CH_CTL_TIME_OUT_1600us |
858 DP_AUX_CH_CTL_RECEIVE_ERROR |
859 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200860 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000861 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
862}
863
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700864static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100865intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200866 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700867 uint8_t *recv, int recv_size)
868{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200869 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
870 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100871 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200872 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100873 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100874 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700875 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000876 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100877 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200878 bool vdd;
879
Ville Syrjälä773538e82014-09-04 14:54:56 +0300880 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300881
Ville Syrjälä72c35002014-08-18 22:16:00 +0300882 /*
883 * We will be called with VDD already enabled for dpcd/edid/oui reads.
884 * In such cases we want to leave VDD enabled and it's up to upper layers
885 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
886 * ourselves.
887 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300888 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100889
890 /* dp aux is extremely sensitive to irq latency, hence request the
891 * lowest possible wakeup latency and so prevent the cpu from going into
892 * deep sleep states.
893 */
894 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700895
Keith Packard9b984da2011-09-19 13:54:47 -0700896 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800897
Jesse Barnes11bee432011-08-01 15:02:20 -0700898 /* Try to wait for any previous AUX channel activity */
899 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100900 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700901 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
902 break;
903 msleep(1);
904 }
905
906 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300907 static u32 last_status = -1;
908 const u32 status = I915_READ(ch_ctl);
909
910 if (status != last_status) {
911 WARN(1, "dp_aux_ch not started status 0x%08x\n",
912 status);
913 last_status = status;
914 }
915
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100916 ret = -EBUSY;
917 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100918 }
919
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300920 /* Only 5 data registers! */
921 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
922 ret = -E2BIG;
923 goto out;
924 }
925
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000926 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000927 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
928 has_aux_irq,
929 send_bytes,
930 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000931
Chris Wilsonbc866252013-07-21 16:00:03 +0100932 /* Must try at least 3 times according to DP spec */
933 for (try = 0; try < 5; try++) {
934 /* Load the send data into the aux channel data registers */
935 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200936 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800937 intel_dp_pack_aux(send + i,
938 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400939
Chris Wilsonbc866252013-07-21 16:00:03 +0100940 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000941 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100942
Chris Wilsonbc866252013-07-21 16:00:03 +0100943 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400944
Chris Wilsonbc866252013-07-21 16:00:03 +0100945 /* Clear done status and any errors */
946 I915_WRITE(ch_ctl,
947 status |
948 DP_AUX_CH_CTL_DONE |
949 DP_AUX_CH_CTL_TIME_OUT_ERROR |
950 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400951
Todd Previte74ebf292015-04-15 08:38:41 -0700952 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +0100953 continue;
Todd Previte74ebf292015-04-15 08:38:41 -0700954
955 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
956 * 400us delay required for errors and timeouts
957 * Timeout errors from the HW already meet this
958 * requirement so skip to next iteration
959 */
960 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
961 usleep_range(400, 500);
962 continue;
963 }
Chris Wilsonbc866252013-07-21 16:00:03 +0100964 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -0700965 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +0100966 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700967 }
968
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700969 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700970 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100971 ret = -EBUSY;
972 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700973 }
974
Jim Bridee058c942015-05-27 10:21:48 -0700975done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700976 /* Check for timeout or receive error.
977 * Timeouts occur when the sink is not connected
978 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700979 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700980 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100981 ret = -EIO;
982 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700983 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700984
985 /* Timeouts occur when the device isn't connected, so they're
986 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700987 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800988 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100989 ret = -ETIMEDOUT;
990 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700991 }
992
993 /* Unload any bytes sent back from the other side */
994 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
995 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -0800996
997 /*
998 * By BSpec: "Message sizes of 0 or >20 are not allowed."
999 * We have no idea of what happened so we return -EBUSY so
1000 * drm layer takes care for the necessary retries.
1001 */
1002 if (recv_bytes == 0 || recv_bytes > 20) {
1003 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1004 recv_bytes);
1005 /*
1006 * FIXME: This patch was created on top of a series that
1007 * organize the retries at drm level. There EBUSY should
1008 * also take care for 1ms wait before retrying.
1009 * That aux retries re-org is still needed and after that is
1010 * merged we remove this sleep from here.
1011 */
1012 usleep_range(1000, 1500);
1013 ret = -EBUSY;
1014 goto out;
1015 }
1016
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001017 if (recv_bytes > recv_size)
1018 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001019
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001020 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001021 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001022 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001023
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001024 ret = recv_bytes;
1025out:
1026 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1027
Jani Nikula884f19e2014-03-14 16:51:14 +02001028 if (vdd)
1029 edp_panel_vdd_off(intel_dp, false);
1030
Ville Syrjälä773538e82014-09-04 14:54:56 +03001031 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001032
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001033 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001034}
1035
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001036#define BARE_ADDRESS_SIZE 3
1037#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001038static ssize_t
1039intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001040{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001041 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1042 uint8_t txbuf[20], rxbuf[20];
1043 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001044 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001045
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001046 txbuf[0] = (msg->request << 4) |
1047 ((msg->address >> 16) & 0xf);
1048 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001049 txbuf[2] = msg->address & 0xff;
1050 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001051
Jani Nikula9d1a1032014-03-14 16:51:15 +02001052 switch (msg->request & ~DP_AUX_I2C_MOT) {
1053 case DP_AUX_NATIVE_WRITE:
1054 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001055 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001056 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001057 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001058
Jani Nikula9d1a1032014-03-14 16:51:15 +02001059 if (WARN_ON(txsize > 20))
1060 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001061
Ville Syrjälädd7880902016-07-28 17:55:04 +03001062 WARN_ON(!msg->buffer != !msg->size);
1063
Imre Deakd81a67c2016-01-29 14:52:26 +02001064 if (msg->buffer)
1065 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001066
Jani Nikula9d1a1032014-03-14 16:51:15 +02001067 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1068 if (ret > 0) {
1069 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001070
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001071 if (ret > 1) {
1072 /* Number of bytes written in a short write. */
1073 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1074 } else {
1075 /* Return payload size. */
1076 ret = msg->size;
1077 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001078 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001079 break;
1080
1081 case DP_AUX_NATIVE_READ:
1082 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001083 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001084 rxsize = msg->size + 1;
1085
1086 if (WARN_ON(rxsize > 20))
1087 return -E2BIG;
1088
1089 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1090 if (ret > 0) {
1091 msg->reply = rxbuf[0] >> 4;
1092 /*
1093 * Assume happy day, and copy the data. The caller is
1094 * expected to check msg->reply before touching it.
1095 *
1096 * Return payload size.
1097 */
1098 ret--;
1099 memcpy(msg->buffer, rxbuf + 1, ret);
1100 }
1101 break;
1102
1103 default:
1104 ret = -EINVAL;
1105 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001106 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001107
Jani Nikula9d1a1032014-03-14 16:51:15 +02001108 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001109}
1110
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001111static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1112 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001113{
1114 switch (port) {
1115 case PORT_B:
1116 case PORT_C:
1117 case PORT_D:
1118 return DP_AUX_CH_CTL(port);
1119 default:
1120 MISSING_CASE(port);
1121 return DP_AUX_CH_CTL(PORT_B);
1122 }
1123}
1124
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001125static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1126 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001127{
1128 switch (port) {
1129 case PORT_B:
1130 case PORT_C:
1131 case PORT_D:
1132 return DP_AUX_CH_DATA(port, index);
1133 default:
1134 MISSING_CASE(port);
1135 return DP_AUX_CH_DATA(PORT_B, index);
1136 }
1137}
1138
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001139static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1140 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001141{
1142 switch (port) {
1143 case PORT_A:
1144 return DP_AUX_CH_CTL(port);
1145 case PORT_B:
1146 case PORT_C:
1147 case PORT_D:
1148 return PCH_DP_AUX_CH_CTL(port);
1149 default:
1150 MISSING_CASE(port);
1151 return DP_AUX_CH_CTL(PORT_A);
1152 }
1153}
1154
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001155static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1156 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001157{
1158 switch (port) {
1159 case PORT_A:
1160 return DP_AUX_CH_DATA(port, index);
1161 case PORT_B:
1162 case PORT_C:
1163 case PORT_D:
1164 return PCH_DP_AUX_CH_DATA(port, index);
1165 default:
1166 MISSING_CASE(port);
1167 return DP_AUX_CH_DATA(PORT_A, index);
1168 }
1169}
1170
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001171/*
1172 * On SKL we don't have Aux for port E so we rely
1173 * on VBT to set a proper alternate aux channel.
1174 */
1175static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
1176{
1177 const struct ddi_vbt_port_info *info =
1178 &dev_priv->vbt.ddi_port_info[PORT_E];
1179
1180 switch (info->alternate_aux_channel) {
1181 case DP_AUX_A:
1182 return PORT_A;
1183 case DP_AUX_B:
1184 return PORT_B;
1185 case DP_AUX_C:
1186 return PORT_C;
1187 case DP_AUX_D:
1188 return PORT_D;
1189 default:
1190 MISSING_CASE(info->alternate_aux_channel);
1191 return PORT_A;
1192 }
1193}
1194
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001195static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1196 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001197{
1198 if (port == PORT_E)
1199 port = skl_porte_aux_port(dev_priv);
1200
1201 switch (port) {
1202 case PORT_A:
1203 case PORT_B:
1204 case PORT_C:
1205 case PORT_D:
1206 return DP_AUX_CH_CTL(port);
1207 default:
1208 MISSING_CASE(port);
1209 return DP_AUX_CH_CTL(PORT_A);
1210 }
1211}
1212
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001213static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1214 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001215{
1216 if (port == PORT_E)
1217 port = skl_porte_aux_port(dev_priv);
1218
1219 switch (port) {
1220 case PORT_A:
1221 case PORT_B:
1222 case PORT_C:
1223 case PORT_D:
1224 return DP_AUX_CH_DATA(port, index);
1225 default:
1226 MISSING_CASE(port);
1227 return DP_AUX_CH_DATA(PORT_A, index);
1228 }
1229}
1230
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001231static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1232 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001233{
1234 if (INTEL_INFO(dev_priv)->gen >= 9)
1235 return skl_aux_ctl_reg(dev_priv, port);
1236 else if (HAS_PCH_SPLIT(dev_priv))
1237 return ilk_aux_ctl_reg(dev_priv, port);
1238 else
1239 return g4x_aux_ctl_reg(dev_priv, port);
1240}
1241
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001242static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1243 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001244{
1245 if (INTEL_INFO(dev_priv)->gen >= 9)
1246 return skl_aux_data_reg(dev_priv, port, index);
1247 else if (HAS_PCH_SPLIT(dev_priv))
1248 return ilk_aux_data_reg(dev_priv, port, index);
1249 else
1250 return g4x_aux_data_reg(dev_priv, port, index);
1251}
1252
1253static void intel_aux_reg_init(struct intel_dp *intel_dp)
1254{
1255 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1256 enum port port = dp_to_dig_port(intel_dp)->port;
1257 int i;
1258
1259 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1260 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1261 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1262}
1263
Jani Nikula9d1a1032014-03-14 16:51:15 +02001264static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001265intel_dp_aux_fini(struct intel_dp *intel_dp)
1266{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001267 kfree(intel_dp->aux.name);
1268}
1269
Chris Wilson7a418e32016-06-24 14:00:14 +01001270static void
Mika Kaholab6339582016-09-09 14:10:52 +03001271intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001272{
Jani Nikula33ad6622014-03-14 16:51:16 +02001273 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1274 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001275
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001276 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001277 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001278
Chris Wilson7a418e32016-06-24 14:00:14 +01001279 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001280 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001281 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001282}
1283
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301284static int
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001285intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301286{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001287 if (intel_dp->num_sink_rates) {
1288 *sink_rates = intel_dp->sink_rates;
1289 return intel_dp->num_sink_rates;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301290 }
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001291
1292 *sink_rates = default_rates;
1293
1294 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301295}
1296
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001297bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301298{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001299 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1300 struct drm_device *dev = dig_port->base.base.dev;
1301
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301302 /* WaDisableHBR2:skl */
Jani Nikulae87a0052015-10-20 15:22:02 +03001303 if (IS_SKL_REVID(dev, 0, SKL_REVID_B0))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301304 return false;
1305
1306 if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) ||
1307 (INTEL_INFO(dev)->gen >= 9))
1308 return true;
1309 else
1310 return false;
1311}
1312
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301313static int
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001314intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301315{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001316 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1317 struct drm_device *dev = dig_port->base.base.dev;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301318 int size;
1319
Sonika Jindal64987fc2015-05-26 17:50:13 +05301320 if (IS_BROXTON(dev)) {
1321 *source_rates = bxt_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301322 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001323 } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Sonika Jindal637a9c62015-05-07 09:52:08 +05301324 *source_rates = skl_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301325 size = ARRAY_SIZE(skl_rates);
1326 } else {
1327 *source_rates = default_rates;
1328 size = ARRAY_SIZE(default_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301329 }
Ville Syrjälä636280b2015-03-12 17:10:29 +02001330
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301331 /* This depends on the fact that 5.4 is last value in the array */
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001332 if (!intel_dp_source_supports_hbr2(intel_dp))
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301333 size--;
Ville Syrjälä636280b2015-03-12 17:10:29 +02001334
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301335 return size;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301336}
1337
Daniel Vetter0e503382014-07-04 11:26:04 -03001338static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001339intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001340 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001341{
1342 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001343 const struct dp_link_dpll *divisor = NULL;
1344 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001345
1346 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001347 divisor = gen4_dpll;
1348 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001349 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001350 divisor = pch_dpll;
1351 count = ARRAY_SIZE(pch_dpll);
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001352 } else if (IS_CHERRYVIEW(dev)) {
1353 divisor = chv_dpll;
1354 count = ARRAY_SIZE(chv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001355 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001356 divisor = vlv_dpll;
1357 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001358 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001359
1360 if (divisor && count) {
1361 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001362 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001363 pipe_config->dpll = divisor[i].dpll;
1364 pipe_config->clock_set = true;
1365 break;
1366 }
1367 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001368 }
1369}
1370
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001371static int intersect_rates(const int *source_rates, int source_len,
1372 const int *sink_rates, int sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001373 int *common_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301374{
1375 int i = 0, j = 0, k = 0;
1376
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301377 while (i < source_len && j < sink_len) {
1378 if (source_rates[i] == sink_rates[j]) {
Ville Syrjäläe6bda3e2015-03-12 17:10:37 +02001379 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
1380 return k;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001381 common_rates[k] = source_rates[i];
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301382 ++k;
1383 ++i;
1384 ++j;
1385 } else if (source_rates[i] < sink_rates[j]) {
1386 ++i;
1387 } else {
1388 ++j;
1389 }
1390 }
1391 return k;
1392}
1393
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001394static int intel_dp_common_rates(struct intel_dp *intel_dp,
1395 int *common_rates)
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001396{
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001397 const int *source_rates, *sink_rates;
1398 int source_len, sink_len;
1399
1400 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001401 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001402
1403 return intersect_rates(source_rates, source_len,
1404 sink_rates, sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001405 common_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001406}
1407
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001408static void snprintf_int_array(char *str, size_t len,
1409 const int *array, int nelem)
1410{
1411 int i;
1412
1413 str[0] = '\0';
1414
1415 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001416 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001417 if (r >= len)
1418 return;
1419 str += r;
1420 len -= r;
1421 }
1422}
1423
1424static void intel_dp_print_rates(struct intel_dp *intel_dp)
1425{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001426 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001427 int source_len, sink_len, common_len;
1428 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001429 char str[128]; /* FIXME: too big for stack? */
1430
1431 if ((drm_debug & DRM_UT_KMS) == 0)
1432 return;
1433
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001434 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001435 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1436 DRM_DEBUG_KMS("source rates: %s\n", str);
1437
1438 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1439 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1440 DRM_DEBUG_KMS("sink rates: %s\n", str);
1441
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001442 common_len = intel_dp_common_rates(intel_dp, common_rates);
1443 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1444 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001445}
1446
Mika Kahola0e390a32016-09-09 14:10:53 +03001447static void intel_dp_print_hw_revision(struct intel_dp *intel_dp)
1448{
1449 uint8_t rev;
1450 int len;
1451
1452 if ((drm_debug & DRM_UT_KMS) == 0)
1453 return;
1454
1455 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1456 DP_DWN_STRM_PORT_PRESENT))
1457 return;
1458
1459 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_HW_REV, &rev, 1);
1460 if (len < 0)
1461 return;
1462
1463 DRM_DEBUG_KMS("sink hw revision: %d.%d\n", (rev & 0xf0) >> 4, rev & 0xf);
1464}
1465
Mika Kahola1a2724f2016-09-09 14:10:54 +03001466static void intel_dp_print_sw_revision(struct intel_dp *intel_dp)
1467{
1468 uint8_t rev[2];
1469 int len;
1470
1471 if ((drm_debug & DRM_UT_KMS) == 0)
1472 return;
1473
1474 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1475 DP_DWN_STRM_PORT_PRESENT))
1476 return;
1477
1478 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_SW_REV, &rev, 2);
1479 if (len < 0)
1480 return;
1481
1482 DRM_DEBUG_KMS("sink sw revision: %d.%d\n", rev[0], rev[1]);
1483}
1484
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001485static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301486{
1487 int i = 0;
1488
1489 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1490 if (find == rates[i])
1491 break;
1492
1493 return i;
1494}
1495
Ville Syrjälä50fec212015-03-12 17:10:34 +02001496int
1497intel_dp_max_link_rate(struct intel_dp *intel_dp)
1498{
1499 int rates[DP_MAX_SUPPORTED_RATES] = {};
1500 int len;
1501
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001502 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001503 if (WARN_ON(len <= 0))
1504 return 162000;
1505
Ville Syrjälä1354f732016-07-28 17:50:45 +03001506 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001507}
1508
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001509int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1510{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001511 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001512}
1513
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001514void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1515 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001516{
1517 if (intel_dp->num_sink_rates) {
1518 *link_bw = 0;
1519 *rate_select =
1520 intel_dp_rate_select(intel_dp, port_clock);
1521 } else {
1522 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1523 *rate_select = 0;
1524 }
1525}
1526
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001527bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001528intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001529 struct intel_crtc_state *pipe_config,
1530 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001531{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001532 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001533 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001534 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001535 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001536 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001537 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001538 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001539 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001540 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001541 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001542 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001543 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301544 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001545 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001546 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001547 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1548 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001549 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301550
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001551 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301552
1553 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001554 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301555
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001556 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001557
Imre Deakbc7d38a2013-05-16 14:40:36 +03001558 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001559 pipe_config->has_pch_encoder = true;
1560
Vandana Kannanf769cd22014-08-05 07:51:22 -07001561 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001562 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001563
Jani Nikuladd06f902012-10-19 14:51:50 +03001564 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1565 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1566 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001567
1568 if (INTEL_INFO(dev)->gen >= 9) {
1569 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001570 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001571 if (ret)
1572 return ret;
1573 }
1574
Matt Roperb56676272015-11-04 09:05:27 -08001575 if (HAS_GMCH_DISPLAY(dev))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001576 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1577 intel_connector->panel.fitting_mode);
1578 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001579 intel_pch_panel_fitting(intel_crtc, pipe_config,
1580 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001581 }
1582
Daniel Vettercb1793c2012-06-04 18:39:21 +02001583 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001584 return false;
1585
Daniel Vetter083f9562012-04-20 20:23:49 +02001586 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301587 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001588 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001589 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001590
Daniel Vetter36008362013-03-27 00:44:59 +01001591 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1592 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +02001593 bpp = pipe_config->pipe_bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001594 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301595
1596 /* Get bpp from vbt only for panels that dont have bpp in edid */
1597 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001598 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001599 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001600 dev_priv->vbt.edp.bpp);
1601 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001602 }
1603
Jani Nikula344c5bb2014-09-09 11:25:13 +03001604 /*
1605 * Use the maximum clock and number of lanes the eDP panel
1606 * advertizes being capable of. The panels are generally
1607 * designed to support only a single clock and lane
1608 * configuration, and typically these values correspond to the
1609 * native resolution of the panel.
1610 */
1611 min_lane_count = max_lane_count;
1612 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001613 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001614
Daniel Vetter36008362013-03-27 00:44:59 +01001615 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001616 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1617 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001618
Dave Airliec6930992014-07-14 11:04:39 +10001619 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301620 for (lane_count = min_lane_count;
1621 lane_count <= max_lane_count;
1622 lane_count <<= 1) {
1623
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001624 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001625 link_avail = intel_dp_max_data_rate(link_clock,
1626 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001627
Daniel Vetter36008362013-03-27 00:44:59 +01001628 if (mode_rate <= link_avail) {
1629 goto found;
1630 }
1631 }
1632 }
1633 }
1634
1635 return false;
1636
1637found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001638 if (intel_dp->color_range_auto) {
1639 /*
1640 * See:
1641 * CEA-861-E - 5.1 Default Encoding Parameters
1642 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1643 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001644 pipe_config->limited_color_range =
1645 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1646 } else {
1647 pipe_config->limited_color_range =
1648 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001649 }
1650
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001651 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301652
Daniel Vetter657445f2013-05-04 10:09:18 +02001653 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001654 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001655
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001656 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1657 &link_bw, &rate_select);
1658
1659 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1660 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001661 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001662 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1663 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001664
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001665 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001666 adjusted_mode->crtc_clock,
1667 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001668 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001669
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301670 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301671 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001672 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301673 intel_link_compute_m_n(bpp, lane_count,
1674 intel_connector->panel.downclock_mode->clock,
1675 pipe_config->port_clock,
1676 &pipe_config->dp_m2_n2);
1677 }
1678
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001679 /*
1680 * DPLL0 VCO may need to be adjusted to get the correct
1681 * clock for eDP. This will affect cdclk as well.
1682 */
1683 if (is_edp(intel_dp) &&
1684 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1685 int vco;
1686
1687 switch (pipe_config->port_clock / 2) {
1688 case 108000:
1689 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001690 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001691 break;
1692 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001693 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001694 break;
1695 }
1696
1697 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1698 }
1699
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02001700 if (!HAS_DDI(dev))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001701 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001702
Daniel Vetter36008362013-03-27 00:44:59 +01001703 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001704}
1705
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001706void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001707 int link_rate, uint8_t lane_count,
1708 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001709{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001710 intel_dp->link_rate = link_rate;
1711 intel_dp->lane_count = lane_count;
1712 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001713}
1714
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001715static void intel_dp_prepare(struct intel_encoder *encoder,
1716 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001717{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001718 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001719 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001720 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001721 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001722 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001723 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001724
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001725 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1726 pipe_config->lane_count,
1727 intel_crtc_has_type(pipe_config,
1728 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001729
Keith Packard417e8222011-11-01 19:54:11 -07001730 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001731 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001732 *
1733 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001734 * SNB CPU
1735 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001736 * CPT PCH
1737 *
1738 * IBX PCH and CPU are the same for almost everything,
1739 * except that the CPU DP PLL is configured in this
1740 * register
1741 *
1742 * CPT PCH is quite different, having many bits moved
1743 * to the TRANS_DP_CTL register instead. That
1744 * configuration happens (oddly) in ironlake_pch_enable
1745 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001746
Keith Packard417e8222011-11-01 19:54:11 -07001747 /* Preserve the BIOS-computed detected bit. This is
1748 * supposed to be read-only.
1749 */
1750 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001751
Keith Packard417e8222011-11-01 19:54:11 -07001752 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001753 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001754 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001755
Keith Packard417e8222011-11-01 19:54:11 -07001756 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001757
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001758 if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001759 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1760 intel_dp->DP |= DP_SYNC_HS_HIGH;
1761 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1762 intel_dp->DP |= DP_SYNC_VS_HIGH;
1763 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1764
Jani Nikula6aba5b62013-10-04 15:08:10 +03001765 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001766 intel_dp->DP |= DP_ENHANCED_FRAMING;
1767
Daniel Vetter7c62a162013-06-01 17:16:20 +02001768 intel_dp->DP |= crtc->pipe << 29;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001769 } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001770 u32 trans_dp;
1771
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001772 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001773
1774 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1775 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1776 trans_dp |= TRANS_DP_ENH_FRAMING;
1777 else
1778 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1779 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001780 } else {
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001781 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001782 !IS_CHERRYVIEW(dev) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001783 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001784
1785 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1786 intel_dp->DP |= DP_SYNC_HS_HIGH;
1787 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1788 intel_dp->DP |= DP_SYNC_VS_HIGH;
1789 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1790
Jani Nikula6aba5b62013-10-04 15:08:10 +03001791 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001792 intel_dp->DP |= DP_ENHANCED_FRAMING;
1793
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001794 if (IS_CHERRYVIEW(dev))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001795 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001796 else if (crtc->pipe == PIPE_B)
1797 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001798 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001799}
1800
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001801#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1802#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001803
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001804#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1805#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001806
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001807#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1808#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001809
Imre Deakde9c1b62016-06-16 20:01:46 +03001810static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1811 struct intel_dp *intel_dp);
1812
Daniel Vetter4be73782014-01-17 14:39:48 +01001813static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001814 u32 mask,
1815 u32 value)
1816{
Paulo Zanoni30add222012-10-26 19:05:45 -02001817 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001818 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001819 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001820
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001821 lockdep_assert_held(&dev_priv->pps_mutex);
1822
Imre Deakde9c1b62016-06-16 20:01:46 +03001823 intel_pps_verify_state(dev_priv, intel_dp);
1824
Jani Nikulabf13e812013-09-06 07:40:05 +03001825 pp_stat_reg = _pp_stat_reg(intel_dp);
1826 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001827
1828 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001829 mask, value,
1830 I915_READ(pp_stat_reg),
1831 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001832
Chris Wilson9036ff02016-06-30 15:33:09 +01001833 if (intel_wait_for_register(dev_priv,
1834 pp_stat_reg, mask, value,
1835 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001836 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001837 I915_READ(pp_stat_reg),
1838 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001839
1840 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001841}
1842
Daniel Vetter4be73782014-01-17 14:39:48 +01001843static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001844{
1845 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001846 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001847}
1848
Daniel Vetter4be73782014-01-17 14:39:48 +01001849static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001850{
Keith Packardbd943152011-09-18 23:09:52 -07001851 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001852 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001853}
Keith Packardbd943152011-09-18 23:09:52 -07001854
Daniel Vetter4be73782014-01-17 14:39:48 +01001855static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001856{
Abhay Kumard28d4732016-01-22 17:39:04 -08001857 ktime_t panel_power_on_time;
1858 s64 panel_power_off_duration;
1859
Keith Packard99ea7122011-11-01 19:57:50 -07001860 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001861
Abhay Kumard28d4732016-01-22 17:39:04 -08001862 /* take the difference of currrent time and panel power off time
1863 * and then make panel wait for t11_t12 if needed. */
1864 panel_power_on_time = ktime_get_boottime();
1865 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1866
Paulo Zanonidce56b32013-12-19 14:29:40 -02001867 /* When we disable the VDD override bit last we have to do the manual
1868 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001869 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1870 wait_remaining_ms_from_jiffies(jiffies,
1871 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001872
Daniel Vetter4be73782014-01-17 14:39:48 +01001873 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001874}
Keith Packardbd943152011-09-18 23:09:52 -07001875
Daniel Vetter4be73782014-01-17 14:39:48 +01001876static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001877{
1878 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1879 intel_dp->backlight_on_delay);
1880}
1881
Daniel Vetter4be73782014-01-17 14:39:48 +01001882static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001883{
1884 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1885 intel_dp->backlight_off_delay);
1886}
Keith Packard99ea7122011-11-01 19:57:50 -07001887
Keith Packard832dd3c2011-11-01 19:34:06 -07001888/* Read the current pp_control value, unlocking the register if it
1889 * is locked
1890 */
1891
Jesse Barnes453c5422013-03-28 09:55:41 -07001892static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001893{
Jesse Barnes453c5422013-03-28 09:55:41 -07001894 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001895 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001896 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001897
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001898 lockdep_assert_held(&dev_priv->pps_mutex);
1899
Jani Nikulabf13e812013-09-06 07:40:05 +03001900 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001901 if (WARN_ON(!HAS_DDI(dev_priv) &&
1902 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301903 control &= ~PANEL_UNLOCK_MASK;
1904 control |= PANEL_UNLOCK_REGS;
1905 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001906 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001907}
1908
Ville Syrjälä951468f2014-09-04 14:55:31 +03001909/*
1910 * Must be paired with edp_panel_vdd_off().
1911 * Must hold pps_mutex around the whole on/off sequence.
1912 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1913 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001914static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001915{
Paulo Zanoni30add222012-10-26 19:05:45 -02001916 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001917 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1918 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001919 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001920 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001921 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001922 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001923 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001924
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001925 lockdep_assert_held(&dev_priv->pps_mutex);
1926
Keith Packard97af61f572011-09-28 16:23:51 -07001927 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001928 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001929
Egbert Eich2c623c12014-11-25 12:54:57 +01001930 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001931 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001932
Daniel Vetter4be73782014-01-17 14:39:48 +01001933 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001934 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001935
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001936 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001937 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001938
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001939 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1940 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001941
Daniel Vetter4be73782014-01-17 14:39:48 +01001942 if (!edp_have_panel_power(intel_dp))
1943 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001944
Jesse Barnes453c5422013-03-28 09:55:41 -07001945 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001946 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001947
Jani Nikulabf13e812013-09-06 07:40:05 +03001948 pp_stat_reg = _pp_stat_reg(intel_dp);
1949 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001950
1951 I915_WRITE(pp_ctrl_reg, pp);
1952 POSTING_READ(pp_ctrl_reg);
1953 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1954 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001955 /*
1956 * If the panel wasn't on, delay before accessing aux channel
1957 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001958 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001959 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1960 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001961 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001962 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001963
1964 return need_to_disable;
1965}
1966
Ville Syrjälä951468f2014-09-04 14:55:31 +03001967/*
1968 * Must be paired with intel_edp_panel_vdd_off() or
1969 * intel_edp_panel_off().
1970 * Nested calls to these functions are not allowed since
1971 * we drop the lock. Caller must use some higher level
1972 * locking to prevent nested calls from other threads.
1973 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001974void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001975{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001976 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001977
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001978 if (!is_edp(intel_dp))
1979 return;
1980
Ville Syrjälä773538e82014-09-04 14:54:56 +03001981 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001982 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001983 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001984
Rob Clarke2c719b2014-12-15 13:56:32 -05001985 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001986 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08001987}
1988
Daniel Vetter4be73782014-01-17 14:39:48 +01001989static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001990{
Paulo Zanoni30add222012-10-26 19:05:45 -02001991 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001992 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001993 struct intel_digital_port *intel_dig_port =
1994 dp_to_dig_port(intel_dp);
1995 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1996 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001997 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001998 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001999
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002000 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002001
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002002 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002003
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002004 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002005 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002006
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002007 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2008 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002009
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002010 pp = ironlake_get_pp_control(intel_dp);
2011 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002012
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002013 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2014 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002015
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002016 I915_WRITE(pp_ctrl_reg, pp);
2017 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002018
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002019 /* Make sure sequencer is idle before allowing subsequent activity */
2020 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2021 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002022
Imre Deak5a162e22016-08-10 14:07:30 +03002023 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002024 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002025
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002026 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002027 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002028}
2029
Daniel Vetter4be73782014-01-17 14:39:48 +01002030static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002031{
2032 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2033 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002034
Ville Syrjälä773538e82014-09-04 14:54:56 +03002035 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002036 if (!intel_dp->want_panel_vdd)
2037 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002038 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002039}
2040
Imre Deakaba86892014-07-30 15:57:31 +03002041static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2042{
2043 unsigned long delay;
2044
2045 /*
2046 * Queue the timer to fire a long time from now (relative to the power
2047 * down delay) to keep the panel power up across a sequence of
2048 * operations.
2049 */
2050 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2051 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2052}
2053
Ville Syrjälä951468f2014-09-04 14:55:31 +03002054/*
2055 * Must be paired with edp_panel_vdd_on().
2056 * Must hold pps_mutex around the whole on/off sequence.
2057 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2058 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002059static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002060{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002061 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002062
2063 lockdep_assert_held(&dev_priv->pps_mutex);
2064
Keith Packard97af61f572011-09-28 16:23:51 -07002065 if (!is_edp(intel_dp))
2066 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002067
Rob Clarke2c719b2014-12-15 13:56:32 -05002068 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002069 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002070
Keith Packardbd943152011-09-18 23:09:52 -07002071 intel_dp->want_panel_vdd = false;
2072
Imre Deakaba86892014-07-30 15:57:31 +03002073 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002074 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002075 else
2076 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002077}
2078
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002079static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002080{
Paulo Zanoni30add222012-10-26 19:05:45 -02002081 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002082 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002083 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002084 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002085
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002086 lockdep_assert_held(&dev_priv->pps_mutex);
2087
Keith Packard97af61f572011-09-28 16:23:51 -07002088 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002089 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002090
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002091 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2092 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002093
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002094 if (WARN(edp_have_panel_power(intel_dp),
2095 "eDP port %c panel power already on\n",
2096 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002097 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002098
Daniel Vetter4be73782014-01-17 14:39:48 +01002099 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002100
Jani Nikulabf13e812013-09-06 07:40:05 +03002101 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002102 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07002103 if (IS_GEN5(dev)) {
2104 /* ILK workaround: disable reset around power sequence */
2105 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002106 I915_WRITE(pp_ctrl_reg, pp);
2107 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002108 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002109
Imre Deak5a162e22016-08-10 14:07:30 +03002110 pp |= PANEL_POWER_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07002111 if (!IS_GEN5(dev))
2112 pp |= PANEL_POWER_RESET;
2113
Jesse Barnes453c5422013-03-28 09:55:41 -07002114 I915_WRITE(pp_ctrl_reg, pp);
2115 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002116
Daniel Vetter4be73782014-01-17 14:39:48 +01002117 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002118 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002119
Keith Packard05ce1a42011-09-29 16:33:01 -07002120 if (IS_GEN5(dev)) {
2121 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002122 I915_WRITE(pp_ctrl_reg, pp);
2123 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002124 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002125}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002126
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002127void intel_edp_panel_on(struct intel_dp *intel_dp)
2128{
2129 if (!is_edp(intel_dp))
2130 return;
2131
2132 pps_lock(intel_dp);
2133 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002134 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002135}
2136
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002137
2138static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002139{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002140 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2141 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002142 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002143 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002144 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002145 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002146 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002147
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002148 lockdep_assert_held(&dev_priv->pps_mutex);
2149
Keith Packard97af61f572011-09-28 16:23:51 -07002150 if (!is_edp(intel_dp))
2151 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002152
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002153 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2154 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002155
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002156 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2157 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002158
Jesse Barnes453c5422013-03-28 09:55:41 -07002159 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002160 /* We need to switch off panel power _and_ force vdd, for otherwise some
2161 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002162 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002163 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002164
Jani Nikulabf13e812013-09-06 07:40:05 +03002165 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002166
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002167 intel_dp->want_panel_vdd = false;
2168
Jesse Barnes453c5422013-03-28 09:55:41 -07002169 I915_WRITE(pp_ctrl_reg, pp);
2170 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002171
Abhay Kumard28d4732016-01-22 17:39:04 -08002172 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002173 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002174
2175 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002176 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002177 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002178}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002179
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002180void intel_edp_panel_off(struct intel_dp *intel_dp)
2181{
2182 if (!is_edp(intel_dp))
2183 return;
2184
2185 pps_lock(intel_dp);
2186 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002187 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002188}
2189
Jani Nikula1250d102014-08-12 17:11:39 +03002190/* Enable backlight in the panel power control. */
2191static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002192{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002193 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2194 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002195 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002196 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002197 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002198
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002199 /*
2200 * If we enable the backlight right away following a panel power
2201 * on, we may see slight flicker as the panel syncs with the eDP
2202 * link. So delay a bit to make sure the image is solid before
2203 * allowing it to appear.
2204 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002205 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002206
Ville Syrjälä773538e82014-09-04 14:54:56 +03002207 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002208
Jesse Barnes453c5422013-03-28 09:55:41 -07002209 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002210 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002211
Jani Nikulabf13e812013-09-06 07:40:05 +03002212 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002213
2214 I915_WRITE(pp_ctrl_reg, pp);
2215 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002216
Ville Syrjälä773538e82014-09-04 14:54:56 +03002217 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002218}
2219
Jani Nikula1250d102014-08-12 17:11:39 +03002220/* Enable backlight PWM and backlight PP control. */
2221void intel_edp_backlight_on(struct intel_dp *intel_dp)
2222{
2223 if (!is_edp(intel_dp))
2224 return;
2225
2226 DRM_DEBUG_KMS("\n");
2227
2228 intel_panel_enable_backlight(intel_dp->attached_connector);
2229 _intel_edp_backlight_on(intel_dp);
2230}
2231
2232/* Disable backlight in the panel power control. */
2233static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002234{
Paulo Zanoni30add222012-10-26 19:05:45 -02002235 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002236 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002237 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002238 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002239
Keith Packardf01eca22011-09-28 16:48:10 -07002240 if (!is_edp(intel_dp))
2241 return;
2242
Ville Syrjälä773538e82014-09-04 14:54:56 +03002243 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002244
Jesse Barnes453c5422013-03-28 09:55:41 -07002245 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002246 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002247
Jani Nikulabf13e812013-09-06 07:40:05 +03002248 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002249
2250 I915_WRITE(pp_ctrl_reg, pp);
2251 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002252
Ville Syrjälä773538e82014-09-04 14:54:56 +03002253 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002254
Paulo Zanonidce56b32013-12-19 14:29:40 -02002255 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002256 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002257}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002258
Jani Nikula1250d102014-08-12 17:11:39 +03002259/* Disable backlight PP control and backlight PWM. */
2260void intel_edp_backlight_off(struct intel_dp *intel_dp)
2261{
2262 if (!is_edp(intel_dp))
2263 return;
2264
2265 DRM_DEBUG_KMS("\n");
2266
2267 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002268 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002269}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002270
Jani Nikula73580fb72014-08-12 17:11:41 +03002271/*
2272 * Hook for controlling the panel power control backlight through the bl_power
2273 * sysfs attribute. Take care to handle multiple calls.
2274 */
2275static void intel_edp_backlight_power(struct intel_connector *connector,
2276 bool enable)
2277{
2278 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002279 bool is_enabled;
2280
Ville Syrjälä773538e82014-09-04 14:54:56 +03002281 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002282 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002283 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002284
2285 if (is_enabled == enable)
2286 return;
2287
Jani Nikula23ba9372014-08-27 14:08:43 +03002288 DRM_DEBUG_KMS("panel power control backlight %s\n",
2289 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002290
2291 if (enable)
2292 _intel_edp_backlight_on(intel_dp);
2293 else
2294 _intel_edp_backlight_off(intel_dp);
2295}
2296
Ville Syrjälä64e10772015-10-29 21:26:01 +02002297static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2298{
2299 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2300 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2301 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2302
2303 I915_STATE_WARN(cur_state != state,
2304 "DP port %c state assertion failure (expected %s, current %s)\n",
2305 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002306 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002307}
2308#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2309
2310static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2311{
2312 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2313
2314 I915_STATE_WARN(cur_state != state,
2315 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002316 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002317}
2318#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2319#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2320
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002321static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2322 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002323{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002324 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002325 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002326
Ville Syrjälä64e10772015-10-29 21:26:01 +02002327 assert_pipe_disabled(dev_priv, crtc->pipe);
2328 assert_dp_port_disabled(intel_dp);
2329 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002330
Ville Syrjäläabfce942015-10-29 21:26:03 +02002331 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002332 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002333
2334 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2335
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002336 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002337 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2338 else
2339 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2340
2341 I915_WRITE(DP_A, intel_dp->DP);
2342 POSTING_READ(DP_A);
2343 udelay(500);
2344
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002345 /*
2346 * [DevILK] Work around required when enabling DP PLL
2347 * while a pipe is enabled going to FDI:
2348 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2349 * 2. Program DP PLL enable
2350 */
2351 if (IS_GEN5(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +01002352 intel_wait_for_vblank_if_active(&dev_priv->drm, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002353
Daniel Vetter07679352012-09-06 22:15:42 +02002354 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002355
Daniel Vetter07679352012-09-06 22:15:42 +02002356 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002357 POSTING_READ(DP_A);
2358 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002359}
2360
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002361static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002362{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002363 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002364 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2365 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002366
Ville Syrjälä64e10772015-10-29 21:26:01 +02002367 assert_pipe_disabled(dev_priv, crtc->pipe);
2368 assert_dp_port_disabled(intel_dp);
2369 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002370
Ville Syrjäläabfce942015-10-29 21:26:03 +02002371 DRM_DEBUG_KMS("disabling eDP PLL\n");
2372
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002373 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002374
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002375 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002376 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002377 udelay(200);
2378}
2379
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002380/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002381void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002382{
2383 int ret, i;
2384
2385 /* Should have a valid DPCD by this point */
2386 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2387 return;
2388
2389 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002390 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2391 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002392 } else {
2393 /*
2394 * When turning on, we need to retry for 1ms to give the sink
2395 * time to wake up.
2396 */
2397 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002398 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2399 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002400 if (ret == 1)
2401 break;
2402 msleep(1);
2403 }
2404 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002405
2406 if (ret != 1)
2407 DRM_DEBUG_KMS("failed to %s sink power state\n",
2408 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002409}
2410
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002411static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2412 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002413{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002414 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002415 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002416 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002417 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002418 enum intel_display_power_domain power_domain;
2419 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002420 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002421
2422 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002423 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002424 return false;
2425
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002426 ret = false;
2427
Imre Deak6d129be2014-03-05 16:20:54 +02002428 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002429
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002430 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002431 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002432
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002433 if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002434 *pipe = PORT_TO_PIPE_CPT(tmp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002435 } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002436 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002437
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002438 for_each_pipe(dev_priv, p) {
2439 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2440 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2441 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002442 ret = true;
2443
2444 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002445 }
2446 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002447
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002448 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002449 i915_mmio_reg_offset(intel_dp->output_reg));
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002450 } else if (IS_CHERRYVIEW(dev)) {
2451 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2452 } else {
2453 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002454 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002455
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002456 ret = true;
2457
2458out:
2459 intel_display_power_put(dev_priv, power_domain);
2460
2461 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002462}
2463
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002464static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002465 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002466{
2467 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002468 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002469 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002470 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002471 enum port port = dp_to_dig_port(intel_dp)->port;
2472 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002473
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002474 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002475
2476 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002477
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002478 if (HAS_PCH_CPT(dev) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002479 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2480
2481 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002482 flags |= DRM_MODE_FLAG_PHSYNC;
2483 else
2484 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002485
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002486 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002487 flags |= DRM_MODE_FLAG_PVSYNC;
2488 else
2489 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002490 } else {
2491 if (tmp & DP_SYNC_HS_HIGH)
2492 flags |= DRM_MODE_FLAG_PHSYNC;
2493 else
2494 flags |= DRM_MODE_FLAG_NHSYNC;
2495
2496 if (tmp & DP_SYNC_VS_HIGH)
2497 flags |= DRM_MODE_FLAG_PVSYNC;
2498 else
2499 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002500 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002501
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002502 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002503
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002504 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08002505 !IS_CHERRYVIEW(dev) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002506 pipe_config->limited_color_range = true;
2507
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002508 pipe_config->lane_count =
2509 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2510
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002511 intel_dp_get_m_n(crtc, pipe_config);
2512
Ville Syrjälä18442d02013-09-13 16:00:08 +03002513 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002514 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002515 pipe_config->port_clock = 162000;
2516 else
2517 pipe_config->port_clock = 270000;
2518 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002519
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002520 pipe_config->base.adjusted_mode.crtc_clock =
2521 intel_dotclock_calculate(pipe_config->port_clock,
2522 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002523
Jani Nikula6aa23e62016-03-24 17:50:20 +02002524 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2525 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002526 /*
2527 * This is a big fat ugly hack.
2528 *
2529 * Some machines in UEFI boot mode provide us a VBT that has 18
2530 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2531 * unknown we fail to light up. Yet the same BIOS boots up with
2532 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2533 * max, not what it tells us to use.
2534 *
2535 * Note: This will still be broken if the eDP panel is not lit
2536 * up by the BIOS, and thus we can't get the mode at module
2537 * load.
2538 */
2539 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002540 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2541 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002542 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002543}
2544
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002545static void intel_disable_dp(struct intel_encoder *encoder,
2546 struct intel_crtc_state *old_crtc_state,
2547 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002548{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002549 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002550 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002551
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002552 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002553 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002554
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002555 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002556 intel_psr_disable(intel_dp);
2557
Daniel Vetter6cb49832012-05-20 17:14:50 +02002558 /* Make sure the panel is off before trying to change the mode. But also
2559 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002560 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002561 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002562 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002563 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002564
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002565 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002566 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002567 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002568}
2569
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002570static void ilk_post_disable_dp(struct intel_encoder *encoder,
2571 struct intel_crtc_state *old_crtc_state,
2572 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002573{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002574 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002575 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002576
Ville Syrjälä49277c32014-03-31 18:21:26 +03002577 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002578
2579 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002580 if (port == PORT_A)
2581 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002582}
2583
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002584static void vlv_post_disable_dp(struct intel_encoder *encoder,
2585 struct intel_crtc_state *old_crtc_state,
2586 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002587{
2588 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2589
2590 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002591}
2592
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002593static void chv_post_disable_dp(struct intel_encoder *encoder,
2594 struct intel_crtc_state *old_crtc_state,
2595 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002596{
2597 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002598 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002599 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002600
2601 intel_dp_link_down(intel_dp);
2602
Ville Syrjäläa5805162015-05-26 20:42:30 +03002603 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002604
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002605 /* Assert data lane reset */
2606 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002607
Ville Syrjäläa5805162015-05-26 20:42:30 +03002608 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002609}
2610
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002611static void
2612_intel_dp_set_link_train(struct intel_dp *intel_dp,
2613 uint32_t *DP,
2614 uint8_t dp_train_pat)
2615{
2616 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2617 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002618 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002619 enum port port = intel_dig_port->port;
2620
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002621 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2622 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2623 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2624
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002625 if (HAS_DDI(dev)) {
2626 uint32_t temp = I915_READ(DP_TP_CTL(port));
2627
2628 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2629 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2630 else
2631 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2632
2633 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2634 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2635 case DP_TRAINING_PATTERN_DISABLE:
2636 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2637
2638 break;
2639 case DP_TRAINING_PATTERN_1:
2640 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2641 break;
2642 case DP_TRAINING_PATTERN_2:
2643 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2644 break;
2645 case DP_TRAINING_PATTERN_3:
2646 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2647 break;
2648 }
2649 I915_WRITE(DP_TP_CTL(port), temp);
2650
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002651 } else if ((IS_GEN7(dev) && port == PORT_A) ||
2652 (HAS_PCH_CPT(dev) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002653 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2654
2655 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2656 case DP_TRAINING_PATTERN_DISABLE:
2657 *DP |= DP_LINK_TRAIN_OFF_CPT;
2658 break;
2659 case DP_TRAINING_PATTERN_1:
2660 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2661 break;
2662 case DP_TRAINING_PATTERN_2:
2663 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2664 break;
2665 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002666 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002667 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2668 break;
2669 }
2670
2671 } else {
2672 if (IS_CHERRYVIEW(dev))
2673 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2674 else
2675 *DP &= ~DP_LINK_TRAIN_MASK;
2676
2677 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2678 case DP_TRAINING_PATTERN_DISABLE:
2679 *DP |= DP_LINK_TRAIN_OFF;
2680 break;
2681 case DP_TRAINING_PATTERN_1:
2682 *DP |= DP_LINK_TRAIN_PAT_1;
2683 break;
2684 case DP_TRAINING_PATTERN_2:
2685 *DP |= DP_LINK_TRAIN_PAT_2;
2686 break;
2687 case DP_TRAINING_PATTERN_3:
2688 if (IS_CHERRYVIEW(dev)) {
2689 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2690 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002691 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002692 *DP |= DP_LINK_TRAIN_PAT_2;
2693 }
2694 break;
2695 }
2696 }
2697}
2698
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002699static void intel_dp_enable_port(struct intel_dp *intel_dp,
2700 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002701{
2702 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002703 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002704
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002705 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002706
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002707 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002708
2709 /*
2710 * Magic for VLV/CHV. We _must_ first set up the register
2711 * without actually enabling the port, and then do another
2712 * write to enable the port. Otherwise link training will
2713 * fail when the power sequencer is freshly used for this port.
2714 */
2715 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002716 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002717 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002718
2719 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2720 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002721}
2722
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002723static void intel_enable_dp(struct intel_encoder *encoder,
2724 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002725{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002726 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2727 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002728 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002729 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002730 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002731 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002732
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002733 if (WARN_ON(dp_reg & DP_PORT_EN))
2734 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002735
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002736 pps_lock(intel_dp);
2737
Wayne Boyer666a4532015-12-09 12:29:35 -08002738 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002739 vlv_init_panel_power_sequencer(intel_dp);
2740
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002741 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002742
2743 edp_panel_vdd_on(intel_dp);
2744 edp_panel_on(intel_dp);
2745 edp_panel_vdd_off(intel_dp, true);
2746
2747 pps_unlock(intel_dp);
2748
Wayne Boyer666a4532015-12-09 12:29:35 -08002749 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002750 unsigned int lane_mask = 0x0;
2751
2752 if (IS_CHERRYVIEW(dev))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002753 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002754
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002755 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2756 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002757 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002758
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002759 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2760 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002761 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002762
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002763 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002764 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002765 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002766 intel_audio_codec_enable(encoder);
2767 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002768}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002769
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002770static void g4x_enable_dp(struct intel_encoder *encoder,
2771 struct intel_crtc_state *pipe_config,
2772 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002773{
Jani Nikula828f5c62013-09-05 16:44:45 +03002774 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2775
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002776 intel_enable_dp(encoder, pipe_config);
Daniel Vetter4be73782014-01-17 14:39:48 +01002777 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002778}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002779
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002780static void vlv_enable_dp(struct intel_encoder *encoder,
2781 struct intel_crtc_state *pipe_config,
2782 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002783{
Jani Nikula828f5c62013-09-05 16:44:45 +03002784 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2785
Daniel Vetter4be73782014-01-17 14:39:48 +01002786 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002787 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002788}
2789
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002790static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2791 struct intel_crtc_state *pipe_config,
2792 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002793{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002794 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002795 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002796
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002797 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002798
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002799 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002800 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002801 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002802}
2803
Ville Syrjälä83b84592014-10-16 21:29:51 +03002804static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2805{
2806 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002807 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002808 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002809 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002810
2811 edp_panel_vdd_off_sync(intel_dp);
2812
2813 /*
2814 * VLV seems to get confused when multiple power seqeuencers
2815 * have the same port selected (even if only one has power/vdd
2816 * enabled). The failure manifests as vlv_wait_port_ready() failing
2817 * CHV on the other hand doesn't seem to mind having the same port
2818 * selected in multiple power seqeuencers, but let's clear the
2819 * port select always when logically disconnecting a power sequencer
2820 * from a port.
2821 */
2822 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2823 pipe_name(pipe), port_name(intel_dig_port->port));
2824 I915_WRITE(pp_on_reg, 0);
2825 POSTING_READ(pp_on_reg);
2826
2827 intel_dp->pps_pipe = INVALID_PIPE;
2828}
2829
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002830static void vlv_steal_power_sequencer(struct drm_device *dev,
2831 enum pipe pipe)
2832{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002833 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002834 struct intel_encoder *encoder;
2835
2836 lockdep_assert_held(&dev_priv->pps_mutex);
2837
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002838 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2839 return;
2840
Jani Nikula19c80542015-12-16 12:48:16 +02002841 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002842 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002843 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002844
2845 if (encoder->type != INTEL_OUTPUT_EDP)
2846 continue;
2847
2848 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002849 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002850
2851 if (intel_dp->pps_pipe != pipe)
2852 continue;
2853
2854 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002855 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002856
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002857 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002858 "stealing pipe %c power sequencer from active eDP port %c\n",
2859 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002860
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002861 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002862 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002863 }
2864}
2865
2866static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2867{
2868 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2869 struct intel_encoder *encoder = &intel_dig_port->base;
2870 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002871 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002872 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002873
2874 lockdep_assert_held(&dev_priv->pps_mutex);
2875
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002876 if (!is_edp(intel_dp))
2877 return;
2878
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002879 if (intel_dp->pps_pipe == crtc->pipe)
2880 return;
2881
2882 /*
2883 * If another power sequencer was being used on this
2884 * port previously make sure to turn off vdd there while
2885 * we still have control of it.
2886 */
2887 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002888 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002889
2890 /*
2891 * We may be stealing the power
2892 * sequencer from another port.
2893 */
2894 vlv_steal_power_sequencer(dev, crtc->pipe);
2895
2896 /* now it's all ours */
2897 intel_dp->pps_pipe = crtc->pipe;
2898
2899 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2900 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2901
2902 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002903 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2904 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002905}
2906
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002907static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2908 struct intel_crtc_state *pipe_config,
2909 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002910{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002911 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002912
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002913 intel_enable_dp(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002914}
2915
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002916static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2917 struct intel_crtc_state *pipe_config,
2918 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002919{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002920 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002921
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002922 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002923}
2924
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002925static void chv_pre_enable_dp(struct intel_encoder *encoder,
2926 struct intel_crtc_state *pipe_config,
2927 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002928{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002929 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002930
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002931 intel_enable_dp(encoder, pipe_config);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002932
2933 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002934 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002935}
2936
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002937static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2938 struct intel_crtc_state *pipe_config,
2939 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002940{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002941 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002942
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002943 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002944}
2945
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002946static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2947 struct intel_crtc_state *pipe_config,
2948 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002949{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002950 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002951}
2952
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002953/*
2954 * Fetch AUX CH registers 0x202 - 0x207 which contain
2955 * link status information
2956 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002957bool
Keith Packard93f62da2011-11-01 19:45:03 -07002958intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002959{
Lyude9f085eb2016-04-13 10:58:33 -04002960 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2961 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002962}
2963
Paulo Zanoni11002442014-06-13 18:45:41 -03002964/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002965uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002966intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002967{
Paulo Zanoni30add222012-10-26 19:05:45 -02002968 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002969 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002970 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002971
Vandana Kannan93147262014-11-18 15:45:29 +05302972 if (IS_BROXTON(dev))
2973 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2974 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002975 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302976 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002977 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Wayne Boyer666a4532015-12-09 12:29:35 -08002978 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Sonika Jindalbd600182014-08-08 16:23:41 +05302979 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002980 else if (IS_GEN7(dev) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302981 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002982 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302983 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08002984 else
Sonika Jindalbd600182014-08-08 16:23:41 +05302985 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08002986}
2987
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002988uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002989intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
2990{
Paulo Zanoni30add222012-10-26 19:05:45 -02002991 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002992 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002993
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002994 if (INTEL_INFO(dev)->gen >= 9) {
2995 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2996 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
2997 return DP_TRAIN_PRE_EMPH_LEVEL_3;
2998 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2999 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3000 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3001 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303002 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3003 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003004 default:
3005 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3006 }
3007 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003008 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303009 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3010 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3011 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3012 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3013 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3014 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3015 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003016 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303017 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003018 }
Wayne Boyer666a4532015-12-09 12:29:35 -08003019 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003020 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303021 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3022 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3023 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3024 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3025 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3026 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3027 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003028 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303029 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003030 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03003031 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003032 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303033 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3034 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3035 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3036 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3037 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003038 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303039 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003040 }
3041 } else {
3042 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303043 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3044 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3045 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3046 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3047 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3048 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3049 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003050 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303051 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003052 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003053 }
3054}
3055
Daniel Vetter5829975c2015-04-16 11:36:52 +02003056static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003057{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003058 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003059 unsigned long demph_reg_value, preemph_reg_value,
3060 uniqtranscale_reg_value;
3061 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003062
3063 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303064 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003065 preemph_reg_value = 0x0004000;
3066 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303067 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003068 demph_reg_value = 0x2B405555;
3069 uniqtranscale_reg_value = 0x552AB83A;
3070 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303071 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003072 demph_reg_value = 0x2B404040;
3073 uniqtranscale_reg_value = 0x5548B83A;
3074 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303075 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003076 demph_reg_value = 0x2B245555;
3077 uniqtranscale_reg_value = 0x5560B83A;
3078 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303079 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003080 demph_reg_value = 0x2B405555;
3081 uniqtranscale_reg_value = 0x5598DA3A;
3082 break;
3083 default:
3084 return 0;
3085 }
3086 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303087 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003088 preemph_reg_value = 0x0002000;
3089 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303090 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003091 demph_reg_value = 0x2B404040;
3092 uniqtranscale_reg_value = 0x5552B83A;
3093 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303094 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003095 demph_reg_value = 0x2B404848;
3096 uniqtranscale_reg_value = 0x5580B83A;
3097 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303098 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003099 demph_reg_value = 0x2B404040;
3100 uniqtranscale_reg_value = 0x55ADDA3A;
3101 break;
3102 default:
3103 return 0;
3104 }
3105 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303106 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003107 preemph_reg_value = 0x0000000;
3108 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303109 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003110 demph_reg_value = 0x2B305555;
3111 uniqtranscale_reg_value = 0x5570B83A;
3112 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303113 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003114 demph_reg_value = 0x2B2B4040;
3115 uniqtranscale_reg_value = 0x55ADDA3A;
3116 break;
3117 default:
3118 return 0;
3119 }
3120 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303121 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003122 preemph_reg_value = 0x0006000;
3123 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303124 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003125 demph_reg_value = 0x1B405555;
3126 uniqtranscale_reg_value = 0x55ADDA3A;
3127 break;
3128 default:
3129 return 0;
3130 }
3131 break;
3132 default:
3133 return 0;
3134 }
3135
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003136 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3137 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003138
3139 return 0;
3140}
3141
Daniel Vetter5829975c2015-04-16 11:36:52 +02003142static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003143{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003144 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3145 u32 deemph_reg_value, margin_reg_value;
3146 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003147 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003148
3149 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303150 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003151 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303152 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003153 deemph_reg_value = 128;
3154 margin_reg_value = 52;
3155 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003157 deemph_reg_value = 128;
3158 margin_reg_value = 77;
3159 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003161 deemph_reg_value = 128;
3162 margin_reg_value = 102;
3163 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303164 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003165 deemph_reg_value = 128;
3166 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003167 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003168 break;
3169 default:
3170 return 0;
3171 }
3172 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303173 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003174 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003176 deemph_reg_value = 85;
3177 margin_reg_value = 78;
3178 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303179 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003180 deemph_reg_value = 85;
3181 margin_reg_value = 116;
3182 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303183 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003184 deemph_reg_value = 85;
3185 margin_reg_value = 154;
3186 break;
3187 default:
3188 return 0;
3189 }
3190 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003192 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003194 deemph_reg_value = 64;
3195 margin_reg_value = 104;
3196 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003198 deemph_reg_value = 64;
3199 margin_reg_value = 154;
3200 break;
3201 default:
3202 return 0;
3203 }
3204 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003206 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303207 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003208 deemph_reg_value = 43;
3209 margin_reg_value = 154;
3210 break;
3211 default:
3212 return 0;
3213 }
3214 break;
3215 default:
3216 return 0;
3217 }
3218
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003219 chv_set_phy_signal_level(encoder, deemph_reg_value,
3220 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003221
3222 return 0;
3223}
3224
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003225static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003226gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003227{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003228 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003229
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003230 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303231 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003232 default:
3233 signal_levels |= DP_VOLTAGE_0_4;
3234 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003236 signal_levels |= DP_VOLTAGE_0_6;
3237 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303238 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003239 signal_levels |= DP_VOLTAGE_0_8;
3240 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303241 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003242 signal_levels |= DP_VOLTAGE_1_2;
3243 break;
3244 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003245 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303246 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003247 default:
3248 signal_levels |= DP_PRE_EMPHASIS_0;
3249 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003251 signal_levels |= DP_PRE_EMPHASIS_3_5;
3252 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003254 signal_levels |= DP_PRE_EMPHASIS_6;
3255 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303256 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003257 signal_levels |= DP_PRE_EMPHASIS_9_5;
3258 break;
3259 }
3260 return signal_levels;
3261}
3262
Zhenyu Wange3421a12010-04-08 09:43:27 +08003263/* Gen6's DP voltage swing and pre-emphasis control */
3264static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003265gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003266{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003267 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3268 DP_TRAIN_PRE_EMPHASIS_MASK);
3269 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303270 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003272 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303273 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003274 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3276 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003277 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303278 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3279 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003280 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3282 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003283 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003284 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003285 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3286 "0x%x\n", signal_levels);
3287 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003288 }
3289}
3290
Keith Packard1a2eb462011-11-16 16:26:07 -08003291/* Gen7's DP voltage swing and pre-emphasis control */
3292static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003293gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003294{
3295 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3296 DP_TRAIN_PRE_EMPHASIS_MASK);
3297 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303298 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003299 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303300 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003301 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303302 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003303 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3304
Sonika Jindalbd600182014-08-08 16:23:41 +05303305 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003306 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003308 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3309
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003311 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003313 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3314
3315 default:
3316 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3317 "0x%x\n", signal_levels);
3318 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3319 }
3320}
3321
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003322void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003323intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003324{
3325 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003326 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003327 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003328 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003329 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003330 uint8_t train_set = intel_dp->train_set[0];
3331
David Weinehallf8896f52015-06-25 11:11:03 +03003332 if (HAS_DDI(dev)) {
3333 signal_levels = ddi_signal_levels(intel_dp);
3334
3335 if (IS_BROXTON(dev))
3336 signal_levels = 0;
3337 else
3338 mask = DDI_BUF_EMP_MASK;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003339 } else if (IS_CHERRYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003340 signal_levels = chv_signal_levels(intel_dp);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003341 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003342 signal_levels = vlv_signal_levels(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003343 } else if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003344 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003345 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003346 } else if (IS_GEN6(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003347 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003348 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3349 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003350 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003351 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3352 }
3353
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303354 if (mask)
3355 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3356
3357 DRM_DEBUG_KMS("Using vswing level %d\n",
3358 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3359 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3360 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3361 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003362
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003363 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003364
3365 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3366 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003367}
3368
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003369void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003370intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3371 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003372{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003373 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003374 struct drm_i915_private *dev_priv =
3375 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003376
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003377 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003378
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003379 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003380 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003381}
3382
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003383void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003384{
3385 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3386 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003387 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003388 enum port port = intel_dig_port->port;
3389 uint32_t val;
3390
3391 if (!HAS_DDI(dev))
3392 return;
3393
3394 val = I915_READ(DP_TP_CTL(port));
3395 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3396 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3397 I915_WRITE(DP_TP_CTL(port), val);
3398
3399 /*
3400 * On PORT_A we can have only eDP in SST mode. There the only reason
3401 * we need to set idle transmission mode is to work around a HW issue
3402 * where we enable the pipe while not in idle link-training mode.
3403 * In this case there is requirement to wait for a minimum number of
3404 * idle patterns to be sent.
3405 */
3406 if (port == PORT_A)
3407 return;
3408
Chris Wilsona7670172016-06-30 15:33:10 +01003409 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3410 DP_TP_STATUS_IDLE_DONE,
3411 DP_TP_STATUS_IDLE_DONE,
3412 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003413 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3414}
3415
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003416static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003417intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003418{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003419 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003420 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003421 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003422 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003423 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003424 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003425
Daniel Vetterbc76e3202014-05-20 22:46:50 +02003426 if (WARN_ON(HAS_DDI(dev)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003427 return;
3428
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003429 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003430 return;
3431
Zhao Yakui28c97732009-10-09 11:39:41 +08003432 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003433
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03003434 if ((IS_GEN7(dev) && port == PORT_A) ||
3435 (HAS_PCH_CPT(dev) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003436 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003437 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003438 } else {
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003439 if (IS_CHERRYVIEW(dev))
3440 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3441 else
3442 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003443 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003444 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003445 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003446 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003447
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003448 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3449 I915_WRITE(intel_dp->output_reg, DP);
3450 POSTING_READ(intel_dp->output_reg);
3451
3452 /*
3453 * HW workaround for IBX, we need to move the port
3454 * to transcoder A after disabling it to allow the
3455 * matching HDMI port to be enabled on transcoder A.
3456 */
3457 if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003458 /*
3459 * We get CPU/PCH FIFO underruns on the other pipe when
3460 * doing the workaround. Sweep them under the rug.
3461 */
3462 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3463 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3464
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003465 /* always enable with pattern 1 (as per spec) */
3466 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3467 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3468 I915_WRITE(intel_dp->output_reg, DP);
3469 POSTING_READ(intel_dp->output_reg);
3470
3471 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003472 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003473 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003474
Chris Wilson91c8a322016-07-05 10:40:23 +01003475 intel_wait_for_vblank_if_active(&dev_priv->drm, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003476 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3477 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003478 }
3479
Keith Packardf01eca22011-09-28 16:48:10 -07003480 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003481
3482 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003483}
3484
Keith Packard26d61aa2011-07-25 20:01:09 -07003485static bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003486intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003487{
Lyude9f085eb2016-04-13 10:58:33 -04003488 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3489 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003490 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003491
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003492 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003493
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003494 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3495}
3496
3497static bool
3498intel_edp_init_dpcd(struct intel_dp *intel_dp)
3499{
3500 struct drm_i915_private *dev_priv =
3501 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3502
3503 /* this function is meant to be called only once */
3504 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3505
3506 if (!intel_dp_read_dpcd(intel_dp))
3507 return false;
3508
3509 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3510 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3511 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3512
3513 /* Check if the panel supports PSR */
3514 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3515 intel_dp->psr_dpcd,
3516 sizeof(intel_dp->psr_dpcd));
3517 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3518 dev_priv->psr.sink_support = true;
3519 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3520 }
3521
3522 if (INTEL_GEN(dev_priv) >= 9 &&
3523 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3524 uint8_t frame_sync_cap;
3525
3526 dev_priv->psr.sink_support = true;
3527 drm_dp_dpcd_read(&intel_dp->aux,
3528 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3529 &frame_sync_cap, 1);
3530 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3531 /* PSR2 needs frame sync as well */
3532 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3533 DRM_DEBUG_KMS("PSR2 %s on sink",
3534 dev_priv->psr.psr2_support ? "supported" : "not supported");
3535 }
3536
3537 /* Read the eDP Display control capabilities registers */
3538 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3539 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
3540 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd) ==
3541 sizeof(intel_dp->edp_dpcd)))
3542 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3543 intel_dp->edp_dpcd);
3544
3545 /* Intermediate frequency support */
3546 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3547 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3548 int i;
3549
3550 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3551 sink_rates, sizeof(sink_rates));
3552
3553 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3554 int val = le16_to_cpu(sink_rates[i]);
3555
3556 if (val == 0)
3557 break;
3558
3559 /* Value read is in kHz while drm clock is saved in deca-kHz */
3560 intel_dp->sink_rates[i] = (val * 200) / 10;
3561 }
3562 intel_dp->num_sink_rates = i;
3563 }
3564
3565 return true;
3566}
3567
3568
3569static bool
3570intel_dp_get_dpcd(struct intel_dp *intel_dp)
3571{
3572 if (!intel_dp_read_dpcd(intel_dp))
3573 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003574
Lyude9f085eb2016-04-13 10:58:33 -04003575 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3576 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303577 return false;
3578
3579 /*
3580 * Sink count can change between short pulse hpd hence
3581 * a member variable in intel_dp will track any changes
3582 * between short pulse interrupts.
3583 */
3584 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3585
3586 /*
3587 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3588 * a dongle is present but no display. Unless we require to know
3589 * if a dongle is present or not, we don't need to update
3590 * downstream port information. So, an early return here saves
3591 * time from performing other operations which are not required.
3592 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303593 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303594 return false;
3595
Adam Jacksonedb39242012-09-18 10:58:49 -04003596 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3597 DP_DWN_STRM_PORT_PRESENT))
3598 return true; /* native DP sink */
3599
3600 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3601 return true; /* no per-port downstream info */
3602
Lyude9f085eb2016-04-13 10:58:33 -04003603 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3604 intel_dp->downstream_ports,
3605 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003606 return false; /* downstream port status fetch failed */
3607
3608 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003609}
3610
Adam Jackson0d198322012-05-14 16:05:47 -04003611static void
3612intel_dp_probe_oui(struct intel_dp *intel_dp)
3613{
3614 u8 buf[3];
3615
3616 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3617 return;
3618
Lyude9f085eb2016-04-13 10:58:33 -04003619 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003620 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3621 buf[0], buf[1], buf[2]);
3622
Lyude9f085eb2016-04-13 10:58:33 -04003623 if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003624 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3625 buf[0], buf[1], buf[2]);
3626}
3627
Dave Airlie0e32b392014-05-02 14:02:48 +10003628static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003629intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003630{
3631 u8 buf[1];
3632
Nathan Schulte7cc96132016-03-15 10:14:05 -05003633 if (!i915.enable_dp_mst)
3634 return false;
3635
Dave Airlie0e32b392014-05-02 14:02:48 +10003636 if (!intel_dp->can_mst)
3637 return false;
3638
3639 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3640 return false;
3641
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003642 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3643 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003644
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003645 return buf[0] & DP_MST_CAP;
3646}
3647
3648static void
3649intel_dp_configure_mst(struct intel_dp *intel_dp)
3650{
3651 if (!i915.enable_dp_mst)
3652 return;
3653
3654 if (!intel_dp->can_mst)
3655 return;
3656
3657 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3658
3659 if (intel_dp->is_mst)
3660 DRM_DEBUG_KMS("Sink is MST capable\n");
3661 else
3662 DRM_DEBUG_KMS("Sink is not MST capable\n");
3663
3664 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3665 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003666}
3667
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003668static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003669{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003670 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003671 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003672 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003673 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003674 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003675 int count = 0;
3676 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003677
3678 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003679 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003680 ret = -EIO;
3681 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003682 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003683
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003684 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003685 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003686 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003687 ret = -EIO;
3688 goto out;
3689 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003690
Rodrigo Vivic6297842015-11-05 10:50:20 -08003691 do {
3692 intel_wait_for_vblank(dev, intel_crtc->pipe);
3693
3694 if (drm_dp_dpcd_readb(&intel_dp->aux,
3695 DP_TEST_SINK_MISC, &buf) < 0) {
3696 ret = -EIO;
3697 goto out;
3698 }
3699 count = buf & DP_TEST_COUNT_MASK;
3700 } while (--attempts && count);
3701
3702 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003703 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003704 ret = -ETIMEDOUT;
3705 }
3706
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003707 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003708 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003709 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003710}
3711
3712static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3713{
3714 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003715 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003716 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3717 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003718 int ret;
3719
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003720 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3721 return -EIO;
3722
3723 if (!(buf & DP_TEST_CRC_SUPPORTED))
3724 return -ENOTTY;
3725
3726 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3727 return -EIO;
3728
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003729 if (buf & DP_TEST_SINK_START) {
3730 ret = intel_dp_sink_crc_stop(intel_dp);
3731 if (ret)
3732 return ret;
3733 }
3734
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003735 hsw_disable_ips(intel_crtc);
3736
3737 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3738 buf | DP_TEST_SINK_START) < 0) {
3739 hsw_enable_ips(intel_crtc);
3740 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003741 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003742
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003743 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003744 return 0;
3745}
3746
3747int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3748{
3749 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3750 struct drm_device *dev = dig_port->base.base.dev;
3751 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3752 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003753 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003754 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003755
3756 ret = intel_dp_sink_crc_start(intel_dp);
3757 if (ret)
3758 return ret;
3759
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003760 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003761 intel_wait_for_vblank(dev, intel_crtc->pipe);
3762
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003763 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003764 DP_TEST_SINK_MISC, &buf) < 0) {
3765 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003766 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003767 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003768 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003769
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003770 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003771
3772 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003773 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3774 ret = -ETIMEDOUT;
3775 goto stop;
3776 }
3777
3778 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3779 ret = -EIO;
3780 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003781 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003782
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003783stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003784 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003785 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003786}
3787
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003788static bool
3789intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3790{
Lyude9f085eb2016-04-13 10:58:33 -04003791 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003792 DP_DEVICE_SERVICE_IRQ_VECTOR,
3793 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003794}
3795
Dave Airlie0e32b392014-05-02 14:02:48 +10003796static bool
3797intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3798{
3799 int ret;
3800
Lyude9f085eb2016-04-13 10:58:33 -04003801 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003802 DP_SINK_COUNT_ESI,
3803 sink_irq_vector, 14);
3804 if (ret != 14)
3805 return false;
3806
3807 return true;
3808}
3809
Todd Previtec5d5ab72015-04-15 08:38:38 -07003810static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003811{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003812 uint8_t test_result = DP_TEST_ACK;
3813 return test_result;
3814}
3815
3816static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3817{
3818 uint8_t test_result = DP_TEST_NAK;
3819 return test_result;
3820}
3821
3822static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3823{
3824 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003825 struct intel_connector *intel_connector = intel_dp->attached_connector;
3826 struct drm_connector *connector = &intel_connector->base;
3827
3828 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003829 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003830 intel_dp->aux.i2c_defer_count > 6) {
3831 /* Check EDID read for NACKs, DEFERs and corruption
3832 * (DP CTS 1.2 Core r1.1)
3833 * 4.2.2.4 : Failed EDID read, I2C_NAK
3834 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3835 * 4.2.2.6 : EDID corruption detected
3836 * Use failsafe mode for all cases
3837 */
3838 if (intel_dp->aux.i2c_nack_count > 0 ||
3839 intel_dp->aux.i2c_defer_count > 0)
3840 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3841 intel_dp->aux.i2c_nack_count,
3842 intel_dp->aux.i2c_defer_count);
3843 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3844 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303845 struct edid *block = intel_connector->detect_edid;
3846
3847 /* We have to write the checksum
3848 * of the last block read
3849 */
3850 block += intel_connector->detect_edid->extensions;
3851
Todd Previte559be302015-05-04 07:48:20 -07003852 if (!drm_dp_dpcd_write(&intel_dp->aux,
3853 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303854 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003855 1))
Todd Previte559be302015-05-04 07:48:20 -07003856 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3857
3858 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3859 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3860 }
3861
3862 /* Set test active flag here so userspace doesn't interrupt things */
3863 intel_dp->compliance_test_active = 1;
3864
Todd Previtec5d5ab72015-04-15 08:38:38 -07003865 return test_result;
3866}
3867
3868static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3869{
3870 uint8_t test_result = DP_TEST_NAK;
3871 return test_result;
3872}
3873
3874static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3875{
3876 uint8_t response = DP_TEST_NAK;
3877 uint8_t rxdata = 0;
3878 int status = 0;
3879
Todd Previtec5d5ab72015-04-15 08:38:38 -07003880 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3881 if (status <= 0) {
3882 DRM_DEBUG_KMS("Could not read test request from sink\n");
3883 goto update_status;
3884 }
3885
3886 switch (rxdata) {
3887 case DP_TEST_LINK_TRAINING:
3888 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3889 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3890 response = intel_dp_autotest_link_training(intel_dp);
3891 break;
3892 case DP_TEST_LINK_VIDEO_PATTERN:
3893 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3894 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3895 response = intel_dp_autotest_video_pattern(intel_dp);
3896 break;
3897 case DP_TEST_LINK_EDID_READ:
3898 DRM_DEBUG_KMS("EDID test requested\n");
3899 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3900 response = intel_dp_autotest_edid(intel_dp);
3901 break;
3902 case DP_TEST_LINK_PHY_TEST_PATTERN:
3903 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3904 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3905 response = intel_dp_autotest_phy_pattern(intel_dp);
3906 break;
3907 default:
3908 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3909 break;
3910 }
3911
3912update_status:
3913 status = drm_dp_dpcd_write(&intel_dp->aux,
3914 DP_TEST_RESPONSE,
3915 &response, 1);
3916 if (status <= 0)
3917 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003918}
3919
Dave Airlie0e32b392014-05-02 14:02:48 +10003920static int
3921intel_dp_check_mst_status(struct intel_dp *intel_dp)
3922{
3923 bool bret;
3924
3925 if (intel_dp->is_mst) {
3926 u8 esi[16] = { 0 };
3927 int ret = 0;
3928 int retry;
3929 bool handled;
3930 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3931go_again:
3932 if (bret == true) {
3933
3934 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003935 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003936 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003937 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3938 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003939 intel_dp_stop_link_train(intel_dp);
3940 }
3941
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003942 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003943 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3944
3945 if (handled) {
3946 for (retry = 0; retry < 3; retry++) {
3947 int wret;
3948 wret = drm_dp_dpcd_write(&intel_dp->aux,
3949 DP_SINK_COUNT_ESI+1,
3950 &esi[1], 3);
3951 if (wret == 3) {
3952 break;
3953 }
3954 }
3955
3956 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3957 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003958 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003959 goto go_again;
3960 }
3961 } else
3962 ret = 0;
3963
3964 return ret;
3965 } else {
3966 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3967 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3968 intel_dp->is_mst = false;
3969 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3970 /* send a hotplug event */
3971 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3972 }
3973 }
3974 return -EINVAL;
3975}
3976
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303977static void
3978intel_dp_check_link_status(struct intel_dp *intel_dp)
3979{
3980 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
3981 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3982 u8 link_status[DP_LINK_STATUS_SIZE];
3983
3984 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
3985
3986 if (!intel_dp_get_link_status(intel_dp, link_status)) {
3987 DRM_ERROR("Failed to get link status\n");
3988 return;
3989 }
3990
3991 if (!intel_encoder->base.crtc)
3992 return;
3993
3994 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
3995 return;
3996
3997 /* if link training is requested we should perform it always */
3998 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
3999 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4000 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4001 intel_encoder->base.name);
4002 intel_dp_start_link_train(intel_dp);
4003 intel_dp_stop_link_train(intel_dp);
4004 }
4005}
4006
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004007/*
4008 * According to DP spec
4009 * 5.1.2:
4010 * 1. Read DPCD
4011 * 2. Configure link according to Receiver Capabilities
4012 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4013 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304014 *
4015 * intel_dp_short_pulse - handles short pulse interrupts
4016 * when full detection is not required.
4017 * Returns %true if short pulse is handled and full detection
4018 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004019 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304020static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304021intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004022{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004023 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004024 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304025 u8 old_sink_count = intel_dp->sink_count;
4026 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004027
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304028 /*
4029 * Clearing compliance test variables to allow capturing
4030 * of values for next automated test request.
4031 */
4032 intel_dp->compliance_test_active = 0;
4033 intel_dp->compliance_test_type = 0;
4034 intel_dp->compliance_test_data = 0;
4035
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304036 /*
4037 * Now read the DPCD to see if it's actually running
4038 * If the current value of sink count doesn't match with
4039 * the value that was stored earlier or dpcd read failed
4040 * we need to do full detection
4041 */
4042 ret = intel_dp_get_dpcd(intel_dp);
4043
4044 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4045 /* No need to proceed if we are going to do full detect */
4046 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004047 }
4048
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004049 /* Try to read the source of the interrupt */
4050 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004051 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4052 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004053 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004054 drm_dp_dpcd_writeb(&intel_dp->aux,
4055 DP_DEVICE_SERVICE_IRQ_VECTOR,
4056 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004057
4058 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004059 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004060 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4061 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4062 }
4063
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304064 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4065 intel_dp_check_link_status(intel_dp);
4066 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304067
4068 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004069}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004070
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004071/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004072static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004073intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004074{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004075 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004076 uint8_t type;
4077
4078 if (!intel_dp_get_dpcd(intel_dp))
4079 return connector_status_disconnected;
4080
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304081 if (is_edp(intel_dp))
4082 return connector_status_connected;
4083
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004084 /* if there's no downstream port, we're done */
4085 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07004086 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004087
4088 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004089 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4090 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004091
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304092 return intel_dp->sink_count ?
4093 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004094 }
4095
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004096 if (intel_dp_can_mst(intel_dp))
4097 return connector_status_connected;
4098
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004099 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004100 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004101 return connector_status_connected;
4102
4103 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004104 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4105 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4106 if (type == DP_DS_PORT_TYPE_VGA ||
4107 type == DP_DS_PORT_TYPE_NON_EDID)
4108 return connector_status_unknown;
4109 } else {
4110 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4111 DP_DWN_STRM_PORT_TYPE_MASK;
4112 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4113 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4114 return connector_status_unknown;
4115 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004116
4117 /* Anything else is out of spec, warn and ignore */
4118 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004119 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004120}
4121
4122static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004123edp_detect(struct intel_dp *intel_dp)
4124{
4125 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4126 enum drm_connector_status status;
4127
4128 status = intel_panel_detect(dev);
4129 if (status == connector_status_unknown)
4130 status = connector_status_connected;
4131
4132 return status;
4133}
4134
Jani Nikulab93433c2015-08-20 10:47:36 +03004135static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4136 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004137{
Jani Nikulab93433c2015-08-20 10:47:36 +03004138 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004139
Jani Nikula0df53b72015-08-20 10:47:40 +03004140 switch (port->port) {
4141 case PORT_A:
4142 return true;
4143 case PORT_B:
4144 bit = SDE_PORTB_HOTPLUG;
4145 break;
4146 case PORT_C:
4147 bit = SDE_PORTC_HOTPLUG;
4148 break;
4149 case PORT_D:
4150 bit = SDE_PORTD_HOTPLUG;
4151 break;
4152 default:
4153 MISSING_CASE(port->port);
4154 return false;
4155 }
4156
4157 return I915_READ(SDEISR) & bit;
4158}
4159
4160static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4161 struct intel_digital_port *port)
4162{
4163 u32 bit;
4164
4165 switch (port->port) {
4166 case PORT_A:
4167 return true;
4168 case PORT_B:
4169 bit = SDE_PORTB_HOTPLUG_CPT;
4170 break;
4171 case PORT_C:
4172 bit = SDE_PORTC_HOTPLUG_CPT;
4173 break;
4174 case PORT_D:
4175 bit = SDE_PORTD_HOTPLUG_CPT;
4176 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004177 case PORT_E:
4178 bit = SDE_PORTE_HOTPLUG_SPT;
4179 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004180 default:
4181 MISSING_CASE(port->port);
4182 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004183 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004184
Jani Nikulab93433c2015-08-20 10:47:36 +03004185 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004186}
4187
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004188static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004189 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004190{
Jani Nikula9642c812015-08-20 10:47:41 +03004191 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004192
Jani Nikula9642c812015-08-20 10:47:41 +03004193 switch (port->port) {
4194 case PORT_B:
4195 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4196 break;
4197 case PORT_C:
4198 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4199 break;
4200 case PORT_D:
4201 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4202 break;
4203 default:
4204 MISSING_CASE(port->port);
4205 return false;
4206 }
4207
4208 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4209}
4210
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004211static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4212 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004213{
4214 u32 bit;
4215
4216 switch (port->port) {
4217 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004218 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004219 break;
4220 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004221 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004222 break;
4223 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004224 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004225 break;
4226 default:
4227 MISSING_CASE(port->port);
4228 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004229 }
4230
Jani Nikula1d245982015-08-20 10:47:37 +03004231 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004232}
4233
Jani Nikulae464bfd2015-08-20 10:47:42 +03004234static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304235 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004236{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304237 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4238 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004239 u32 bit;
4240
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304241 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4242 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004243 case PORT_A:
4244 bit = BXT_DE_PORT_HP_DDIA;
4245 break;
4246 case PORT_B:
4247 bit = BXT_DE_PORT_HP_DDIB;
4248 break;
4249 case PORT_C:
4250 bit = BXT_DE_PORT_HP_DDIC;
4251 break;
4252 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304253 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004254 return false;
4255 }
4256
4257 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4258}
4259
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004260/*
4261 * intel_digital_port_connected - is the specified port connected?
4262 * @dev_priv: i915 private structure
4263 * @port: the port to test
4264 *
4265 * Return %true if @port is connected, %false otherwise.
4266 */
David Weinehall23f889b2016-08-17 15:47:48 +03004267static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004268 struct intel_digital_port *port)
4269{
Jani Nikula0df53b72015-08-20 10:47:40 +03004270 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004271 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004272 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004273 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004274 else if (IS_BROXTON(dev_priv))
4275 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004276 else if (IS_GM45(dev_priv))
4277 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004278 else
4279 return g4x_digital_port_connected(dev_priv, port);
4280}
4281
Keith Packard8c241fe2011-09-28 16:38:44 -07004282static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004283intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004284{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004285 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004286
Jani Nikula9cd300e2012-10-19 14:51:52 +03004287 /* use cached edid if we have one */
4288 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004289 /* invalid edid */
4290 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004291 return NULL;
4292
Jani Nikula55e9ede2013-10-01 10:38:54 +03004293 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004294 } else
4295 return drm_get_edid(&intel_connector->base,
4296 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004297}
4298
Chris Wilsonbeb60602014-09-02 20:04:00 +01004299static void
4300intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004301{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004302 struct intel_connector *intel_connector = intel_dp->attached_connector;
4303 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004304
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304305 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004306 edid = intel_dp_get_edid(intel_dp);
4307 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004308
Chris Wilsonbeb60602014-09-02 20:04:00 +01004309 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4310 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4311 else
4312 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4313}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004314
Chris Wilsonbeb60602014-09-02 20:04:00 +01004315static void
4316intel_dp_unset_edid(struct intel_dp *intel_dp)
4317{
4318 struct intel_connector *intel_connector = intel_dp->attached_connector;
4319
4320 kfree(intel_connector->detect_edid);
4321 intel_connector->detect_edid = NULL;
4322
4323 intel_dp->has_audio = false;
4324}
4325
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304326static void
4327intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004328{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304329 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004330 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004331 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4332 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004333 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004334 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004335 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004336 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004337
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004338 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4339 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004340
Chris Wilsond410b562014-09-02 20:03:59 +01004341 /* Can't disconnect eDP, but you can close the lid... */
4342 if (is_edp(intel_dp))
4343 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004344 else if (intel_digital_port_connected(to_i915(dev),
4345 dp_to_dig_port(intel_dp)))
4346 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004347 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004348 status = connector_status_disconnected;
4349
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304350 if (status != connector_status_connected) {
4351 intel_dp->compliance_test_active = 0;
4352 intel_dp->compliance_test_type = 0;
4353 intel_dp->compliance_test_data = 0;
4354
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004355 if (intel_dp->is_mst) {
4356 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4357 intel_dp->is_mst,
4358 intel_dp->mst_mgr.mst_state);
4359 intel_dp->is_mst = false;
4360 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4361 intel_dp->is_mst);
4362 }
4363
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004364 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304365 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004366
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304367 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004368 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304369
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004370 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4371 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4372 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4373
4374 intel_dp_print_rates(intel_dp);
4375
Adam Jackson0d198322012-05-14 16:05:47 -04004376 intel_dp_probe_oui(intel_dp);
4377
Mika Kahola0e390a32016-09-09 14:10:53 +03004378 intel_dp_print_hw_revision(intel_dp);
Mika Kahola1a2724f2016-09-09 14:10:54 +03004379 intel_dp_print_sw_revision(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004380
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004381 intel_dp_configure_mst(intel_dp);
4382
4383 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304384 /*
4385 * If we are in MST mode then this connector
4386 * won't appear connected or have anything
4387 * with EDID on it
4388 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004389 status = connector_status_disconnected;
4390 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304391 } else if (connector->status == connector_status_connected) {
4392 /*
4393 * If display was connected already and is still connected
4394 * check links status, there has been known issues of
4395 * link loss triggerring long pulse!!!!
4396 */
4397 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4398 intel_dp_check_link_status(intel_dp);
4399 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4400 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004401 }
4402
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304403 /*
4404 * Clearing NACK and defer counts to get their exact values
4405 * while reading EDID which are required by Compliance tests
4406 * 4.2.2.4 and 4.2.2.5
4407 */
4408 intel_dp->aux.i2c_nack_count = 0;
4409 intel_dp->aux.i2c_defer_count = 0;
4410
Chris Wilsonbeb60602014-09-02 20:04:00 +01004411 intel_dp_set_edid(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004412
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004413 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304414 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004415
Todd Previte09b1eb12015-04-20 15:27:34 -07004416 /* Try to read the source of the interrupt */
4417 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004418 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4419 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004420 /* Clear interrupt source */
4421 drm_dp_dpcd_writeb(&intel_dp->aux,
4422 DP_DEVICE_SERVICE_IRQ_VECTOR,
4423 sink_irq_vector);
4424
4425 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4426 intel_dp_handle_test_request(intel_dp);
4427 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4428 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4429 }
4430
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004431out:
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004432 if ((status != connector_status_connected) &&
4433 (intel_dp->is_mst == false))
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304434 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304435
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004436 intel_display_power_put(to_i915(dev), power_domain);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304437 return;
4438}
4439
4440static enum drm_connector_status
4441intel_dp_detect(struct drm_connector *connector, bool force)
4442{
4443 struct intel_dp *intel_dp = intel_attached_dp(connector);
4444 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4445 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4446 struct intel_connector *intel_connector = to_intel_connector(connector);
4447
4448 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4449 connector->base.id, connector->name);
4450
4451 if (intel_dp->is_mst) {
4452 /* MST devices are disconnected from a monitor POV */
4453 intel_dp_unset_edid(intel_dp);
4454 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004455 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304456 return connector_status_disconnected;
4457 }
4458
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304459 /* If full detect is not performed yet, do a full detect */
4460 if (!intel_dp->detect_done)
4461 intel_dp_long_pulse(intel_dp->attached_connector);
4462
4463 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304464
Ville Syrjälä1b7f2c82016-07-18 13:15:14 +03004465 if (is_edp(intel_dp) || intel_connector->detect_edid)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304466 return connector_status_connected;
4467 else
4468 return connector_status_disconnected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004469}
4470
Chris Wilsonbeb60602014-09-02 20:04:00 +01004471static void
4472intel_dp_force(struct drm_connector *connector)
4473{
4474 struct intel_dp *intel_dp = intel_attached_dp(connector);
4475 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004476 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004477 enum intel_display_power_domain power_domain;
4478
4479 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4480 connector->base.id, connector->name);
4481 intel_dp_unset_edid(intel_dp);
4482
4483 if (connector->status != connector_status_connected)
4484 return;
4485
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004486 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4487 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004488
4489 intel_dp_set_edid(intel_dp);
4490
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004491 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004492
4493 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004494 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004495}
4496
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004497static int intel_dp_get_modes(struct drm_connector *connector)
4498{
Jani Nikuladd06f902012-10-19 14:51:50 +03004499 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004500 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004501
Chris Wilsonbeb60602014-09-02 20:04:00 +01004502 edid = intel_connector->detect_edid;
4503 if (edid) {
4504 int ret = intel_connector_update_modes(connector, edid);
4505 if (ret)
4506 return ret;
4507 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004508
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004509 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004510 if (is_edp(intel_attached_dp(connector)) &&
4511 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004512 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004513
4514 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004515 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004516 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004517 drm_mode_probed_add(connector, mode);
4518 return 1;
4519 }
4520 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004521
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004522 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004523}
4524
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004525static bool
4526intel_dp_detect_audio(struct drm_connector *connector)
4527{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004528 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004529 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004530
Chris Wilsonbeb60602014-09-02 20:04:00 +01004531 edid = to_intel_connector(connector)->detect_edid;
4532 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004533 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004534
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004535 return has_audio;
4536}
4537
Chris Wilsonf6849602010-09-19 09:29:33 +01004538static int
4539intel_dp_set_property(struct drm_connector *connector,
4540 struct drm_property *property,
4541 uint64_t val)
4542{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004543 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004544 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004545 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4546 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004547 int ret;
4548
Rob Clark662595d2012-10-11 20:36:04 -05004549 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004550 if (ret)
4551 return ret;
4552
Chris Wilson3f43c482011-05-12 22:17:24 +01004553 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004554 int i = val;
4555 bool has_audio;
4556
4557 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004558 return 0;
4559
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004560 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004561
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004562 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004563 has_audio = intel_dp_detect_audio(connector);
4564 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004565 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004566
4567 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004568 return 0;
4569
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004570 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004571 goto done;
4572 }
4573
Chris Wilsone953fd72011-02-21 22:23:52 +00004574 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004575 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004576 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004577
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004578 switch (val) {
4579 case INTEL_BROADCAST_RGB_AUTO:
4580 intel_dp->color_range_auto = true;
4581 break;
4582 case INTEL_BROADCAST_RGB_FULL:
4583 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004584 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004585 break;
4586 case INTEL_BROADCAST_RGB_LIMITED:
4587 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004588 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004589 break;
4590 default:
4591 return -EINVAL;
4592 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004593
4594 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004595 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004596 return 0;
4597
Chris Wilsone953fd72011-02-21 22:23:52 +00004598 goto done;
4599 }
4600
Yuly Novikov53b41832012-10-26 12:04:00 +03004601 if (is_edp(intel_dp) &&
4602 property == connector->dev->mode_config.scaling_mode_property) {
4603 if (val == DRM_MODE_SCALE_NONE) {
4604 DRM_DEBUG_KMS("no scaling not supported\n");
4605 return -EINVAL;
4606 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004607 if (HAS_GMCH_DISPLAY(dev_priv) &&
4608 val == DRM_MODE_SCALE_CENTER) {
4609 DRM_DEBUG_KMS("centering not supported\n");
4610 return -EINVAL;
4611 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004612
4613 if (intel_connector->panel.fitting_mode == val) {
4614 /* the eDP scaling property is not changed */
4615 return 0;
4616 }
4617 intel_connector->panel.fitting_mode = val;
4618
4619 goto done;
4620 }
4621
Chris Wilsonf6849602010-09-19 09:29:33 +01004622 return -EINVAL;
4623
4624done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004625 if (intel_encoder->base.crtc)
4626 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004627
4628 return 0;
4629}
4630
Chris Wilson7a418e32016-06-24 14:00:14 +01004631static int
4632intel_dp_connector_register(struct drm_connector *connector)
4633{
4634 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004635 int ret;
4636
4637 ret = intel_connector_register(connector);
4638 if (ret)
4639 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004640
4641 i915_debugfs_connector_add(connector);
4642
4643 DRM_DEBUG_KMS("registering %s bus for %s\n",
4644 intel_dp->aux.name, connector->kdev->kobj.name);
4645
4646 intel_dp->aux.dev = connector->kdev;
4647 return drm_dp_aux_register(&intel_dp->aux);
4648}
4649
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004650static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004651intel_dp_connector_unregister(struct drm_connector *connector)
4652{
4653 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4654 intel_connector_unregister(connector);
4655}
4656
4657static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004658intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004659{
Jani Nikula1d508702012-10-19 14:51:49 +03004660 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004661
Chris Wilson10e972d2014-09-04 21:43:45 +01004662 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004663
Jani Nikula9cd300e2012-10-19 14:51:52 +03004664 if (!IS_ERR_OR_NULL(intel_connector->edid))
4665 kfree(intel_connector->edid);
4666
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004667 /* Can't call is_edp() since the encoder may have been destroyed
4668 * already. */
4669 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004670 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004671
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004672 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004673 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004674}
4675
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004676void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004677{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004678 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4679 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004680
Dave Airlie0e32b392014-05-02 14:02:48 +10004681 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004682 if (is_edp(intel_dp)) {
4683 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004684 /*
4685 * vdd might still be enabled do to the delayed vdd off.
4686 * Make sure vdd is actually turned off here.
4687 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004688 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004689 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004690 pps_unlock(intel_dp);
4691
Clint Taylor01527b32014-07-07 13:01:46 -07004692 if (intel_dp->edp_notifier.notifier_call) {
4693 unregister_reboot_notifier(&intel_dp->edp_notifier);
4694 intel_dp->edp_notifier.notifier_call = NULL;
4695 }
Keith Packardbd943152011-09-18 23:09:52 -07004696 }
Chris Wilson99681882016-06-20 09:29:17 +01004697
4698 intel_dp_aux_fini(intel_dp);
4699
Imre Deakc8bd0e42014-12-12 17:57:38 +02004700 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004701 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004702}
4703
Imre Deakbf93ba62016-04-18 10:04:21 +03004704void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004705{
4706 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4707
4708 if (!is_edp(intel_dp))
4709 return;
4710
Ville Syrjälä951468f2014-09-04 14:55:31 +03004711 /*
4712 * vdd might still be enabled do to the delayed vdd off.
4713 * Make sure vdd is actually turned off here.
4714 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004715 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004716 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004717 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004718 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004719}
4720
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004721static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4722{
4723 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4724 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004725 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004726 enum intel_display_power_domain power_domain;
4727
4728 lockdep_assert_held(&dev_priv->pps_mutex);
4729
4730 if (!edp_have_panel_vdd(intel_dp))
4731 return;
4732
4733 /*
4734 * The VDD bit needs a power domain reference, so if the bit is
4735 * already enabled when we boot or resume, grab this reference and
4736 * schedule a vdd off, so we don't hold on to the reference
4737 * indefinitely.
4738 */
4739 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004740 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004741 intel_display_power_get(dev_priv, power_domain);
4742
4743 edp_panel_vdd_schedule_off(intel_dp);
4744}
4745
Imre Deakbf93ba62016-04-18 10:04:21 +03004746void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004747{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004748 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
4749 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4750
4751 if (!HAS_DDI(dev_priv))
4752 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004753
4754 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4755 return;
4756
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004757 pps_lock(intel_dp);
4758
Imre Deak335f7522016-08-10 14:07:32 +03004759 /* Reinit the power sequencer, in case BIOS did something with it. */
4760 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004761 intel_edp_panel_vdd_sanitize(intel_dp);
4762
4763 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004764}
4765
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004766static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004767 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004768 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004769 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004770 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004771 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004772 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004773 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004774 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004775 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004776 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004777 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004778};
4779
4780static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4781 .get_modes = intel_dp_get_modes,
4782 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004783};
4784
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004785static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004786 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004787 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004788};
4789
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004790enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004791intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4792{
4793 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004794 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004795 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004796 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004797 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004798 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004799
Takashi Iwai25400582015-11-19 12:09:56 +01004800 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4801 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004802 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004803
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004804 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4805 /*
4806 * vdd off can generate a long pulse on eDP which
4807 * would require vdd on to handle it, and thus we
4808 * would end up in an endless cycle of
4809 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4810 */
4811 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4812 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004813 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004814 }
4815
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004816 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4817 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004818 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004819
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004820 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004821 intel_display_power_get(dev_priv, power_domain);
4822
Dave Airlie0e32b392014-05-02 14:02:48 +10004823 if (long_hpd) {
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304824 intel_dp_long_pulse(intel_dp->attached_connector);
4825 if (intel_dp->is_mst)
4826 ret = IRQ_HANDLED;
4827 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004828
Dave Airlie0e32b392014-05-02 14:02:48 +10004829 } else {
4830 if (intel_dp->is_mst) {
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304831 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4832 /*
4833 * If we were in MST mode, and device is not
4834 * there, get out of MST mode
4835 */
4836 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4837 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4838 intel_dp->is_mst = false;
4839 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4840 intel_dp->is_mst);
4841 goto put_power;
4842 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004843 }
4844
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304845 if (!intel_dp->is_mst) {
4846 if (!intel_dp_short_pulse(intel_dp)) {
4847 intel_dp_long_pulse(intel_dp->attached_connector);
4848 goto put_power;
4849 }
4850 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004851 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004852
4853 ret = IRQ_HANDLED;
4854
Imre Deak1c767b32014-08-18 14:42:42 +03004855put_power:
4856 intel_display_power_put(dev_priv, power_domain);
4857
4858 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004859}
4860
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004861/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004862bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004863{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004864 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004865
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004866 /*
4867 * eDP not supported on g4x. so bail out early just
4868 * for a bit extra safety in case the VBT is bonkers.
4869 */
4870 if (INTEL_INFO(dev)->gen < 5)
4871 return false;
4872
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004873 if (port == PORT_A)
4874 return true;
4875
Jani Nikula951d9ef2016-03-16 12:43:31 +02004876 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004877}
4878
Dave Airlie0e32b392014-05-02 14:02:48 +10004879void
Chris Wilsonf6849602010-09-19 09:29:33 +01004880intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4881{
Yuly Novikov53b41832012-10-26 12:04:00 +03004882 struct intel_connector *intel_connector = to_intel_connector(connector);
4883
Chris Wilson3f43c482011-05-12 22:17:24 +01004884 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004885 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004886 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004887
4888 if (is_edp(intel_dp)) {
4889 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004890 drm_object_attach_property(
4891 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004892 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004893 DRM_MODE_SCALE_ASPECT);
4894 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004895 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004896}
4897
Imre Deakdada1a92014-01-29 13:25:41 +02004898static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4899{
Abhay Kumard28d4732016-01-22 17:39:04 -08004900 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004901 intel_dp->last_power_on = jiffies;
4902 intel_dp->last_backlight_off = jiffies;
4903}
4904
Daniel Vetter67a54562012-10-20 20:57:45 +02004905static void
Imre Deak54648612016-06-16 16:37:22 +03004906intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4907 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004908{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304909 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004910 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004911
Imre Deak8e8232d2016-06-16 16:37:21 +03004912 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004913
4914 /* Workaround: Need to write PP_CONTROL with the unlock key as
4915 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304916 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004917
Imre Deak8e8232d2016-06-16 16:37:21 +03004918 pp_on = I915_READ(regs.pp_on);
4919 pp_off = I915_READ(regs.pp_off);
Imre Deak54648612016-06-16 16:37:22 +03004920 if (!IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004921 I915_WRITE(regs.pp_ctrl, pp_ctl);
4922 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304923 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004924
4925 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004926 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4927 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004928
Imre Deak54648612016-06-16 16:37:22 +03004929 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4930 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004931
Imre Deak54648612016-06-16 16:37:22 +03004932 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4933 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004934
Imre Deak54648612016-06-16 16:37:22 +03004935 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4936 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004937
Imre Deak54648612016-06-16 16:37:22 +03004938 if (IS_BROXTON(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304939 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4940 BXT_POWER_CYCLE_DELAY_SHIFT;
4941 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004942 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304943 else
Imre Deak54648612016-06-16 16:37:22 +03004944 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304945 } else {
Imre Deak54648612016-06-16 16:37:22 +03004946 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004947 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304948 }
Imre Deak54648612016-06-16 16:37:22 +03004949}
4950
4951static void
Imre Deakde9c1b62016-06-16 20:01:46 +03004952intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
4953{
4954 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4955 state_name,
4956 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
4957}
4958
4959static void
4960intel_pps_verify_state(struct drm_i915_private *dev_priv,
4961 struct intel_dp *intel_dp)
4962{
4963 struct edp_power_seq hw;
4964 struct edp_power_seq *sw = &intel_dp->pps_delays;
4965
4966 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
4967
4968 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
4969 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
4970 DRM_ERROR("PPS state mismatch\n");
4971 intel_pps_dump_state("sw", sw);
4972 intel_pps_dump_state("hw", &hw);
4973 }
4974}
4975
4976static void
Imre Deak54648612016-06-16 16:37:22 +03004977intel_dp_init_panel_power_sequencer(struct drm_device *dev,
4978 struct intel_dp *intel_dp)
4979{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004980 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03004981 struct edp_power_seq cur, vbt, spec,
4982 *final = &intel_dp->pps_delays;
4983
4984 lockdep_assert_held(&dev_priv->pps_mutex);
4985
4986 /* already initialized? */
4987 if (final->t11_t12 != 0)
4988 return;
4989
4990 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02004991
Imre Deakde9c1b62016-06-16 20:01:46 +03004992 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02004993
Jani Nikula6aa23e62016-03-24 17:50:20 +02004994 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02004995
4996 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
4997 * our hw here, which are all in 100usec. */
4998 spec.t1_t3 = 210 * 10;
4999 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5000 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5001 spec.t10 = 500 * 10;
5002 /* This one is special and actually in units of 100ms, but zero
5003 * based in the hw (so we need to add 100 ms). But the sw vbt
5004 * table multiplies it with 1000 to make it in units of 100usec,
5005 * too. */
5006 spec.t11_t12 = (510 + 100) * 10;
5007
Imre Deakde9c1b62016-06-16 20:01:46 +03005008 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005009
5010 /* Use the max of the register settings and vbt. If both are
5011 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005012#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005013 spec.field : \
5014 max(cur.field, vbt.field))
5015 assign_final(t1_t3);
5016 assign_final(t8);
5017 assign_final(t9);
5018 assign_final(t10);
5019 assign_final(t11_t12);
5020#undef assign_final
5021
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005022#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005023 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5024 intel_dp->backlight_on_delay = get_delay(t8);
5025 intel_dp->backlight_off_delay = get_delay(t9);
5026 intel_dp->panel_power_down_delay = get_delay(t10);
5027 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5028#undef get_delay
5029
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005030 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5031 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5032 intel_dp->panel_power_cycle_delay);
5033
5034 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5035 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005036
5037 /*
5038 * We override the HW backlight delays to 1 because we do manual waits
5039 * on them. For T8, even BSpec recommends doing it. For T9, if we
5040 * don't do this, we'll end up waiting for the backlight off delay
5041 * twice: once when we do the manual sleep, and once when we disable
5042 * the panel and wait for the PP_STATUS bit to become zero.
5043 */
5044 final->t8 = 1;
5045 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005046}
5047
5048static void
5049intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005050 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005051{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005052 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005053 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005054 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005055 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005056 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005057 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005058
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005059 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005060
Imre Deak8e8232d2016-06-16 16:37:21 +03005061 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005062
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005063 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005064 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5065 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005066 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005067 /* Compute the divisor for the pp clock, simply match the Bspec
5068 * formula. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305069 if (IS_BROXTON(dev)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005070 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305071 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5072 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5073 << BXT_POWER_CYCLE_DELAY_SHIFT);
5074 } else {
5075 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5076 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5077 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5078 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005079
5080 /* Haswell doesn't have any port selection bits for the panel
5081 * power sequencer any more. */
Wayne Boyer666a4532015-12-09 12:29:35 -08005082 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005083 port_sel = PANEL_PORT_SELECT_VLV(port);
Imre Deakbc7d38a2013-05-16 14:40:36 +03005084 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005085 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005086 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005087 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005088 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005089 }
5090
Jesse Barnes453c5422013-03-28 09:55:41 -07005091 pp_on |= port_sel;
5092
Imre Deak8e8232d2016-06-16 16:37:21 +03005093 I915_WRITE(regs.pp_on, pp_on);
5094 I915_WRITE(regs.pp_off, pp_off);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305095 if (IS_BROXTON(dev))
Imre Deak8e8232d2016-06-16 16:37:21 +03005096 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305097 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005098 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005099
Daniel Vetter67a54562012-10-20 20:57:45 +02005100 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
Imre Deak8e8232d2016-06-16 16:37:21 +03005101 I915_READ(regs.pp_on),
5102 I915_READ(regs.pp_off),
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305103 IS_BROXTON(dev) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005104 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5105 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005106}
5107
Imre Deak335f7522016-08-10 14:07:32 +03005108static void intel_dp_pps_init(struct drm_device *dev,
5109 struct intel_dp *intel_dp)
5110{
5111 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
5112 vlv_initial_power_sequencer_setup(intel_dp);
5113 } else {
5114 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5115 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5116 }
5117}
5118
Vandana Kannanb33a2812015-02-13 15:33:03 +05305119/**
5120 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005121 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005122 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305123 * @refresh_rate: RR to be programmed
5124 *
5125 * This function gets called when refresh rate (RR) has to be changed from
5126 * one frequency to another. Switches can be between high and low RR
5127 * supported by the panel or to any other RR based on media playback (in
5128 * this case, RR value needs to be passed from user space).
5129 *
5130 * The caller of this function needs to take a lock on dev_priv->drrs.
5131 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005132static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5133 struct intel_crtc_state *crtc_state,
5134 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305135{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305136 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305137 struct intel_digital_port *dig_port = NULL;
5138 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005139 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305140 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305141
5142 if (refresh_rate <= 0) {
5143 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5144 return;
5145 }
5146
Vandana Kannan96178ee2015-01-10 02:25:56 +05305147 if (intel_dp == NULL) {
5148 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305149 return;
5150 }
5151
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005152 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005153 * FIXME: This needs proper synchronization with psr state for some
5154 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005155 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305156
Vandana Kannan96178ee2015-01-10 02:25:56 +05305157 dig_port = dp_to_dig_port(intel_dp);
5158 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005159 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305160
5161 if (!intel_crtc) {
5162 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5163 return;
5164 }
5165
Vandana Kannan96178ee2015-01-10 02:25:56 +05305166 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305167 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5168 return;
5169 }
5170
Vandana Kannan96178ee2015-01-10 02:25:56 +05305171 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5172 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305173 index = DRRS_LOW_RR;
5174
Vandana Kannan96178ee2015-01-10 02:25:56 +05305175 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305176 DRM_DEBUG_KMS(
5177 "DRRS requested for previously set RR...ignoring\n");
5178 return;
5179 }
5180
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005181 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305182 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5183 return;
5184 }
5185
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005186 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305187 switch (index) {
5188 case DRRS_HIGH_RR:
5189 intel_dp_set_m_n(intel_crtc, M1_N1);
5190 break;
5191 case DRRS_LOW_RR:
5192 intel_dp_set_m_n(intel_crtc, M2_N2);
5193 break;
5194 case DRRS_MAX_RR:
5195 default:
5196 DRM_ERROR("Unsupported refreshrate type\n");
5197 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005198 } else if (INTEL_GEN(dev_priv) > 6) {
5199 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005200 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305201
Ville Syrjälä649636e2015-09-22 19:50:01 +03005202 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305203 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005204 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305205 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5206 else
5207 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305208 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005209 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305210 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5211 else
5212 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305213 }
5214 I915_WRITE(reg, val);
5215 }
5216
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305217 dev_priv->drrs.refresh_rate_type = index;
5218
5219 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5220}
5221
Vandana Kannanb33a2812015-02-13 15:33:03 +05305222/**
5223 * intel_edp_drrs_enable - init drrs struct if supported
5224 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005225 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305226 *
5227 * Initializes frontbuffer_bits and drrs.dp
5228 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005229void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5230 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305231{
5232 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005233 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305234
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005235 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305236 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5237 return;
5238 }
5239
5240 mutex_lock(&dev_priv->drrs.mutex);
5241 if (WARN_ON(dev_priv->drrs.dp)) {
5242 DRM_ERROR("DRRS already enabled\n");
5243 goto unlock;
5244 }
5245
5246 dev_priv->drrs.busy_frontbuffer_bits = 0;
5247
5248 dev_priv->drrs.dp = intel_dp;
5249
5250unlock:
5251 mutex_unlock(&dev_priv->drrs.mutex);
5252}
5253
Vandana Kannanb33a2812015-02-13 15:33:03 +05305254/**
5255 * intel_edp_drrs_disable - Disable DRRS
5256 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005257 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305258 *
5259 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005260void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5261 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305262{
5263 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005264 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305265
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005266 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305267 return;
5268
5269 mutex_lock(&dev_priv->drrs.mutex);
5270 if (!dev_priv->drrs.dp) {
5271 mutex_unlock(&dev_priv->drrs.mutex);
5272 return;
5273 }
5274
5275 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005276 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5277 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305278
5279 dev_priv->drrs.dp = NULL;
5280 mutex_unlock(&dev_priv->drrs.mutex);
5281
5282 cancel_delayed_work_sync(&dev_priv->drrs.work);
5283}
5284
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305285static void intel_edp_drrs_downclock_work(struct work_struct *work)
5286{
5287 struct drm_i915_private *dev_priv =
5288 container_of(work, typeof(*dev_priv), drrs.work.work);
5289 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305290
Vandana Kannan96178ee2015-01-10 02:25:56 +05305291 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305292
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305293 intel_dp = dev_priv->drrs.dp;
5294
5295 if (!intel_dp)
5296 goto unlock;
5297
5298 /*
5299 * The delayed work can race with an invalidate hence we need to
5300 * recheck.
5301 */
5302
5303 if (dev_priv->drrs.busy_frontbuffer_bits)
5304 goto unlock;
5305
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005306 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5307 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5308
5309 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5310 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5311 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305312
5313unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305314 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305315}
5316
Vandana Kannanb33a2812015-02-13 15:33:03 +05305317/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305318 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005319 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305320 * @frontbuffer_bits: frontbuffer plane tracking bits
5321 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305322 * This function gets called everytime rendering on the given planes start.
5323 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305324 *
5325 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5326 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005327void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5328 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305329{
Vandana Kannana93fad02015-01-10 02:25:59 +05305330 struct drm_crtc *crtc;
5331 enum pipe pipe;
5332
Daniel Vetter9da7d692015-04-09 16:44:15 +02005333 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305334 return;
5335
Daniel Vetter88f933a2015-04-09 16:44:16 +02005336 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305337
Vandana Kannana93fad02015-01-10 02:25:59 +05305338 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005339 if (!dev_priv->drrs.dp) {
5340 mutex_unlock(&dev_priv->drrs.mutex);
5341 return;
5342 }
5343
Vandana Kannana93fad02015-01-10 02:25:59 +05305344 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5345 pipe = to_intel_crtc(crtc)->pipe;
5346
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005347 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5348 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5349
Ramalingam C0ddfd202015-06-15 20:50:05 +05305350 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005351 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005352 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5353 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305354
Vandana Kannana93fad02015-01-10 02:25:59 +05305355 mutex_unlock(&dev_priv->drrs.mutex);
5356}
5357
Vandana Kannanb33a2812015-02-13 15:33:03 +05305358/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305359 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005360 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305361 * @frontbuffer_bits: frontbuffer plane tracking bits
5362 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305363 * This function gets called every time rendering on the given planes has
5364 * completed or flip on a crtc is completed. So DRRS should be upclocked
5365 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5366 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305367 *
5368 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5369 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005370void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5371 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305372{
Vandana Kannana93fad02015-01-10 02:25:59 +05305373 struct drm_crtc *crtc;
5374 enum pipe pipe;
5375
Daniel Vetter9da7d692015-04-09 16:44:15 +02005376 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305377 return;
5378
Daniel Vetter88f933a2015-04-09 16:44:16 +02005379 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305380
Vandana Kannana93fad02015-01-10 02:25:59 +05305381 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005382 if (!dev_priv->drrs.dp) {
5383 mutex_unlock(&dev_priv->drrs.mutex);
5384 return;
5385 }
5386
Vandana Kannana93fad02015-01-10 02:25:59 +05305387 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5388 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005389
5390 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305391 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5392
Ramalingam C0ddfd202015-06-15 20:50:05 +05305393 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005394 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005395 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5396 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305397
5398 /*
5399 * flush also means no more activity hence schedule downclock, if all
5400 * other fbs are quiescent too
5401 */
5402 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305403 schedule_delayed_work(&dev_priv->drrs.work,
5404 msecs_to_jiffies(1000));
5405 mutex_unlock(&dev_priv->drrs.mutex);
5406}
5407
Vandana Kannanb33a2812015-02-13 15:33:03 +05305408/**
5409 * DOC: Display Refresh Rate Switching (DRRS)
5410 *
5411 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5412 * which enables swtching between low and high refresh rates,
5413 * dynamically, based on the usage scenario. This feature is applicable
5414 * for internal panels.
5415 *
5416 * Indication that the panel supports DRRS is given by the panel EDID, which
5417 * would list multiple refresh rates for one resolution.
5418 *
5419 * DRRS is of 2 types - static and seamless.
5420 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5421 * (may appear as a blink on screen) and is used in dock-undock scenario.
5422 * Seamless DRRS involves changing RR without any visual effect to the user
5423 * and can be used during normal system usage. This is done by programming
5424 * certain registers.
5425 *
5426 * Support for static/seamless DRRS may be indicated in the VBT based on
5427 * inputs from the panel spec.
5428 *
5429 * DRRS saves power by switching to low RR based on usage scenarios.
5430 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005431 * The implementation is based on frontbuffer tracking implementation. When
5432 * there is a disturbance on the screen triggered by user activity or a periodic
5433 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5434 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5435 * made.
5436 *
5437 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5438 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305439 *
5440 * DRRS can be further extended to support other internal panels and also
5441 * the scenario of video playback wherein RR is set based on the rate
5442 * requested by userspace.
5443 */
5444
5445/**
5446 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5447 * @intel_connector: eDP connector
5448 * @fixed_mode: preferred mode of panel
5449 *
5450 * This function is called only once at driver load to initialize basic
5451 * DRRS stuff.
5452 *
5453 * Returns:
5454 * Downclock mode if panel supports it, else return NULL.
5455 * DRRS support is determined by the presence of downclock mode (apart
5456 * from VBT setting).
5457 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305458static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305459intel_dp_drrs_init(struct intel_connector *intel_connector,
5460 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305461{
5462 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305463 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005464 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305465 struct drm_display_mode *downclock_mode = NULL;
5466
Daniel Vetter9da7d692015-04-09 16:44:15 +02005467 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5468 mutex_init(&dev_priv->drrs.mutex);
5469
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305470 if (INTEL_INFO(dev)->gen <= 6) {
5471 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5472 return NULL;
5473 }
5474
5475 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005476 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305477 return NULL;
5478 }
5479
5480 downclock_mode = intel_find_panel_downclock
5481 (dev, fixed_mode, connector);
5482
5483 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305484 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305485 return NULL;
5486 }
5487
Vandana Kannan96178ee2015-01-10 02:25:56 +05305488 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305489
Vandana Kannan96178ee2015-01-10 02:25:56 +05305490 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005491 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305492 return downclock_mode;
5493}
5494
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005495static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005496 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005497{
5498 struct drm_connector *connector = &intel_connector->base;
5499 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005500 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5501 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005502 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005503 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305504 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005505 bool has_dpcd;
5506 struct drm_display_mode *scan;
5507 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005508 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005509
5510 if (!is_edp(intel_dp))
5511 return true;
5512
Imre Deak97a824e12016-06-21 11:51:47 +03005513 /*
5514 * On IBX/CPT we may get here with LVDS already registered. Since the
5515 * driver uses the only internal power sequencer available for both
5516 * eDP and LVDS bail out early in this case to prevent interfering
5517 * with an already powered-on LVDS power sequencer.
5518 */
5519 if (intel_get_lvds_encoder(dev)) {
5520 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5521 DRM_INFO("LVDS was detected, not registering eDP\n");
5522
5523 return false;
5524 }
5525
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005526 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005527
5528 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005529 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005530 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005531
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005532 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005533
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005534 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005535 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005536
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005537 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005538 /* if this fails, presume the device is a ghost */
5539 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005540 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005541 }
5542
Daniel Vetter060c8772014-03-21 23:22:35 +01005543 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005544 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005545 if (edid) {
5546 if (drm_add_edid_modes(connector, edid)) {
5547 drm_mode_connector_update_edid_property(connector,
5548 edid);
5549 drm_edid_to_eld(connector, edid);
5550 } else {
5551 kfree(edid);
5552 edid = ERR_PTR(-EINVAL);
5553 }
5554 } else {
5555 edid = ERR_PTR(-ENOENT);
5556 }
5557 intel_connector->edid = edid;
5558
5559 /* prefer fixed mode from EDID if available */
5560 list_for_each_entry(scan, &connector->probed_modes, head) {
5561 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5562 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305563 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305564 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005565 break;
5566 }
5567 }
5568
5569 /* fallback to VBT if available for eDP */
5570 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5571 fixed_mode = drm_mode_duplicate(dev,
5572 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005573 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005574 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005575 connector->display_info.width_mm = fixed_mode->width_mm;
5576 connector->display_info.height_mm = fixed_mode->height_mm;
5577 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005578 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005579 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005580
Wayne Boyer666a4532015-12-09 12:29:35 -08005581 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005582 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5583 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005584
5585 /*
5586 * Figure out the current pipe for the initial backlight setup.
5587 * If the current pipe isn't valid, try the PPS pipe, and if that
5588 * fails just assume pipe A.
5589 */
5590 if (IS_CHERRYVIEW(dev))
5591 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5592 else
5593 pipe = PORT_TO_PIPE(intel_dp->DP);
5594
5595 if (pipe != PIPE_A && pipe != PIPE_B)
5596 pipe = intel_dp->pps_pipe;
5597
5598 if (pipe != PIPE_A && pipe != PIPE_B)
5599 pipe = PIPE_A;
5600
5601 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5602 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005603 }
5604
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305605 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005606 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005607 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005608
5609 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005610
5611out_vdd_off:
5612 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5613 /*
5614 * vdd might still be enabled do to the delayed vdd off.
5615 * Make sure vdd is actually turned off here.
5616 */
5617 pps_lock(intel_dp);
5618 edp_panel_vdd_off_sync(intel_dp);
5619 pps_unlock(intel_dp);
5620
5621 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005622}
5623
Paulo Zanoni16c25532013-06-12 17:27:25 -03005624bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005625intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5626 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005627{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005628 struct drm_connector *connector = &intel_connector->base;
5629 struct intel_dp *intel_dp = &intel_dig_port->dp;
5630 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5631 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005632 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005633 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005634 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005635
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005636 if (WARN(intel_dig_port->max_lanes < 1,
5637 "Not enough lanes (%d) for DP on port %c\n",
5638 intel_dig_port->max_lanes, port_name(port)))
5639 return false;
5640
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005641 intel_dp->pps_pipe = INVALID_PIPE;
5642
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005643 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005644 if (INTEL_INFO(dev)->gen >= 9)
5645 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005646 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
5647 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
5648 else if (HAS_PCH_SPLIT(dev))
5649 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5650 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005651 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005652
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005653 if (INTEL_INFO(dev)->gen >= 9)
5654 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5655 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005656 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005657
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005658 if (HAS_DDI(dev))
5659 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5660
Daniel Vetter07679352012-09-06 22:15:42 +02005661 /* Preserve the current hw state. */
5662 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005663 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005664
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005665 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305666 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005667 else
5668 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005669
Imre Deakf7d24902013-05-08 13:14:05 +03005670 /*
5671 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5672 * for DP the encoder type can be set by the caller to
5673 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5674 */
5675 if (type == DRM_MODE_CONNECTOR_eDP)
5676 intel_encoder->type = INTEL_OUTPUT_EDP;
5677
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005678 /* eDP only on port B and/or C on vlv/chv */
Wayne Boyer666a4532015-12-09 12:29:35 -08005679 if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
5680 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005681 return false;
5682
Imre Deake7281ea2013-05-08 13:14:08 +03005683 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5684 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5685 port_name(port));
5686
Adam Jacksonb3295302010-07-16 14:46:28 -04005687 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005688 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5689
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005690 connector->interlace_allowed = true;
5691 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005692
Mika Kaholab6339582016-09-09 14:10:52 +03005693 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005694
Daniel Vetter66a92782012-07-12 20:08:18 +02005695 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005696 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005697
Chris Wilsondf0e9242010-09-09 16:20:55 +01005698 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005699
Paulo Zanoniaffa9352012-11-23 15:30:39 -02005700 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005701 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5702 else
5703 intel_connector->get_hw_state = intel_connector_get_hw_state;
5704
Jani Nikula0b998362014-03-14 16:51:17 +02005705 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005706 switch (port) {
5707 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005708 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005709 break;
5710 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005711 intel_encoder->hpd_pin = HPD_PORT_B;
Jani Nikulae87a0052015-10-20 15:22:02 +03005712 if (IS_BXT_REVID(dev, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305713 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005714 break;
5715 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005716 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005717 break;
5718 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005719 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005720 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005721 case PORT_E:
5722 intel_encoder->hpd_pin = HPD_PORT_E;
5723 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005724 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005725 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005726 }
5727
Dave Airlie0e32b392014-05-02 14:02:48 +10005728 /* init MST on ports that can support it */
Ville Syrjäläf8e58dd2016-06-22 21:56:59 +03005729 if (HAS_DP_MST(dev) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005730 (port == PORT_B || port == PORT_C || port == PORT_D))
5731 intel_dp_mst_encoder_init(intel_dig_port,
5732 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005733
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005734 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005735 intel_dp_aux_fini(intel_dp);
5736 intel_dp_mst_encoder_cleanup(intel_dig_port);
5737 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005738 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005739
Chris Wilsonf6849602010-09-19 09:29:33 +01005740 intel_dp_add_properties(intel_dp, connector);
5741
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005742 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5743 * 0xd. Failure to do so will result in spurious interrupts being
5744 * generated on the port when a cable is not attached.
5745 */
5746 if (IS_G4X(dev) && !IS_GM45(dev)) {
5747 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5748 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5749 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005750
5751 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005752
5753fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005754 drm_connector_cleanup(connector);
5755
5756 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005757}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005758
Chris Wilson457c52d2016-06-01 08:27:50 +01005759bool intel_dp_init(struct drm_device *dev,
5760 i915_reg_t output_reg,
5761 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005762{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005763 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005764 struct intel_digital_port *intel_dig_port;
5765 struct intel_encoder *intel_encoder;
5766 struct drm_encoder *encoder;
5767 struct intel_connector *intel_connector;
5768
Daniel Vetterb14c5672013-09-19 12:18:32 +02005769 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005770 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005771 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005772
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005773 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305774 if (!intel_connector)
5775 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005776
5777 intel_encoder = &intel_dig_port->base;
5778 encoder = &intel_encoder->base;
5779
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305780 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005781 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305782 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005783
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005784 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005785 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005786 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005787 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005788 intel_encoder->suspend = intel_dp_encoder_suspend;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005789 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005790 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005791 intel_encoder->pre_enable = chv_pre_enable_dp;
5792 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005793 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005794 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005795 } else if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005796 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005797 intel_encoder->pre_enable = vlv_pre_enable_dp;
5798 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005799 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005800 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005801 intel_encoder->pre_enable = g4x_pre_enable_dp;
5802 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005803 if (INTEL_INFO(dev)->gen >= 5)
5804 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005805 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005806
Paulo Zanoni174edf12012-10-26 19:05:50 -02005807 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005808 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005809 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005810
Ville Syrjäläcca05022016-06-22 21:57:06 +03005811 intel_encoder->type = INTEL_OUTPUT_DP;
Ville Syrjälä882ec382014-04-28 14:07:43 +03005812 if (IS_CHERRYVIEW(dev)) {
5813 if (port == PORT_D)
5814 intel_encoder->crtc_mask = 1 << 2;
5815 else
5816 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5817 } else {
5818 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5819 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005820 intel_encoder->cloneable = 0;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005821
Dave Airlie13cf5502014-06-18 11:29:35 +10005822 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005823 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005824
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305825 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5826 goto err_init_connector;
5827
Chris Wilson457c52d2016-06-01 08:27:50 +01005828 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305829
5830err_init_connector:
5831 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305832err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305833 kfree(intel_connector);
5834err_connector_alloc:
5835 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005836 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005837}
Dave Airlie0e32b392014-05-02 14:02:48 +10005838
5839void intel_dp_mst_suspend(struct drm_device *dev)
5840{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005841 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005842 int i;
5843
5844 /* disable MST */
5845 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005846 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005847
5848 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005849 continue;
5850
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005851 if (intel_dig_port->dp.is_mst)
5852 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005853 }
5854}
5855
5856void intel_dp_mst_resume(struct drm_device *dev)
5857{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005858 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005859 int i;
5860
5861 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005862 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005863 int ret;
5864
5865 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005866 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005867
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005868 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5869 if (ret)
5870 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005871 }
5872}