blob: 03379baffe49987b5ff26bd4f0351c51921a55d0 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300159 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
160
161 return min(source_max, sink_max);
162}
163
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400164/*
165 * The units on the numbers in the next two are... bizarre. Examples will
166 * make it clearer; this one parallels an example in the eDP spec.
167 *
168 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
169 *
170 * 270000 * 1 * 8 / 10 == 216000
171 *
172 * The actual data capacity of that configuration is 2.16Gbit/s, so the
173 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
174 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
175 * 119000. At 18bpp that's 2142000 kilobits per second.
176 *
177 * Thus the strange-looking division by 10 in intel_dp_link_required, to
178 * get the result in decakilobits instead of kilobits.
179 */
180
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181static int
Keith Packardc8982612012-01-25 08:16:25 -0800182intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700183{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400184 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185}
186
187static int
Dave Airliefe27d532010-06-30 11:46:17 +1000188intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189{
190 return (max_link_clock * max_lanes * 8) / 10;
191}
192
Mika Kahola70ec0642016-09-09 14:10:55 +0300193static int
194intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
195{
196 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
197 struct intel_encoder *encoder = &intel_dig_port->base;
198 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
199 int max_dotclk = dev_priv->max_dotclk_freq;
200 int ds_max_dotclk;
201
202 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
203
204 if (type != DP_DS_PORT_TYPE_VGA)
205 return max_dotclk;
206
207 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
208 intel_dp->downstream_ports);
209
210 if (ds_max_dotclk != 0)
211 max_dotclk = min(max_dotclk, ds_max_dotclk);
212
213 return max_dotclk;
214}
215
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000216static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700217intel_dp_mode_valid(struct drm_connector *connector,
218 struct drm_display_mode *mode)
219{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100220 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300221 struct intel_connector *intel_connector = to_intel_connector(connector);
222 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100223 int target_clock = mode->clock;
224 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300225 int max_dotclk;
226
227 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700228
Jani Nikuladd06f902012-10-19 14:51:50 +0300229 if (is_edp(intel_dp) && fixed_mode) {
230 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100231 return MODE_PANEL;
232
Jani Nikuladd06f902012-10-19 14:51:50 +0300233 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100234 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200235
236 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100237 }
238
Ville Syrjälä50fec212015-03-12 17:10:34 +0200239 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300240 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100241
242 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
243 mode_rate = intel_dp_link_required(target_clock, 18);
244
Mika Kahola799487f2016-02-02 15:16:38 +0200245 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200246 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700247
248 if (mode->clock < 10000)
249 return MODE_CLOCK_LOW;
250
Daniel Vetter0af78a22012-05-23 11:30:55 +0200251 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
252 return MODE_H_ILLEGAL;
253
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700254 return MODE_OK;
255}
256
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800257uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700258{
259 int i;
260 uint32_t v = 0;
261
262 if (src_bytes > 4)
263 src_bytes = 4;
264 for (i = 0; i < src_bytes; i++)
265 v |= ((uint32_t) src[i]) << ((3-i) * 8);
266 return v;
267}
268
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000269static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700270{
271 int i;
272 if (dst_bytes > 4)
273 dst_bytes = 4;
274 for (i = 0; i < dst_bytes; i++)
275 dst[i] = src >> ((3-i) * 8);
276}
277
Jani Nikulabf13e812013-09-06 07:40:05 +0300278static void
279intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300280 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300281static void
282intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300283 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300284static void
285intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300286
Ville Syrjälä773538e82014-09-04 14:54:56 +0300287static void pps_lock(struct intel_dp *intel_dp)
288{
289 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
290 struct intel_encoder *encoder = &intel_dig_port->base;
291 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100292 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300293 enum intel_display_power_domain power_domain;
294
295 /*
296 * See vlv_power_sequencer_reset() why we need
297 * a power domain reference here.
298 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100299 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300300 intel_display_power_get(dev_priv, power_domain);
301
302 mutex_lock(&dev_priv->pps_mutex);
303}
304
305static void pps_unlock(struct intel_dp *intel_dp)
306{
307 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
308 struct intel_encoder *encoder = &intel_dig_port->base;
309 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100310 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300311 enum intel_display_power_domain power_domain;
312
313 mutex_unlock(&dev_priv->pps_mutex);
314
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100315 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300316 intel_display_power_put(dev_priv, power_domain);
317}
318
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300319static void
320vlv_power_sequencer_kick(struct intel_dp *intel_dp)
321{
322 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
323 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100324 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300325 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300326 bool pll_enabled, release_cl_override = false;
327 enum dpio_phy phy = DPIO_PHY(pipe);
328 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300329 uint32_t DP;
330
331 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
332 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
333 pipe_name(pipe), port_name(intel_dig_port->port)))
334 return;
335
336 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
337 pipe_name(pipe), port_name(intel_dig_port->port));
338
339 /* Preserve the BIOS-computed detected bit. This is
340 * supposed to be read-only.
341 */
342 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
343 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
344 DP |= DP_PORT_WIDTH(1);
345 DP |= DP_LINK_TRAIN_PAT_1;
346
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100347 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300348 DP |= DP_PIPE_SELECT_CHV(pipe);
349 else if (pipe == PIPE_B)
350 DP |= DP_PIPEB_SELECT;
351
Ville Syrjäläd288f652014-10-28 13:20:22 +0200352 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
353
354 /*
355 * The DPLL for the pipe must be enabled for this to work.
356 * So enable temporarily it if it's not already enabled.
357 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300358 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100359 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300360 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
361
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100362 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000363 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
364 DRM_ERROR("Failed to force on pll for pipe %c!\n",
365 pipe_name(pipe));
366 return;
367 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300368 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200369
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300370 /*
371 * Similar magic as in intel_dp_enable_port().
372 * We _must_ do this port enable + disable trick
373 * to make this power seqeuencer lock onto the port.
374 * Otherwise even VDD force bit won't work.
375 */
376 I915_WRITE(intel_dp->output_reg, DP);
377 POSTING_READ(intel_dp->output_reg);
378
379 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
380 POSTING_READ(intel_dp->output_reg);
381
382 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
383 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200384
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300385 if (!pll_enabled) {
Ville Syrjäläd288f652014-10-28 13:20:22 +0200386 vlv_force_pll_off(dev, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300387
388 if (release_cl_override)
389 chv_phy_powergate_ch(dev_priv, phy, ch, false);
390 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300391}
392
Jani Nikulabf13e812013-09-06 07:40:05 +0300393static enum pipe
394vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
395{
396 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300397 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100398 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300399 struct intel_encoder *encoder;
400 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300401 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300402
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300403 lockdep_assert_held(&dev_priv->pps_mutex);
404
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300405 /* We should never land here with regular DP ports */
406 WARN_ON(!is_edp(intel_dp));
407
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300408 if (intel_dp->pps_pipe != INVALID_PIPE)
409 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300410
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300411 /*
412 * We don't have power sequencer currently.
413 * Pick one that's not used by other ports.
414 */
Jani Nikula19c80542015-12-16 12:48:16 +0200415 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300416 struct intel_dp *tmp;
417
418 if (encoder->type != INTEL_OUTPUT_EDP)
419 continue;
420
421 tmp = enc_to_intel_dp(&encoder->base);
422
423 if (tmp->pps_pipe != INVALID_PIPE)
424 pipes &= ~(1 << tmp->pps_pipe);
425 }
426
427 /*
428 * Didn't find one. This should not happen since there
429 * are two power sequencers and up to two eDP ports.
430 */
431 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300432 pipe = PIPE_A;
433 else
434 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300435
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300436 vlv_steal_power_sequencer(dev, pipe);
437 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300438
439 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
440 pipe_name(intel_dp->pps_pipe),
441 port_name(intel_dig_port->port));
442
443 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300444 intel_dp_init_panel_power_sequencer(dev, intel_dp);
445 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300446
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300447 /*
448 * Even vdd force doesn't work until we've made
449 * the power sequencer lock in on the port.
450 */
451 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300452
453 return intel_dp->pps_pipe;
454}
455
Imre Deak78597992016-06-16 16:37:20 +0300456static int
457bxt_power_sequencer_idx(struct intel_dp *intel_dp)
458{
459 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
460 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100461 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300462
463 lockdep_assert_held(&dev_priv->pps_mutex);
464
465 /* We should never land here with regular DP ports */
466 WARN_ON(!is_edp(intel_dp));
467
468 /*
469 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
470 * mapping needs to be retrieved from VBT, for now just hard-code to
471 * use instance #0 always.
472 */
473 if (!intel_dp->pps_reset)
474 return 0;
475
476 intel_dp->pps_reset = false;
477
478 /*
479 * Only the HW needs to be reprogrammed, the SW state is fixed and
480 * has been setup during connector init.
481 */
482 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
483
484 return 0;
485}
486
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300487typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
488 enum pipe pipe);
489
490static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
491 enum pipe pipe)
492{
Imre Deak44cb7342016-08-10 14:07:29 +0300493 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300494}
495
496static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
497 enum pipe pipe)
498{
Imre Deak44cb7342016-08-10 14:07:29 +0300499 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300500}
501
502static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
503 enum pipe pipe)
504{
505 return true;
506}
507
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300508static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300509vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
510 enum port port,
511 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300512{
Jani Nikulabf13e812013-09-06 07:40:05 +0300513 enum pipe pipe;
514
Jani Nikulabf13e812013-09-06 07:40:05 +0300515 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300516 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300517 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300518
519 if (port_sel != PANEL_PORT_SELECT_VLV(port))
520 continue;
521
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300522 if (!pipe_check(dev_priv, pipe))
523 continue;
524
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300525 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300526 }
527
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300528 return INVALID_PIPE;
529}
530
531static void
532vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
533{
534 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
535 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100536 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300537 enum port port = intel_dig_port->port;
538
539 lockdep_assert_held(&dev_priv->pps_mutex);
540
541 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300542 /* first pick one where the panel is on */
543 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
544 vlv_pipe_has_pp_on);
545 /* didn't find one? pick one where vdd is on */
546 if (intel_dp->pps_pipe == INVALID_PIPE)
547 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
548 vlv_pipe_has_vdd_on);
549 /* didn't find one? pick one with just the correct port */
550 if (intel_dp->pps_pipe == INVALID_PIPE)
551 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
552 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300553
554 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
555 if (intel_dp->pps_pipe == INVALID_PIPE) {
556 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
557 port_name(port));
558 return;
559 }
560
561 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
562 port_name(port), pipe_name(intel_dp->pps_pipe));
563
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300564 intel_dp_init_panel_power_sequencer(dev, intel_dp);
565 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300566}
567
Imre Deak78597992016-06-16 16:37:20 +0300568void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300569{
Chris Wilson91c8a322016-07-05 10:40:23 +0100570 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300571 struct intel_encoder *encoder;
572
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100573 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100574 !IS_BROXTON(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300575 return;
576
577 /*
578 * We can't grab pps_mutex here due to deadlock with power_domain
579 * mutex when power_domain functions are called while holding pps_mutex.
580 * That also means that in order to use pps_pipe the code needs to
581 * hold both a power domain reference and pps_mutex, and the power domain
582 * reference get/put must be done while _not_ holding pps_mutex.
583 * pps_{lock,unlock}() do these steps in the correct order, so one
584 * should use them always.
585 */
586
Jani Nikula19c80542015-12-16 12:48:16 +0200587 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300588 struct intel_dp *intel_dp;
589
590 if (encoder->type != INTEL_OUTPUT_EDP)
591 continue;
592
593 intel_dp = enc_to_intel_dp(&encoder->base);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100594 if (IS_BROXTON(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300595 intel_dp->pps_reset = true;
596 else
597 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300598 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300599}
600
Imre Deak8e8232d2016-06-16 16:37:21 +0300601struct pps_registers {
602 i915_reg_t pp_ctrl;
603 i915_reg_t pp_stat;
604 i915_reg_t pp_on;
605 i915_reg_t pp_off;
606 i915_reg_t pp_div;
607};
608
609static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
610 struct intel_dp *intel_dp,
611 struct pps_registers *regs)
612{
Imre Deak44cb7342016-08-10 14:07:29 +0300613 int pps_idx = 0;
614
Imre Deak8e8232d2016-06-16 16:37:21 +0300615 memset(regs, 0, sizeof(*regs));
616
Imre Deak44cb7342016-08-10 14:07:29 +0300617 if (IS_BROXTON(dev_priv))
618 pps_idx = bxt_power_sequencer_idx(intel_dp);
619 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
620 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300621
Imre Deak44cb7342016-08-10 14:07:29 +0300622 regs->pp_ctrl = PP_CONTROL(pps_idx);
623 regs->pp_stat = PP_STATUS(pps_idx);
624 regs->pp_on = PP_ON_DELAYS(pps_idx);
625 regs->pp_off = PP_OFF_DELAYS(pps_idx);
626 if (!IS_BROXTON(dev_priv))
627 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300628}
629
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200630static i915_reg_t
631_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300632{
Imre Deak8e8232d2016-06-16 16:37:21 +0300633 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300634
Imre Deak8e8232d2016-06-16 16:37:21 +0300635 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
636 &regs);
637
638 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300639}
640
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200641static i915_reg_t
642_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300643{
Imre Deak8e8232d2016-06-16 16:37:21 +0300644 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300645
Imre Deak8e8232d2016-06-16 16:37:21 +0300646 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
647 &regs);
648
649 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300650}
651
Clint Taylor01527b32014-07-07 13:01:46 -0700652/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
653 This function only applicable when panel PM state is not to be tracked */
654static int edp_notify_handler(struct notifier_block *this, unsigned long code,
655 void *unused)
656{
657 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
658 edp_notifier);
659 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100660 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700661
662 if (!is_edp(intel_dp) || code != SYS_RESTART)
663 return 0;
664
Ville Syrjälä773538e82014-09-04 14:54:56 +0300665 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300666
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100667 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300668 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200669 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300670 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300671
Imre Deak44cb7342016-08-10 14:07:29 +0300672 pp_ctrl_reg = PP_CONTROL(pipe);
673 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700674 pp_div = I915_READ(pp_div_reg);
675 pp_div &= PP_REFERENCE_DIVIDER_MASK;
676
677 /* 0x1F write to PP_DIV_REG sets max cycle delay */
678 I915_WRITE(pp_div_reg, pp_div | 0x1F);
679 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
680 msleep(intel_dp->panel_power_cycle_delay);
681 }
682
Ville Syrjälä773538e82014-09-04 14:54:56 +0300683 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300684
Clint Taylor01527b32014-07-07 13:01:46 -0700685 return 0;
686}
687
Daniel Vetter4be73782014-01-17 14:39:48 +0100688static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700689{
Paulo Zanoni30add222012-10-26 19:05:45 -0200690 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100691 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700692
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300693 lockdep_assert_held(&dev_priv->pps_mutex);
694
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100695 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300696 intel_dp->pps_pipe == INVALID_PIPE)
697 return false;
698
Jani Nikulabf13e812013-09-06 07:40:05 +0300699 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700700}
701
Daniel Vetter4be73782014-01-17 14:39:48 +0100702static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700703{
Paulo Zanoni30add222012-10-26 19:05:45 -0200704 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100705 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700706
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300707 lockdep_assert_held(&dev_priv->pps_mutex);
708
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100709 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300710 intel_dp->pps_pipe == INVALID_PIPE)
711 return false;
712
Ville Syrjälä773538e82014-09-04 14:54:56 +0300713 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700714}
715
Keith Packard9b984da2011-09-19 13:54:47 -0700716static void
717intel_dp_check_edp(struct intel_dp *intel_dp)
718{
Paulo Zanoni30add222012-10-26 19:05:45 -0200719 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100720 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700721
Keith Packard9b984da2011-09-19 13:54:47 -0700722 if (!is_edp(intel_dp))
723 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700724
Daniel Vetter4be73782014-01-17 14:39:48 +0100725 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700726 WARN(1, "eDP powered off while attempting aux channel communication.\n");
727 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300728 I915_READ(_pp_stat_reg(intel_dp)),
729 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700730 }
731}
732
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100733static uint32_t
734intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
735{
736 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
737 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100738 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200739 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100740 uint32_t status;
741 bool done;
742
Daniel Vetteref04f002012-12-01 21:03:59 +0100743#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100744 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300745 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300746 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100747 else
Imre Deak713a6b662016-06-28 13:37:33 +0300748 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100749 if (!done)
750 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
751 has_aux_irq);
752#undef C
753
754 return status;
755}
756
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200757static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000758{
759 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200760 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000761
Ville Syrjäläa457f542016-03-02 17:22:17 +0200762 if (index)
763 return 0;
764
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000765 /*
766 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200767 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000768 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200769 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000770}
771
772static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
773{
774 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200775 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000776
777 if (index)
778 return 0;
779
Ville Syrjäläa457f542016-03-02 17:22:17 +0200780 /*
781 * The clock divider is based off the cdclk or PCH rawclk, and would
782 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
783 * divide by 2000 and use that
784 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200785 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200786 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200787 else
788 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000789}
790
791static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300792{
793 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200794 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300795
Ville Syrjäläa457f542016-03-02 17:22:17 +0200796 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300797 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100798 switch (index) {
799 case 0: return 63;
800 case 1: return 72;
801 default: return 0;
802 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300803 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200804
805 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300806}
807
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000808static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
809{
810 /*
811 * SKL doesn't need us to program the AUX clock divider (Hardware will
812 * derive the clock from CDCLK automatically). We still implement the
813 * get_aux_clock_divider vfunc to plug-in into the existing code.
814 */
815 return index ? 0 : 1;
816}
817
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200818static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
819 bool has_aux_irq,
820 int send_bytes,
821 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000822{
823 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100824 struct drm_i915_private *dev_priv =
825 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000826 uint32_t precharge, timeout;
827
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100828 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000829 precharge = 3;
830 else
831 precharge = 5;
832
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100833 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000834 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
835 else
836 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
837
838 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000839 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000840 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000841 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000842 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000843 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000844 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
845 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000846 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000847}
848
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000849static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
850 bool has_aux_irq,
851 int send_bytes,
852 uint32_t unused)
853{
854 return DP_AUX_CH_CTL_SEND_BUSY |
855 DP_AUX_CH_CTL_DONE |
856 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
857 DP_AUX_CH_CTL_TIME_OUT_ERROR |
858 DP_AUX_CH_CTL_TIME_OUT_1600us |
859 DP_AUX_CH_CTL_RECEIVE_ERROR |
860 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200861 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000862 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
863}
864
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700865static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100866intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200867 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700868 uint8_t *recv, int recv_size)
869{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200870 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
871 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100872 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200873 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100874 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100875 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700876 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000877 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100878 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200879 bool vdd;
880
Ville Syrjälä773538e82014-09-04 14:54:56 +0300881 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300882
Ville Syrjälä72c35002014-08-18 22:16:00 +0300883 /*
884 * We will be called with VDD already enabled for dpcd/edid/oui reads.
885 * In such cases we want to leave VDD enabled and it's up to upper layers
886 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
887 * ourselves.
888 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300889 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100890
891 /* dp aux is extremely sensitive to irq latency, hence request the
892 * lowest possible wakeup latency and so prevent the cpu from going into
893 * deep sleep states.
894 */
895 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700896
Keith Packard9b984da2011-09-19 13:54:47 -0700897 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800898
Jesse Barnes11bee432011-08-01 15:02:20 -0700899 /* Try to wait for any previous AUX channel activity */
900 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100901 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700902 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
903 break;
904 msleep(1);
905 }
906
907 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300908 static u32 last_status = -1;
909 const u32 status = I915_READ(ch_ctl);
910
911 if (status != last_status) {
912 WARN(1, "dp_aux_ch not started status 0x%08x\n",
913 status);
914 last_status = status;
915 }
916
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100917 ret = -EBUSY;
918 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100919 }
920
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300921 /* Only 5 data registers! */
922 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
923 ret = -E2BIG;
924 goto out;
925 }
926
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000927 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000928 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
929 has_aux_irq,
930 send_bytes,
931 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000932
Chris Wilsonbc866252013-07-21 16:00:03 +0100933 /* Must try at least 3 times according to DP spec */
934 for (try = 0; try < 5; try++) {
935 /* Load the send data into the aux channel data registers */
936 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +0200937 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800938 intel_dp_pack_aux(send + i,
939 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400940
Chris Wilsonbc866252013-07-21 16:00:03 +0100941 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000942 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100943
Chris Wilsonbc866252013-07-21 16:00:03 +0100944 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400945
Chris Wilsonbc866252013-07-21 16:00:03 +0100946 /* Clear done status and any errors */
947 I915_WRITE(ch_ctl,
948 status |
949 DP_AUX_CH_CTL_DONE |
950 DP_AUX_CH_CTL_TIME_OUT_ERROR |
951 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400952
Todd Previte74ebf292015-04-15 08:38:41 -0700953 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +0100954 continue;
Todd Previte74ebf292015-04-15 08:38:41 -0700955
956 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
957 * 400us delay required for errors and timeouts
958 * Timeout errors from the HW already meet this
959 * requirement so skip to next iteration
960 */
961 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
962 usleep_range(400, 500);
963 continue;
964 }
Chris Wilsonbc866252013-07-21 16:00:03 +0100965 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -0700966 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +0100967 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700968 }
969
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700970 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700971 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100972 ret = -EBUSY;
973 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700974 }
975
Jim Bridee058c942015-05-27 10:21:48 -0700976done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700977 /* Check for timeout or receive error.
978 * Timeouts occur when the sink is not connected
979 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700980 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700981 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100982 ret = -EIO;
983 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700984 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700985
986 /* Timeouts occur when the device isn't connected, so they're
987 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700988 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800989 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100990 ret = -ETIMEDOUT;
991 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700992 }
993
994 /* Unload any bytes sent back from the other side */
995 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
996 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -0800997
998 /*
999 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1000 * We have no idea of what happened so we return -EBUSY so
1001 * drm layer takes care for the necessary retries.
1002 */
1003 if (recv_bytes == 0 || recv_bytes > 20) {
1004 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1005 recv_bytes);
1006 /*
1007 * FIXME: This patch was created on top of a series that
1008 * organize the retries at drm level. There EBUSY should
1009 * also take care for 1ms wait before retrying.
1010 * That aux retries re-org is still needed and after that is
1011 * merged we remove this sleep from here.
1012 */
1013 usleep_range(1000, 1500);
1014 ret = -EBUSY;
1015 goto out;
1016 }
1017
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001018 if (recv_bytes > recv_size)
1019 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001020
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001021 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001022 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001023 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001024
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001025 ret = recv_bytes;
1026out:
1027 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1028
Jani Nikula884f19e2014-03-14 16:51:14 +02001029 if (vdd)
1030 edp_panel_vdd_off(intel_dp, false);
1031
Ville Syrjälä773538e82014-09-04 14:54:56 +03001032 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001033
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001034 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001035}
1036
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001037#define BARE_ADDRESS_SIZE 3
1038#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001039static ssize_t
1040intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001041{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001042 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1043 uint8_t txbuf[20], rxbuf[20];
1044 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001045 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001046
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001047 txbuf[0] = (msg->request << 4) |
1048 ((msg->address >> 16) & 0xf);
1049 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001050 txbuf[2] = msg->address & 0xff;
1051 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001052
Jani Nikula9d1a1032014-03-14 16:51:15 +02001053 switch (msg->request & ~DP_AUX_I2C_MOT) {
1054 case DP_AUX_NATIVE_WRITE:
1055 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001056 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001057 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001058 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001059
Jani Nikula9d1a1032014-03-14 16:51:15 +02001060 if (WARN_ON(txsize > 20))
1061 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001062
Ville Syrjälädd788092016-07-28 17:55:04 +03001063 WARN_ON(!msg->buffer != !msg->size);
1064
Imre Deakd81a67c2016-01-29 14:52:26 +02001065 if (msg->buffer)
1066 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001067
Jani Nikula9d1a1032014-03-14 16:51:15 +02001068 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1069 if (ret > 0) {
1070 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001071
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001072 if (ret > 1) {
1073 /* Number of bytes written in a short write. */
1074 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1075 } else {
1076 /* Return payload size. */
1077 ret = msg->size;
1078 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001079 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001080 break;
1081
1082 case DP_AUX_NATIVE_READ:
1083 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001084 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001085 rxsize = msg->size + 1;
1086
1087 if (WARN_ON(rxsize > 20))
1088 return -E2BIG;
1089
1090 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1091 if (ret > 0) {
1092 msg->reply = rxbuf[0] >> 4;
1093 /*
1094 * Assume happy day, and copy the data. The caller is
1095 * expected to check msg->reply before touching it.
1096 *
1097 * Return payload size.
1098 */
1099 ret--;
1100 memcpy(msg->buffer, rxbuf + 1, ret);
1101 }
1102 break;
1103
1104 default:
1105 ret = -EINVAL;
1106 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001107 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001108
Jani Nikula9d1a1032014-03-14 16:51:15 +02001109 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001110}
1111
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001112static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1113 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001114{
1115 switch (port) {
1116 case PORT_B:
1117 case PORT_C:
1118 case PORT_D:
1119 return DP_AUX_CH_CTL(port);
1120 default:
1121 MISSING_CASE(port);
1122 return DP_AUX_CH_CTL(PORT_B);
1123 }
1124}
1125
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001126static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1127 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001128{
1129 switch (port) {
1130 case PORT_B:
1131 case PORT_C:
1132 case PORT_D:
1133 return DP_AUX_CH_DATA(port, index);
1134 default:
1135 MISSING_CASE(port);
1136 return DP_AUX_CH_DATA(PORT_B, index);
1137 }
1138}
1139
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001140static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1141 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001142{
1143 switch (port) {
1144 case PORT_A:
1145 return DP_AUX_CH_CTL(port);
1146 case PORT_B:
1147 case PORT_C:
1148 case PORT_D:
1149 return PCH_DP_AUX_CH_CTL(port);
1150 default:
1151 MISSING_CASE(port);
1152 return DP_AUX_CH_CTL(PORT_A);
1153 }
1154}
1155
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001156static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1157 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001158{
1159 switch (port) {
1160 case PORT_A:
1161 return DP_AUX_CH_DATA(port, index);
1162 case PORT_B:
1163 case PORT_C:
1164 case PORT_D:
1165 return PCH_DP_AUX_CH_DATA(port, index);
1166 default:
1167 MISSING_CASE(port);
1168 return DP_AUX_CH_DATA(PORT_A, index);
1169 }
1170}
1171
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001172/*
1173 * On SKL we don't have Aux for port E so we rely
1174 * on VBT to set a proper alternate aux channel.
1175 */
1176static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
1177{
1178 const struct ddi_vbt_port_info *info =
1179 &dev_priv->vbt.ddi_port_info[PORT_E];
1180
1181 switch (info->alternate_aux_channel) {
1182 case DP_AUX_A:
1183 return PORT_A;
1184 case DP_AUX_B:
1185 return PORT_B;
1186 case DP_AUX_C:
1187 return PORT_C;
1188 case DP_AUX_D:
1189 return PORT_D;
1190 default:
1191 MISSING_CASE(info->alternate_aux_channel);
1192 return PORT_A;
1193 }
1194}
1195
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001196static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1197 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001198{
1199 if (port == PORT_E)
1200 port = skl_porte_aux_port(dev_priv);
1201
1202 switch (port) {
1203 case PORT_A:
1204 case PORT_B:
1205 case PORT_C:
1206 case PORT_D:
1207 return DP_AUX_CH_CTL(port);
1208 default:
1209 MISSING_CASE(port);
1210 return DP_AUX_CH_CTL(PORT_A);
1211 }
1212}
1213
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001214static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1215 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001216{
1217 if (port == PORT_E)
1218 port = skl_porte_aux_port(dev_priv);
1219
1220 switch (port) {
1221 case PORT_A:
1222 case PORT_B:
1223 case PORT_C:
1224 case PORT_D:
1225 return DP_AUX_CH_DATA(port, index);
1226 default:
1227 MISSING_CASE(port);
1228 return DP_AUX_CH_DATA(PORT_A, index);
1229 }
1230}
1231
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001232static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1233 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001234{
1235 if (INTEL_INFO(dev_priv)->gen >= 9)
1236 return skl_aux_ctl_reg(dev_priv, port);
1237 else if (HAS_PCH_SPLIT(dev_priv))
1238 return ilk_aux_ctl_reg(dev_priv, port);
1239 else
1240 return g4x_aux_ctl_reg(dev_priv, port);
1241}
1242
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001243static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1244 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001245{
1246 if (INTEL_INFO(dev_priv)->gen >= 9)
1247 return skl_aux_data_reg(dev_priv, port, index);
1248 else if (HAS_PCH_SPLIT(dev_priv))
1249 return ilk_aux_data_reg(dev_priv, port, index);
1250 else
1251 return g4x_aux_data_reg(dev_priv, port, index);
1252}
1253
1254static void intel_aux_reg_init(struct intel_dp *intel_dp)
1255{
1256 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1257 enum port port = dp_to_dig_port(intel_dp)->port;
1258 int i;
1259
1260 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1261 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1262 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1263}
1264
Jani Nikula9d1a1032014-03-14 16:51:15 +02001265static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001266intel_dp_aux_fini(struct intel_dp *intel_dp)
1267{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001268 kfree(intel_dp->aux.name);
1269}
1270
Chris Wilson7a418e32016-06-24 14:00:14 +01001271static void
Mika Kaholab6339582016-09-09 14:10:52 +03001272intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001273{
Jani Nikula33ad6622014-03-14 16:51:16 +02001274 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1275 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001276
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001277 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001278 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001279
Chris Wilson7a418e32016-06-24 14:00:14 +01001280 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001281 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001282 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001283}
1284
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301285static int
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001286intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301287{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001288 if (intel_dp->num_sink_rates) {
1289 *sink_rates = intel_dp->sink_rates;
1290 return intel_dp->num_sink_rates;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301291 }
Ville Syrjälä12f6a2e2015-03-12 17:10:30 +02001292
1293 *sink_rates = default_rates;
1294
1295 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
Sonika Jindalfc0f8e22015-03-05 10:03:58 +05301296}
1297
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001298bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301299{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001300 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001301 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001302
Navare, Manasi D577c5432016-09-27 16:36:53 -07001303 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1304 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301305 return true;
1306 else
1307 return false;
1308}
1309
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301310static int
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001311intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301312{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001313 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001314 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301315 int size;
1316
Navare, Manasi D577c5432016-09-27 16:36:53 -07001317 if (IS_BROXTON(dev_priv)) {
Sonika Jindal64987fc2015-05-26 17:50:13 +05301318 *source_rates = bxt_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301319 size = ARRAY_SIZE(bxt_rates);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001320 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Sonika Jindal637a9c62015-05-07 09:52:08 +05301321 *source_rates = skl_rates;
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301322 size = ARRAY_SIZE(skl_rates);
1323 } else {
1324 *source_rates = default_rates;
1325 size = ARRAY_SIZE(default_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301326 }
Ville Syrjälä636280b2015-03-12 17:10:29 +02001327
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301328 /* This depends on the fact that 5.4 is last value in the array */
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001329 if (!intel_dp_source_supports_hbr2(intel_dp))
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301330 size--;
Ville Syrjälä636280b2015-03-12 17:10:29 +02001331
Thulasimani,Sivakumaraf7080f2015-08-18 11:07:59 +05301332 return size;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301333}
1334
Daniel Vetter0e503382014-07-04 11:26:04 -03001335static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001336intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001337 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001338{
1339 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001340 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001341 const struct dp_link_dpll *divisor = NULL;
1342 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001343
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001344 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001345 divisor = gen4_dpll;
1346 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001347 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001348 divisor = pch_dpll;
1349 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001350 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001351 divisor = chv_dpll;
1352 count = ARRAY_SIZE(chv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001353 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001354 divisor = vlv_dpll;
1355 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001356 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001357
1358 if (divisor && count) {
1359 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001360 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001361 pipe_config->dpll = divisor[i].dpll;
1362 pipe_config->clock_set = true;
1363 break;
1364 }
1365 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001366 }
1367}
1368
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001369static int intersect_rates(const int *source_rates, int source_len,
1370 const int *sink_rates, int sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001371 int *common_rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301372{
1373 int i = 0, j = 0, k = 0;
1374
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301375 while (i < source_len && j < sink_len) {
1376 if (source_rates[i] == sink_rates[j]) {
Ville Syrjäläe6bda3e2015-03-12 17:10:37 +02001377 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
1378 return k;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001379 common_rates[k] = source_rates[i];
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301380 ++k;
1381 ++i;
1382 ++j;
1383 } else if (source_rates[i] < sink_rates[j]) {
1384 ++i;
1385 } else {
1386 ++j;
1387 }
1388 }
1389 return k;
1390}
1391
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001392static int intel_dp_common_rates(struct intel_dp *intel_dp,
1393 int *common_rates)
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001394{
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001395 const int *source_rates, *sink_rates;
1396 int source_len, sink_len;
1397
1398 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001399 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001400
1401 return intersect_rates(source_rates, source_len,
1402 sink_rates, sink_len,
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001403 common_rates);
Ville Syrjälä2ecae762015-03-12 17:10:33 +02001404}
1405
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001406static void snprintf_int_array(char *str, size_t len,
1407 const int *array, int nelem)
1408{
1409 int i;
1410
1411 str[0] = '\0';
1412
1413 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001414 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001415 if (r >= len)
1416 return;
1417 str += r;
1418 len -= r;
1419 }
1420}
1421
1422static void intel_dp_print_rates(struct intel_dp *intel_dp)
1423{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001424 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001425 int source_len, sink_len, common_len;
1426 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001427 char str[128]; /* FIXME: too big for stack? */
1428
1429 if ((drm_debug & DRM_UT_KMS) == 0)
1430 return;
1431
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001432 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001433 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1434 DRM_DEBUG_KMS("source rates: %s\n", str);
1435
1436 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1437 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1438 DRM_DEBUG_KMS("sink rates: %s\n", str);
1439
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001440 common_len = intel_dp_common_rates(intel_dp, common_rates);
1441 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1442 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001443}
1444
Mika Kahola0e390a32016-09-09 14:10:53 +03001445static void intel_dp_print_hw_revision(struct intel_dp *intel_dp)
1446{
1447 uint8_t rev;
1448 int len;
1449
1450 if ((drm_debug & DRM_UT_KMS) == 0)
1451 return;
1452
1453 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1454 DP_DWN_STRM_PORT_PRESENT))
1455 return;
1456
1457 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_HW_REV, &rev, 1);
1458 if (len < 0)
1459 return;
1460
1461 DRM_DEBUG_KMS("sink hw revision: %d.%d\n", (rev & 0xf0) >> 4, rev & 0xf);
1462}
1463
Mika Kahola1a2724f2016-09-09 14:10:54 +03001464static void intel_dp_print_sw_revision(struct intel_dp *intel_dp)
1465{
1466 uint8_t rev[2];
1467 int len;
1468
1469 if ((drm_debug & DRM_UT_KMS) == 0)
1470 return;
1471
1472 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
1473 DP_DWN_STRM_PORT_PRESENT))
1474 return;
1475
1476 len = drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_SW_REV, &rev, 2);
1477 if (len < 0)
1478 return;
1479
1480 DRM_DEBUG_KMS("sink sw revision: %d.%d\n", rev[0], rev[1]);
1481}
1482
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001483static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301484{
1485 int i = 0;
1486
1487 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1488 if (find == rates[i])
1489 break;
1490
1491 return i;
1492}
1493
Ville Syrjälä50fec212015-03-12 17:10:34 +02001494int
1495intel_dp_max_link_rate(struct intel_dp *intel_dp)
1496{
1497 int rates[DP_MAX_SUPPORTED_RATES] = {};
1498 int len;
1499
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001500 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001501 if (WARN_ON(len <= 0))
1502 return 162000;
1503
Ville Syrjälä1354f732016-07-28 17:50:45 +03001504 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001505}
1506
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001507int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1508{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001509 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001510}
1511
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001512void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1513 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001514{
1515 if (intel_dp->num_sink_rates) {
1516 *link_bw = 0;
1517 *rate_select =
1518 intel_dp_rate_select(intel_dp, port_clock);
1519 } else {
1520 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1521 *rate_select = 0;
1522 }
1523}
1524
Jani Nikulaf580bea2016-09-15 16:28:52 +03001525static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1526 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001527{
1528 int bpp, bpc;
1529
1530 bpp = pipe_config->pipe_bpp;
1531 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1532
1533 if (bpc > 0)
1534 bpp = min(bpp, 3*bpc);
1535
1536 return bpp;
1537}
1538
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001539bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001540intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001541 struct intel_crtc_state *pipe_config,
1542 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001543{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001544 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001545 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001546 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001547 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001548 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001549 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001550 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001551 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001552 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001553 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001554 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001555 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301556 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001557 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001558 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001559 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1560 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001561 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301562
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001563 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301564
1565 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001566 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301567
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001568 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001569
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001570 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001571 pipe_config->has_pch_encoder = true;
1572
Vandana Kannanf769cd22014-08-05 07:51:22 -07001573 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001574 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001575
Jani Nikuladd06f902012-10-19 14:51:50 +03001576 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1577 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1578 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001579
1580 if (INTEL_INFO(dev)->gen >= 9) {
1581 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001582 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001583 if (ret)
1584 return ret;
1585 }
1586
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001587 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001588 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1589 intel_connector->panel.fitting_mode);
1590 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001591 intel_pch_panel_fitting(intel_crtc, pipe_config,
1592 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001593 }
1594
Daniel Vettercb1793c2012-06-04 18:39:21 +02001595 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001596 return false;
1597
Daniel Vetter083f9562012-04-20 20:23:49 +02001598 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301599 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001600 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001601 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001602
Daniel Vetter36008362013-03-27 00:44:59 +01001603 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1604 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001605 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001606 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301607
1608 /* Get bpp from vbt only for panels that dont have bpp in edid */
1609 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001610 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001611 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001612 dev_priv->vbt.edp.bpp);
1613 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001614 }
1615
Jani Nikula344c5bb2014-09-09 11:25:13 +03001616 /*
1617 * Use the maximum clock and number of lanes the eDP panel
1618 * advertizes being capable of. The panels are generally
1619 * designed to support only a single clock and lane
1620 * configuration, and typically these values correspond to the
1621 * native resolution of the panel.
1622 */
1623 min_lane_count = max_lane_count;
1624 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001625 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001626
Daniel Vetter36008362013-03-27 00:44:59 +01001627 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001628 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1629 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001630
Dave Airliec6930992014-07-14 11:04:39 +10001631 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301632 for (lane_count = min_lane_count;
1633 lane_count <= max_lane_count;
1634 lane_count <<= 1) {
1635
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001636 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001637 link_avail = intel_dp_max_data_rate(link_clock,
1638 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001639
Daniel Vetter36008362013-03-27 00:44:59 +01001640 if (mode_rate <= link_avail) {
1641 goto found;
1642 }
1643 }
1644 }
1645 }
1646
1647 return false;
1648
1649found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001650 if (intel_dp->color_range_auto) {
1651 /*
1652 * See:
1653 * CEA-861-E - 5.1 Default Encoding Parameters
1654 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1655 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001656 pipe_config->limited_color_range =
1657 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1658 } else {
1659 pipe_config->limited_color_range =
1660 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001661 }
1662
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001663 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301664
Daniel Vetter657445f2013-05-04 10:09:18 +02001665 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001666 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001667
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001668 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1669 &link_bw, &rate_select);
1670
1671 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1672 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001673 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001674 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1675 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001676
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001677 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001678 adjusted_mode->crtc_clock,
1679 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001680 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001681
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301682 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301683 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001684 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301685 intel_link_compute_m_n(bpp, lane_count,
1686 intel_connector->panel.downclock_mode->clock,
1687 pipe_config->port_clock,
1688 &pipe_config->dp_m2_n2);
1689 }
1690
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001691 /*
1692 * DPLL0 VCO may need to be adjusted to get the correct
1693 * clock for eDP. This will affect cdclk as well.
1694 */
1695 if (is_edp(intel_dp) &&
1696 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1697 int vco;
1698
1699 switch (pipe_config->port_clock / 2) {
1700 case 108000:
1701 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001702 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001703 break;
1704 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001705 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001706 break;
1707 }
1708
1709 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1710 }
1711
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001712 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001713 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001714
Daniel Vetter36008362013-03-27 00:44:59 +01001715 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001716}
1717
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001718void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001719 int link_rate, uint8_t lane_count,
1720 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001721{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001722 intel_dp->link_rate = link_rate;
1723 intel_dp->lane_count = lane_count;
1724 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001725}
1726
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001727static void intel_dp_prepare(struct intel_encoder *encoder,
1728 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001729{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001730 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001731 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001732 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001733 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001734 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001735 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001736
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001737 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1738 pipe_config->lane_count,
1739 intel_crtc_has_type(pipe_config,
1740 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001741
Keith Packard417e8222011-11-01 19:54:11 -07001742 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001743 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001744 *
1745 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001746 * SNB CPU
1747 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001748 * CPT PCH
1749 *
1750 * IBX PCH and CPU are the same for almost everything,
1751 * except that the CPU DP PLL is configured in this
1752 * register
1753 *
1754 * CPT PCH is quite different, having many bits moved
1755 * to the TRANS_DP_CTL register instead. That
1756 * configuration happens (oddly) in ironlake_pch_enable
1757 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001758
Keith Packard417e8222011-11-01 19:54:11 -07001759 /* Preserve the BIOS-computed detected bit. This is
1760 * supposed to be read-only.
1761 */
1762 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001763
Keith Packard417e8222011-11-01 19:54:11 -07001764 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001765 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001766 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001767
Keith Packard417e8222011-11-01 19:54:11 -07001768 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001769
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001770 if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001771 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1772 intel_dp->DP |= DP_SYNC_HS_HIGH;
1773 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1774 intel_dp->DP |= DP_SYNC_VS_HIGH;
1775 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1776
Jani Nikula6aba5b62013-10-04 15:08:10 +03001777 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001778 intel_dp->DP |= DP_ENHANCED_FRAMING;
1779
Daniel Vetter7c62a162013-06-01 17:16:20 +02001780 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001781 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001782 u32 trans_dp;
1783
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001784 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001785
1786 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1787 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1788 trans_dp |= TRANS_DP_ENH_FRAMING;
1789 else
1790 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1791 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001792 } else {
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001793 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev) &&
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001794 !IS_CHERRYVIEW(dev_priv) &&
1795 pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001796 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001797
1798 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1799 intel_dp->DP |= DP_SYNC_HS_HIGH;
1800 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1801 intel_dp->DP |= DP_SYNC_VS_HIGH;
1802 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1803
Jani Nikula6aba5b62013-10-04 15:08:10 +03001804 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001805 intel_dp->DP |= DP_ENHANCED_FRAMING;
1806
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001807 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001808 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001809 else if (crtc->pipe == PIPE_B)
1810 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001811 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001812}
1813
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001814#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1815#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001816
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001817#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1818#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001819
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001820#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1821#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001822
Imre Deakde9c1b62016-06-16 20:01:46 +03001823static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1824 struct intel_dp *intel_dp);
1825
Daniel Vetter4be73782014-01-17 14:39:48 +01001826static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001827 u32 mask,
1828 u32 value)
1829{
Paulo Zanoni30add222012-10-26 19:05:45 -02001830 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001831 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001832 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001833
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001834 lockdep_assert_held(&dev_priv->pps_mutex);
1835
Imre Deakde9c1b62016-06-16 20:01:46 +03001836 intel_pps_verify_state(dev_priv, intel_dp);
1837
Jani Nikulabf13e812013-09-06 07:40:05 +03001838 pp_stat_reg = _pp_stat_reg(intel_dp);
1839 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001840
1841 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001842 mask, value,
1843 I915_READ(pp_stat_reg),
1844 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001845
Chris Wilson9036ff02016-06-30 15:33:09 +01001846 if (intel_wait_for_register(dev_priv,
1847 pp_stat_reg, mask, value,
1848 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001849 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001850 I915_READ(pp_stat_reg),
1851 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001852
1853 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001854}
1855
Daniel Vetter4be73782014-01-17 14:39:48 +01001856static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001857{
1858 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001859 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001860}
1861
Daniel Vetter4be73782014-01-17 14:39:48 +01001862static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001863{
Keith Packardbd943152011-09-18 23:09:52 -07001864 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001865 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001866}
Keith Packardbd943152011-09-18 23:09:52 -07001867
Daniel Vetter4be73782014-01-17 14:39:48 +01001868static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001869{
Abhay Kumard28d4732016-01-22 17:39:04 -08001870 ktime_t panel_power_on_time;
1871 s64 panel_power_off_duration;
1872
Keith Packard99ea7122011-11-01 19:57:50 -07001873 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001874
Abhay Kumard28d4732016-01-22 17:39:04 -08001875 /* take the difference of currrent time and panel power off time
1876 * and then make panel wait for t11_t12 if needed. */
1877 panel_power_on_time = ktime_get_boottime();
1878 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1879
Paulo Zanonidce56b32013-12-19 14:29:40 -02001880 /* When we disable the VDD override bit last we have to do the manual
1881 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001882 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1883 wait_remaining_ms_from_jiffies(jiffies,
1884 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001885
Daniel Vetter4be73782014-01-17 14:39:48 +01001886 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001887}
Keith Packardbd943152011-09-18 23:09:52 -07001888
Daniel Vetter4be73782014-01-17 14:39:48 +01001889static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001890{
1891 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1892 intel_dp->backlight_on_delay);
1893}
1894
Daniel Vetter4be73782014-01-17 14:39:48 +01001895static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001896{
1897 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1898 intel_dp->backlight_off_delay);
1899}
Keith Packard99ea7122011-11-01 19:57:50 -07001900
Keith Packard832dd3c2011-11-01 19:34:06 -07001901/* Read the current pp_control value, unlocking the register if it
1902 * is locked
1903 */
1904
Jesse Barnes453c5422013-03-28 09:55:41 -07001905static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001906{
Jesse Barnes453c5422013-03-28 09:55:41 -07001907 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001908 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001909 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001910
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001911 lockdep_assert_held(&dev_priv->pps_mutex);
1912
Jani Nikulabf13e812013-09-06 07:40:05 +03001913 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001914 if (WARN_ON(!HAS_DDI(dev_priv) &&
1915 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301916 control &= ~PANEL_UNLOCK_MASK;
1917 control |= PANEL_UNLOCK_REGS;
1918 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001919 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001920}
1921
Ville Syrjälä951468f2014-09-04 14:55:31 +03001922/*
1923 * Must be paired with edp_panel_vdd_off().
1924 * Must hold pps_mutex around the whole on/off sequence.
1925 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1926 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001927static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001928{
Paulo Zanoni30add222012-10-26 19:05:45 -02001929 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001930 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1931 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001932 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001933 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001934 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001935 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001936 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001937
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001938 lockdep_assert_held(&dev_priv->pps_mutex);
1939
Keith Packard97af61f572011-09-28 16:23:51 -07001940 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001941 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001942
Egbert Eich2c623c12014-11-25 12:54:57 +01001943 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001944 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001945
Daniel Vetter4be73782014-01-17 14:39:48 +01001946 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001947 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001948
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001949 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001950 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001951
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001952 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1953 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001954
Daniel Vetter4be73782014-01-17 14:39:48 +01001955 if (!edp_have_panel_power(intel_dp))
1956 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001957
Jesse Barnes453c5422013-03-28 09:55:41 -07001958 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001959 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001960
Jani Nikulabf13e812013-09-06 07:40:05 +03001961 pp_stat_reg = _pp_stat_reg(intel_dp);
1962 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001963
1964 I915_WRITE(pp_ctrl_reg, pp);
1965 POSTING_READ(pp_ctrl_reg);
1966 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1967 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001968 /*
1969 * If the panel wasn't on, delay before accessing aux channel
1970 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001971 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001972 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1973 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001974 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001975 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001976
1977 return need_to_disable;
1978}
1979
Ville Syrjälä951468f2014-09-04 14:55:31 +03001980/*
1981 * Must be paired with intel_edp_panel_vdd_off() or
1982 * intel_edp_panel_off().
1983 * Nested calls to these functions are not allowed since
1984 * we drop the lock. Caller must use some higher level
1985 * locking to prevent nested calls from other threads.
1986 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001987void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001988{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001989 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001990
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001991 if (!is_edp(intel_dp))
1992 return;
1993
Ville Syrjälä773538e82014-09-04 14:54:56 +03001994 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001995 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001996 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001997
Rob Clarke2c719b2014-12-15 13:56:32 -05001998 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001999 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002000}
2001
Daniel Vetter4be73782014-01-17 14:39:48 +01002002static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002003{
Paulo Zanoni30add222012-10-26 19:05:45 -02002004 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002005 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002006 struct intel_digital_port *intel_dig_port =
2007 dp_to_dig_port(intel_dp);
2008 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2009 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002010 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002011 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002012
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002013 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002014
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002015 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002016
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002017 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002018 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002019
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002020 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2021 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002022
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002023 pp = ironlake_get_pp_control(intel_dp);
2024 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002025
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002026 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2027 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002028
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002029 I915_WRITE(pp_ctrl_reg, pp);
2030 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002031
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002032 /* Make sure sequencer is idle before allowing subsequent activity */
2033 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2034 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002035
Imre Deak5a162e22016-08-10 14:07:30 +03002036 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002037 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002038
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002039 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002040 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002041}
2042
Daniel Vetter4be73782014-01-17 14:39:48 +01002043static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002044{
2045 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2046 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002047
Ville Syrjälä773538e82014-09-04 14:54:56 +03002048 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002049 if (!intel_dp->want_panel_vdd)
2050 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002051 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002052}
2053
Imre Deakaba86892014-07-30 15:57:31 +03002054static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2055{
2056 unsigned long delay;
2057
2058 /*
2059 * Queue the timer to fire a long time from now (relative to the power
2060 * down delay) to keep the panel power up across a sequence of
2061 * operations.
2062 */
2063 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2064 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2065}
2066
Ville Syrjälä951468f2014-09-04 14:55:31 +03002067/*
2068 * Must be paired with edp_panel_vdd_on().
2069 * Must hold pps_mutex around the whole on/off sequence.
2070 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2071 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002072static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002073{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002074 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002075
2076 lockdep_assert_held(&dev_priv->pps_mutex);
2077
Keith Packard97af61f572011-09-28 16:23:51 -07002078 if (!is_edp(intel_dp))
2079 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002080
Rob Clarke2c719b2014-12-15 13:56:32 -05002081 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002082 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002083
Keith Packardbd943152011-09-18 23:09:52 -07002084 intel_dp->want_panel_vdd = false;
2085
Imre Deakaba86892014-07-30 15:57:31 +03002086 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002087 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002088 else
2089 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002090}
2091
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002092static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002093{
Paulo Zanoni30add222012-10-26 19:05:45 -02002094 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002095 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002096 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002097 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002098
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002099 lockdep_assert_held(&dev_priv->pps_mutex);
2100
Keith Packard97af61f572011-09-28 16:23:51 -07002101 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002102 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002103
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002104 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2105 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002106
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002107 if (WARN(edp_have_panel_power(intel_dp),
2108 "eDP port %c panel power already on\n",
2109 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002110 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002111
Daniel Vetter4be73782014-01-17 14:39:48 +01002112 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002113
Jani Nikulabf13e812013-09-06 07:40:05 +03002114 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002115 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07002116 if (IS_GEN5(dev)) {
2117 /* ILK workaround: disable reset around power sequence */
2118 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002119 I915_WRITE(pp_ctrl_reg, pp);
2120 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002121 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002122
Imre Deak5a162e22016-08-10 14:07:30 +03002123 pp |= PANEL_POWER_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07002124 if (!IS_GEN5(dev))
2125 pp |= PANEL_POWER_RESET;
2126
Jesse Barnes453c5422013-03-28 09:55:41 -07002127 I915_WRITE(pp_ctrl_reg, pp);
2128 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002129
Daniel Vetter4be73782014-01-17 14:39:48 +01002130 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002131 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002132
Keith Packard05ce1a42011-09-29 16:33:01 -07002133 if (IS_GEN5(dev)) {
2134 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002135 I915_WRITE(pp_ctrl_reg, pp);
2136 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002137 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002138}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002139
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002140void intel_edp_panel_on(struct intel_dp *intel_dp)
2141{
2142 if (!is_edp(intel_dp))
2143 return;
2144
2145 pps_lock(intel_dp);
2146 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002147 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002148}
2149
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002150
2151static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002152{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002153 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2154 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002155 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002156 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002157 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002158 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002159 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002160
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002161 lockdep_assert_held(&dev_priv->pps_mutex);
2162
Keith Packard97af61f572011-09-28 16:23:51 -07002163 if (!is_edp(intel_dp))
2164 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002165
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002166 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2167 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002168
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002169 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2170 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002171
Jesse Barnes453c5422013-03-28 09:55:41 -07002172 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002173 /* We need to switch off panel power _and_ force vdd, for otherwise some
2174 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002175 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002176 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002177
Jani Nikulabf13e812013-09-06 07:40:05 +03002178 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002179
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002180 intel_dp->want_panel_vdd = false;
2181
Jesse Barnes453c5422013-03-28 09:55:41 -07002182 I915_WRITE(pp_ctrl_reg, pp);
2183 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002184
Abhay Kumard28d4732016-01-22 17:39:04 -08002185 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002186 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002187
2188 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002189 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002190 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002191}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002192
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002193void intel_edp_panel_off(struct intel_dp *intel_dp)
2194{
2195 if (!is_edp(intel_dp))
2196 return;
2197
2198 pps_lock(intel_dp);
2199 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002200 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002201}
2202
Jani Nikula1250d102014-08-12 17:11:39 +03002203/* Enable backlight in the panel power control. */
2204static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002205{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002206 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2207 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002208 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002209 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002210 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002211
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002212 /*
2213 * If we enable the backlight right away following a panel power
2214 * on, we may see slight flicker as the panel syncs with the eDP
2215 * link. So delay a bit to make sure the image is solid before
2216 * allowing it to appear.
2217 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002218 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002219
Ville Syrjälä773538e82014-09-04 14:54:56 +03002220 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002221
Jesse Barnes453c5422013-03-28 09:55:41 -07002222 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002223 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002224
Jani Nikulabf13e812013-09-06 07:40:05 +03002225 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002226
2227 I915_WRITE(pp_ctrl_reg, pp);
2228 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002229
Ville Syrjälä773538e82014-09-04 14:54:56 +03002230 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002231}
2232
Jani Nikula1250d102014-08-12 17:11:39 +03002233/* Enable backlight PWM and backlight PP control. */
2234void intel_edp_backlight_on(struct intel_dp *intel_dp)
2235{
2236 if (!is_edp(intel_dp))
2237 return;
2238
2239 DRM_DEBUG_KMS("\n");
2240
2241 intel_panel_enable_backlight(intel_dp->attached_connector);
2242 _intel_edp_backlight_on(intel_dp);
2243}
2244
2245/* Disable backlight in the panel power control. */
2246static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002247{
Paulo Zanoni30add222012-10-26 19:05:45 -02002248 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002249 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002250 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002251 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002252
Keith Packardf01eca22011-09-28 16:48:10 -07002253 if (!is_edp(intel_dp))
2254 return;
2255
Ville Syrjälä773538e82014-09-04 14:54:56 +03002256 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002257
Jesse Barnes453c5422013-03-28 09:55:41 -07002258 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002259 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002260
Jani Nikulabf13e812013-09-06 07:40:05 +03002261 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002262
2263 I915_WRITE(pp_ctrl_reg, pp);
2264 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002265
Ville Syrjälä773538e82014-09-04 14:54:56 +03002266 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002267
Paulo Zanonidce56b32013-12-19 14:29:40 -02002268 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002269 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002270}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002271
Jani Nikula1250d102014-08-12 17:11:39 +03002272/* Disable backlight PP control and backlight PWM. */
2273void intel_edp_backlight_off(struct intel_dp *intel_dp)
2274{
2275 if (!is_edp(intel_dp))
2276 return;
2277
2278 DRM_DEBUG_KMS("\n");
2279
2280 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002281 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002282}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002283
Jani Nikula73580fb72014-08-12 17:11:41 +03002284/*
2285 * Hook for controlling the panel power control backlight through the bl_power
2286 * sysfs attribute. Take care to handle multiple calls.
2287 */
2288static void intel_edp_backlight_power(struct intel_connector *connector,
2289 bool enable)
2290{
2291 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002292 bool is_enabled;
2293
Ville Syrjälä773538e82014-09-04 14:54:56 +03002294 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002295 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002296 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002297
2298 if (is_enabled == enable)
2299 return;
2300
Jani Nikula23ba9372014-08-27 14:08:43 +03002301 DRM_DEBUG_KMS("panel power control backlight %s\n",
2302 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002303
2304 if (enable)
2305 _intel_edp_backlight_on(intel_dp);
2306 else
2307 _intel_edp_backlight_off(intel_dp);
2308}
2309
Ville Syrjälä64e10772015-10-29 21:26:01 +02002310static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2311{
2312 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2313 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2314 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2315
2316 I915_STATE_WARN(cur_state != state,
2317 "DP port %c state assertion failure (expected %s, current %s)\n",
2318 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002319 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002320}
2321#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2322
2323static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2324{
2325 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2326
2327 I915_STATE_WARN(cur_state != state,
2328 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002329 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002330}
2331#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2332#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2333
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002334static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2335 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002336{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002337 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002338 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002339
Ville Syrjälä64e10772015-10-29 21:26:01 +02002340 assert_pipe_disabled(dev_priv, crtc->pipe);
2341 assert_dp_port_disabled(intel_dp);
2342 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002343
Ville Syrjäläabfce942015-10-29 21:26:03 +02002344 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002345 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002346
2347 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2348
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002349 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002350 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2351 else
2352 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2353
2354 I915_WRITE(DP_A, intel_dp->DP);
2355 POSTING_READ(DP_A);
2356 udelay(500);
2357
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002358 /*
2359 * [DevILK] Work around required when enabling DP PLL
2360 * while a pipe is enabled going to FDI:
2361 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2362 * 2. Program DP PLL enable
2363 */
2364 if (IS_GEN5(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +01002365 intel_wait_for_vblank_if_active(&dev_priv->drm, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002366
Daniel Vetter07679352012-09-06 22:15:42 +02002367 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002368
Daniel Vetter07679352012-09-06 22:15:42 +02002369 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002370 POSTING_READ(DP_A);
2371 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002372}
2373
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002374static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002375{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002376 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002377 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2378 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002379
Ville Syrjälä64e10772015-10-29 21:26:01 +02002380 assert_pipe_disabled(dev_priv, crtc->pipe);
2381 assert_dp_port_disabled(intel_dp);
2382 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002383
Ville Syrjäläabfce942015-10-29 21:26:03 +02002384 DRM_DEBUG_KMS("disabling eDP PLL\n");
2385
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002386 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002387
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002388 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002389 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002390 udelay(200);
2391}
2392
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002393/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002394void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002395{
2396 int ret, i;
2397
2398 /* Should have a valid DPCD by this point */
2399 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2400 return;
2401
2402 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002403 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2404 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002405 } else {
2406 /*
2407 * When turning on, we need to retry for 1ms to give the sink
2408 * time to wake up.
2409 */
2410 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002411 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2412 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002413 if (ret == 1)
2414 break;
2415 msleep(1);
2416 }
2417 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002418
2419 if (ret != 1)
2420 DRM_DEBUG_KMS("failed to %s sink power state\n",
2421 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002422}
2423
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002424static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2425 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002426{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002427 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002428 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002429 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002430 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002431 enum intel_display_power_domain power_domain;
2432 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002433 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002434
2435 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002436 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002437 return false;
2438
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002439 ret = false;
2440
Imre Deak6d129be2014-03-05 16:20:54 +02002441 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002442
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002443 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002444 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002445
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002446 if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002447 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002448 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002449 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002450
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002451 for_each_pipe(dev_priv, p) {
2452 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2453 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2454 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002455 ret = true;
2456
2457 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002458 }
2459 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002460
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002461 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002462 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002463 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002464 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2465 } else {
2466 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002467 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002468
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002469 ret = true;
2470
2471out:
2472 intel_display_power_put(dev_priv, power_domain);
2473
2474 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002475}
2476
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002477static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002478 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002479{
2480 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002481 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002482 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002483 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002484 enum port port = dp_to_dig_port(intel_dp)->port;
2485 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002486
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002487 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002488
2489 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002490
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002491 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002492 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2493
2494 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002495 flags |= DRM_MODE_FLAG_PHSYNC;
2496 else
2497 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002498
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002499 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002500 flags |= DRM_MODE_FLAG_PVSYNC;
2501 else
2502 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002503 } else {
2504 if (tmp & DP_SYNC_HS_HIGH)
2505 flags |= DRM_MODE_FLAG_PHSYNC;
2506 else
2507 flags |= DRM_MODE_FLAG_NHSYNC;
2508
2509 if (tmp & DP_SYNC_VS_HIGH)
2510 flags |= DRM_MODE_FLAG_PVSYNC;
2511 else
2512 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002513 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002514
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002515 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002516
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002517 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
2518 !IS_CHERRYVIEW(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002519 pipe_config->limited_color_range = true;
2520
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002521 pipe_config->lane_count =
2522 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2523
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002524 intel_dp_get_m_n(crtc, pipe_config);
2525
Ville Syrjälä18442d02013-09-13 16:00:08 +03002526 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002527 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002528 pipe_config->port_clock = 162000;
2529 else
2530 pipe_config->port_clock = 270000;
2531 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002532
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002533 pipe_config->base.adjusted_mode.crtc_clock =
2534 intel_dotclock_calculate(pipe_config->port_clock,
2535 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002536
Jani Nikula6aa23e62016-03-24 17:50:20 +02002537 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2538 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002539 /*
2540 * This is a big fat ugly hack.
2541 *
2542 * Some machines in UEFI boot mode provide us a VBT that has 18
2543 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2544 * unknown we fail to light up. Yet the same BIOS boots up with
2545 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2546 * max, not what it tells us to use.
2547 *
2548 * Note: This will still be broken if the eDP panel is not lit
2549 * up by the BIOS, and thus we can't get the mode at module
2550 * load.
2551 */
2552 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002553 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2554 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002555 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002556}
2557
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002558static void intel_disable_dp(struct intel_encoder *encoder,
2559 struct intel_crtc_state *old_crtc_state,
2560 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002561{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002562 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002563 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002564
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002565 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002566 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002567
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002568 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002569 intel_psr_disable(intel_dp);
2570
Daniel Vetter6cb49832012-05-20 17:14:50 +02002571 /* Make sure the panel is off before trying to change the mode. But also
2572 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002573 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002574 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002575 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002576 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002577
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002578 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002579 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002580 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002581}
2582
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002583static void ilk_post_disable_dp(struct intel_encoder *encoder,
2584 struct intel_crtc_state *old_crtc_state,
2585 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002586{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002587 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002588 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002589
Ville Syrjälä49277c32014-03-31 18:21:26 +03002590 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002591
2592 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002593 if (port == PORT_A)
2594 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002595}
2596
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002597static void vlv_post_disable_dp(struct intel_encoder *encoder,
2598 struct intel_crtc_state *old_crtc_state,
2599 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002600{
2601 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2602
2603 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002604}
2605
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002606static void chv_post_disable_dp(struct intel_encoder *encoder,
2607 struct intel_crtc_state *old_crtc_state,
2608 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002609{
2610 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002611 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002612 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002613
2614 intel_dp_link_down(intel_dp);
2615
Ville Syrjäläa5805162015-05-26 20:42:30 +03002616 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002617
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002618 /* Assert data lane reset */
2619 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002620
Ville Syrjäläa5805162015-05-26 20:42:30 +03002621 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002622}
2623
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002624static void
2625_intel_dp_set_link_train(struct intel_dp *intel_dp,
2626 uint32_t *DP,
2627 uint8_t dp_train_pat)
2628{
2629 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2630 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002631 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002632 enum port port = intel_dig_port->port;
2633
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002634 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2635 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2636 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2637
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002638 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002639 uint32_t temp = I915_READ(DP_TP_CTL(port));
2640
2641 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2642 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2643 else
2644 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2645
2646 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2647 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2648 case DP_TRAINING_PATTERN_DISABLE:
2649 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2650
2651 break;
2652 case DP_TRAINING_PATTERN_1:
2653 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2654 break;
2655 case DP_TRAINING_PATTERN_2:
2656 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2657 break;
2658 case DP_TRAINING_PATTERN_3:
2659 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2660 break;
2661 }
2662 I915_WRITE(DP_TP_CTL(port), temp);
2663
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002664 } else if ((IS_GEN7(dev) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002665 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002666 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2667
2668 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2669 case DP_TRAINING_PATTERN_DISABLE:
2670 *DP |= DP_LINK_TRAIN_OFF_CPT;
2671 break;
2672 case DP_TRAINING_PATTERN_1:
2673 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2674 break;
2675 case DP_TRAINING_PATTERN_2:
2676 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2677 break;
2678 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002679 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002680 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2681 break;
2682 }
2683
2684 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002685 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002686 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2687 else
2688 *DP &= ~DP_LINK_TRAIN_MASK;
2689
2690 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2691 case DP_TRAINING_PATTERN_DISABLE:
2692 *DP |= DP_LINK_TRAIN_OFF;
2693 break;
2694 case DP_TRAINING_PATTERN_1:
2695 *DP |= DP_LINK_TRAIN_PAT_1;
2696 break;
2697 case DP_TRAINING_PATTERN_2:
2698 *DP |= DP_LINK_TRAIN_PAT_2;
2699 break;
2700 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002701 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002702 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2703 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002704 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002705 *DP |= DP_LINK_TRAIN_PAT_2;
2706 }
2707 break;
2708 }
2709 }
2710}
2711
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002712static void intel_dp_enable_port(struct intel_dp *intel_dp,
2713 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002714{
2715 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002716 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002717
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002718 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002719
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002720 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002721
2722 /*
2723 * Magic for VLV/CHV. We _must_ first set up the register
2724 * without actually enabling the port, and then do another
2725 * write to enable the port. Otherwise link training will
2726 * fail when the power sequencer is freshly used for this port.
2727 */
2728 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002729 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002730 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002731
2732 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2733 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002734}
2735
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002736static void intel_enable_dp(struct intel_encoder *encoder,
2737 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002738{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002739 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2740 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002741 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002742 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002743 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002744 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002745
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002746 if (WARN_ON(dp_reg & DP_PORT_EN))
2747 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002748
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002749 pps_lock(intel_dp);
2750
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002751 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002752 vlv_init_panel_power_sequencer(intel_dp);
2753
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002754 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002755
2756 edp_panel_vdd_on(intel_dp);
2757 edp_panel_on(intel_dp);
2758 edp_panel_vdd_off(intel_dp, true);
2759
2760 pps_unlock(intel_dp);
2761
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002762 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002763 unsigned int lane_mask = 0x0;
2764
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002765 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002766 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002767
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002768 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2769 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002770 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002771
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002772 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2773 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002774 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002775
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002776 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002777 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002778 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002779 intel_audio_codec_enable(encoder);
2780 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002781}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002782
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002783static void g4x_enable_dp(struct intel_encoder *encoder,
2784 struct intel_crtc_state *pipe_config,
2785 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002786{
Jani Nikula828f5c62013-09-05 16:44:45 +03002787 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2788
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002789 intel_enable_dp(encoder, pipe_config);
Daniel Vetter4be73782014-01-17 14:39:48 +01002790 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002791}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002792
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002793static void vlv_enable_dp(struct intel_encoder *encoder,
2794 struct intel_crtc_state *pipe_config,
2795 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002796{
Jani Nikula828f5c62013-09-05 16:44:45 +03002797 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2798
Daniel Vetter4be73782014-01-17 14:39:48 +01002799 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002800 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002801}
2802
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002803static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2804 struct intel_crtc_state *pipe_config,
2805 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002806{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002807 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002808 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002809
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002810 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002811
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002812 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002813 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002814 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002815}
2816
Ville Syrjälä83b84592014-10-16 21:29:51 +03002817static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2818{
2819 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002820 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002821 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002822 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002823
2824 edp_panel_vdd_off_sync(intel_dp);
2825
2826 /*
2827 * VLV seems to get confused when multiple power seqeuencers
2828 * have the same port selected (even if only one has power/vdd
2829 * enabled). The failure manifests as vlv_wait_port_ready() failing
2830 * CHV on the other hand doesn't seem to mind having the same port
2831 * selected in multiple power seqeuencers, but let's clear the
2832 * port select always when logically disconnecting a power sequencer
2833 * from a port.
2834 */
2835 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2836 pipe_name(pipe), port_name(intel_dig_port->port));
2837 I915_WRITE(pp_on_reg, 0);
2838 POSTING_READ(pp_on_reg);
2839
2840 intel_dp->pps_pipe = INVALID_PIPE;
2841}
2842
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002843static void vlv_steal_power_sequencer(struct drm_device *dev,
2844 enum pipe pipe)
2845{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002846 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002847 struct intel_encoder *encoder;
2848
2849 lockdep_assert_held(&dev_priv->pps_mutex);
2850
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002851 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2852 return;
2853
Jani Nikula19c80542015-12-16 12:48:16 +02002854 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002855 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002856 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002857
2858 if (encoder->type != INTEL_OUTPUT_EDP)
2859 continue;
2860
2861 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002862 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002863
2864 if (intel_dp->pps_pipe != pipe)
2865 continue;
2866
2867 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002868 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002869
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002870 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002871 "stealing pipe %c power sequencer from active eDP port %c\n",
2872 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002873
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002874 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002875 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002876 }
2877}
2878
2879static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2880{
2881 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2882 struct intel_encoder *encoder = &intel_dig_port->base;
2883 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002884 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002885 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002886
2887 lockdep_assert_held(&dev_priv->pps_mutex);
2888
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002889 if (!is_edp(intel_dp))
2890 return;
2891
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002892 if (intel_dp->pps_pipe == crtc->pipe)
2893 return;
2894
2895 /*
2896 * If another power sequencer was being used on this
2897 * port previously make sure to turn off vdd there while
2898 * we still have control of it.
2899 */
2900 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002901 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002902
2903 /*
2904 * We may be stealing the power
2905 * sequencer from another port.
2906 */
2907 vlv_steal_power_sequencer(dev, crtc->pipe);
2908
2909 /* now it's all ours */
2910 intel_dp->pps_pipe = crtc->pipe;
2911
2912 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2913 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2914
2915 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002916 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2917 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002918}
2919
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002920static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2921 struct intel_crtc_state *pipe_config,
2922 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002923{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002924 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002925
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002926 intel_enable_dp(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002927}
2928
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002929static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2930 struct intel_crtc_state *pipe_config,
2931 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002932{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002933 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002934
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002935 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002936}
2937
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002938static void chv_pre_enable_dp(struct intel_encoder *encoder,
2939 struct intel_crtc_state *pipe_config,
2940 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002941{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002942 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002943
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002944 intel_enable_dp(encoder, pipe_config);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002945
2946 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002947 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002948}
2949
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002950static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2951 struct intel_crtc_state *pipe_config,
2952 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002953{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002954 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002955
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002956 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002957}
2958
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002959static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2960 struct intel_crtc_state *pipe_config,
2961 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002962{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002963 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002964}
2965
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002966/*
2967 * Fetch AUX CH registers 0x202 - 0x207 which contain
2968 * link status information
2969 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002970bool
Keith Packard93f62da2011-11-01 19:45:03 -07002971intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002972{
Lyude9f085eb2016-04-13 10:58:33 -04002973 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2974 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002975}
2976
Paulo Zanoni11002442014-06-13 18:45:41 -03002977/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002978uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002979intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002980{
Paulo Zanoni30add222012-10-26 19:05:45 -02002981 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002982 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002983 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002984
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002985 if (IS_BROXTON(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05302986 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2987 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002988 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302989 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002990 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002991 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05302992 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002993 else if (IS_GEN7(dev) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302994 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002995 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302996 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08002997 else
Sonika Jindalbd600182014-08-08 16:23:41 +05302998 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08002999}
3000
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003001uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003002intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3003{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003004 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003005 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003006
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003007 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003008 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3009 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;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303015 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3016 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003017 default:
3018 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3019 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003020 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003021 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303022 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3023 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3024 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3025 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3026 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3027 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3028 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003029 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303030 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003031 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003032 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003033 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303034 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3035 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3036 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3037 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3038 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3039 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3040 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003041 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303042 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003043 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003044 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003045 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303046 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3047 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3048 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3049 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3050 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003051 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303052 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003053 }
3054 } else {
3055 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303056 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3057 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3058 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3059 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3060 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3061 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3062 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003063 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303064 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003065 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003066 }
3067}
3068
Daniel Vetter5829975c2015-04-16 11:36:52 +02003069static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003070{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003071 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003072 unsigned long demph_reg_value, preemph_reg_value,
3073 uniqtranscale_reg_value;
3074 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003075
3076 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303077 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003078 preemph_reg_value = 0x0004000;
3079 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303080 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003081 demph_reg_value = 0x2B405555;
3082 uniqtranscale_reg_value = 0x552AB83A;
3083 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303084 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003085 demph_reg_value = 0x2B404040;
3086 uniqtranscale_reg_value = 0x5548B83A;
3087 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303088 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003089 demph_reg_value = 0x2B245555;
3090 uniqtranscale_reg_value = 0x5560B83A;
3091 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303092 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003093 demph_reg_value = 0x2B405555;
3094 uniqtranscale_reg_value = 0x5598DA3A;
3095 break;
3096 default:
3097 return 0;
3098 }
3099 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303100 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003101 preemph_reg_value = 0x0002000;
3102 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303103 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003104 demph_reg_value = 0x2B404040;
3105 uniqtranscale_reg_value = 0x5552B83A;
3106 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003108 demph_reg_value = 0x2B404848;
3109 uniqtranscale_reg_value = 0x5580B83A;
3110 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303111 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003112 demph_reg_value = 0x2B404040;
3113 uniqtranscale_reg_value = 0x55ADDA3A;
3114 break;
3115 default:
3116 return 0;
3117 }
3118 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303119 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003120 preemph_reg_value = 0x0000000;
3121 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303122 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003123 demph_reg_value = 0x2B305555;
3124 uniqtranscale_reg_value = 0x5570B83A;
3125 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003127 demph_reg_value = 0x2B2B4040;
3128 uniqtranscale_reg_value = 0x55ADDA3A;
3129 break;
3130 default:
3131 return 0;
3132 }
3133 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303134 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003135 preemph_reg_value = 0x0006000;
3136 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003138 demph_reg_value = 0x1B405555;
3139 uniqtranscale_reg_value = 0x55ADDA3A;
3140 break;
3141 default:
3142 return 0;
3143 }
3144 break;
3145 default:
3146 return 0;
3147 }
3148
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003149 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3150 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003151
3152 return 0;
3153}
3154
Daniel Vetter5829975c2015-04-16 11:36:52 +02003155static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003156{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003157 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3158 u32 deemph_reg_value, margin_reg_value;
3159 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003160 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003161
3162 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303163 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003164 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303165 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003166 deemph_reg_value = 128;
3167 margin_reg_value = 52;
3168 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003170 deemph_reg_value = 128;
3171 margin_reg_value = 77;
3172 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003174 deemph_reg_value = 128;
3175 margin_reg_value = 102;
3176 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003178 deemph_reg_value = 128;
3179 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003180 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003181 break;
3182 default:
3183 return 0;
3184 }
3185 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303186 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003187 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303188 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003189 deemph_reg_value = 85;
3190 margin_reg_value = 78;
3191 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003193 deemph_reg_value = 85;
3194 margin_reg_value = 116;
3195 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003197 deemph_reg_value = 85;
3198 margin_reg_value = 154;
3199 break;
3200 default:
3201 return 0;
3202 }
3203 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303204 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003205 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303206 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003207 deemph_reg_value = 64;
3208 margin_reg_value = 104;
3209 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003211 deemph_reg_value = 64;
3212 margin_reg_value = 154;
3213 break;
3214 default:
3215 return 0;
3216 }
3217 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003219 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303220 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003221 deemph_reg_value = 43;
3222 margin_reg_value = 154;
3223 break;
3224 default:
3225 return 0;
3226 }
3227 break;
3228 default:
3229 return 0;
3230 }
3231
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003232 chv_set_phy_signal_level(encoder, deemph_reg_value,
3233 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003234
3235 return 0;
3236}
3237
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003238static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003239gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003240{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003241 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003242
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003243 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303244 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003245 default:
3246 signal_levels |= DP_VOLTAGE_0_4;
3247 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303248 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003249 signal_levels |= DP_VOLTAGE_0_6;
3250 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303251 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003252 signal_levels |= DP_VOLTAGE_0_8;
3253 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303254 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003255 signal_levels |= DP_VOLTAGE_1_2;
3256 break;
3257 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003258 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303259 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003260 default:
3261 signal_levels |= DP_PRE_EMPHASIS_0;
3262 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303263 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003264 signal_levels |= DP_PRE_EMPHASIS_3_5;
3265 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303266 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003267 signal_levels |= DP_PRE_EMPHASIS_6;
3268 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303269 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003270 signal_levels |= DP_PRE_EMPHASIS_9_5;
3271 break;
3272 }
3273 return signal_levels;
3274}
3275
Zhenyu Wange3421a12010-04-08 09:43:27 +08003276/* Gen6's DP voltage swing and pre-emphasis control */
3277static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003278gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003279{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003280 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3281 DP_TRAIN_PRE_EMPHASIS_MASK);
3282 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003285 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303286 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003287 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3289 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003290 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3292 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003293 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303294 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003296 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003297 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003298 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3299 "0x%x\n", signal_levels);
3300 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003301 }
3302}
3303
Keith Packard1a2eb462011-11-16 16:26:07 -08003304/* Gen7's DP voltage swing and pre-emphasis control */
3305static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003306gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003307{
3308 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3309 DP_TRAIN_PRE_EMPHASIS_MASK);
3310 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303311 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003312 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303313 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003314 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303315 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003316 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3317
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003319 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003321 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3322
Sonika Jindalbd600182014-08-08 16:23:41 +05303323 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003324 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303325 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003326 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3327
3328 default:
3329 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3330 "0x%x\n", signal_levels);
3331 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3332 }
3333}
3334
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003335void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003336intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003337{
3338 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003339 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003340 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003341 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003342 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003343 uint8_t train_set = intel_dp->train_set[0];
3344
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003345 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003346 signal_levels = ddi_signal_levels(intel_dp);
3347
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003348 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003349 signal_levels = 0;
3350 else
3351 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003352 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003353 signal_levels = chv_signal_levels(intel_dp);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003354 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003355 signal_levels = vlv_signal_levels(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003356 } else if (IS_GEN7(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003357 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003358 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003359 } else if (IS_GEN6(dev) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003360 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003361 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3362 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003363 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003364 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3365 }
3366
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303367 if (mask)
3368 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3369
3370 DRM_DEBUG_KMS("Using vswing level %d\n",
3371 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3372 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3373 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3374 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003375
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003376 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003377
3378 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3379 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003380}
3381
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003382void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003383intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3384 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003385{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003386 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003387 struct drm_i915_private *dev_priv =
3388 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003389
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003390 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003391
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003392 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003393 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003394}
3395
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003396void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003397{
3398 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3399 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003400 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003401 enum port port = intel_dig_port->port;
3402 uint32_t val;
3403
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003404 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003405 return;
3406
3407 val = I915_READ(DP_TP_CTL(port));
3408 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3409 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3410 I915_WRITE(DP_TP_CTL(port), val);
3411
3412 /*
3413 * On PORT_A we can have only eDP in SST mode. There the only reason
3414 * we need to set idle transmission mode is to work around a HW issue
3415 * where we enable the pipe while not in idle link-training mode.
3416 * In this case there is requirement to wait for a minimum number of
3417 * idle patterns to be sent.
3418 */
3419 if (port == PORT_A)
3420 return;
3421
Chris Wilsona7670172016-06-30 15:33:10 +01003422 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3423 DP_TP_STATUS_IDLE_DONE,
3424 DP_TP_STATUS_IDLE_DONE,
3425 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003426 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3427}
3428
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003429static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003430intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003431{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003432 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003433 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003434 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003435 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003436 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003437 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003438
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003439 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003440 return;
3441
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003442 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003443 return;
3444
Zhao Yakui28c97732009-10-09 11:39:41 +08003445 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003446
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03003447 if ((IS_GEN7(dev) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003448 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003449 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003450 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003451 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003452 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003453 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3454 else
3455 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003456 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003457 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003458 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003459 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003460
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003461 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3462 I915_WRITE(intel_dp->output_reg, DP);
3463 POSTING_READ(intel_dp->output_reg);
3464
3465 /*
3466 * HW workaround for IBX, we need to move the port
3467 * to transcoder A after disabling it to allow the
3468 * matching HDMI port to be enabled on transcoder A.
3469 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003470 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003471 /*
3472 * We get CPU/PCH FIFO underruns on the other pipe when
3473 * doing the workaround. Sweep them under the rug.
3474 */
3475 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3476 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3477
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003478 /* always enable with pattern 1 (as per spec) */
3479 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3480 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3481 I915_WRITE(intel_dp->output_reg, DP);
3482 POSTING_READ(intel_dp->output_reg);
3483
3484 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003485 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003486 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003487
Chris Wilson91c8a322016-07-05 10:40:23 +01003488 intel_wait_for_vblank_if_active(&dev_priv->drm, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003489 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3490 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003491 }
3492
Keith Packardf01eca22011-09-28 16:48:10 -07003493 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003494
3495 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003496}
3497
Keith Packard26d61aa2011-07-25 20:01:09 -07003498static bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003499intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003500{
Lyude9f085eb2016-04-13 10:58:33 -04003501 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3502 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003503 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003504
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003505 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003506
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003507 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3508}
3509
3510static bool
3511intel_edp_init_dpcd(struct intel_dp *intel_dp)
3512{
3513 struct drm_i915_private *dev_priv =
3514 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3515
3516 /* this function is meant to be called only once */
3517 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3518
3519 if (!intel_dp_read_dpcd(intel_dp))
3520 return false;
3521
3522 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3523 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3524 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3525
3526 /* Check if the panel supports PSR */
3527 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3528 intel_dp->psr_dpcd,
3529 sizeof(intel_dp->psr_dpcd));
3530 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3531 dev_priv->psr.sink_support = true;
3532 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3533 }
3534
3535 if (INTEL_GEN(dev_priv) >= 9 &&
3536 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3537 uint8_t frame_sync_cap;
3538
3539 dev_priv->psr.sink_support = true;
3540 drm_dp_dpcd_read(&intel_dp->aux,
3541 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3542 &frame_sync_cap, 1);
3543 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3544 /* PSR2 needs frame sync as well */
3545 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3546 DRM_DEBUG_KMS("PSR2 %s on sink",
3547 dev_priv->psr.psr2_support ? "supported" : "not supported");
3548 }
3549
3550 /* Read the eDP Display control capabilities registers */
3551 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3552 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003553 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3554 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003555 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3556 intel_dp->edp_dpcd);
3557
3558 /* Intermediate frequency support */
3559 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3560 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3561 int i;
3562
3563 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3564 sink_rates, sizeof(sink_rates));
3565
3566 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3567 int val = le16_to_cpu(sink_rates[i]);
3568
3569 if (val == 0)
3570 break;
3571
3572 /* Value read is in kHz while drm clock is saved in deca-kHz */
3573 intel_dp->sink_rates[i] = (val * 200) / 10;
3574 }
3575 intel_dp->num_sink_rates = i;
3576 }
3577
3578 return true;
3579}
3580
3581
3582static bool
3583intel_dp_get_dpcd(struct intel_dp *intel_dp)
3584{
3585 if (!intel_dp_read_dpcd(intel_dp))
3586 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003587
Lyude9f085eb2016-04-13 10:58:33 -04003588 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3589 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303590 return false;
3591
3592 /*
3593 * Sink count can change between short pulse hpd hence
3594 * a member variable in intel_dp will track any changes
3595 * between short pulse interrupts.
3596 */
3597 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3598
3599 /*
3600 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3601 * a dongle is present but no display. Unless we require to know
3602 * if a dongle is present or not, we don't need to update
3603 * downstream port information. So, an early return here saves
3604 * time from performing other operations which are not required.
3605 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303606 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303607 return false;
3608
Adam Jacksonedb39242012-09-18 10:58:49 -04003609 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3610 DP_DWN_STRM_PORT_PRESENT))
3611 return true; /* native DP sink */
3612
3613 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3614 return true; /* no per-port downstream info */
3615
Lyude9f085eb2016-04-13 10:58:33 -04003616 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3617 intel_dp->downstream_ports,
3618 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003619 return false; /* downstream port status fetch failed */
3620
3621 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003622}
3623
Adam Jackson0d198322012-05-14 16:05:47 -04003624static void
3625intel_dp_probe_oui(struct intel_dp *intel_dp)
3626{
3627 u8 buf[3];
3628
3629 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3630 return;
3631
Lyude9f085eb2016-04-13 10:58:33 -04003632 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003633 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3634 buf[0], buf[1], buf[2]);
3635
Lyude9f085eb2016-04-13 10:58:33 -04003636 if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003637 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3638 buf[0], buf[1], buf[2]);
3639}
3640
Dave Airlie0e32b392014-05-02 14:02:48 +10003641static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003642intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003643{
3644 u8 buf[1];
3645
Nathan Schulte7cc96132016-03-15 10:14:05 -05003646 if (!i915.enable_dp_mst)
3647 return false;
3648
Dave Airlie0e32b392014-05-02 14:02:48 +10003649 if (!intel_dp->can_mst)
3650 return false;
3651
3652 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3653 return false;
3654
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003655 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3656 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003657
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003658 return buf[0] & DP_MST_CAP;
3659}
3660
3661static void
3662intel_dp_configure_mst(struct intel_dp *intel_dp)
3663{
3664 if (!i915.enable_dp_mst)
3665 return;
3666
3667 if (!intel_dp->can_mst)
3668 return;
3669
3670 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3671
3672 if (intel_dp->is_mst)
3673 DRM_DEBUG_KMS("Sink is MST capable\n");
3674 else
3675 DRM_DEBUG_KMS("Sink is not MST capable\n");
3676
3677 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3678 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003679}
3680
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003681static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003682{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003683 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003684 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003685 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003686 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003687 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003688 int count = 0;
3689 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003690
3691 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003692 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003693 ret = -EIO;
3694 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003695 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003696
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003697 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003698 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003699 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003700 ret = -EIO;
3701 goto out;
3702 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003703
Rodrigo Vivic6297842015-11-05 10:50:20 -08003704 do {
3705 intel_wait_for_vblank(dev, intel_crtc->pipe);
3706
3707 if (drm_dp_dpcd_readb(&intel_dp->aux,
3708 DP_TEST_SINK_MISC, &buf) < 0) {
3709 ret = -EIO;
3710 goto out;
3711 }
3712 count = buf & DP_TEST_COUNT_MASK;
3713 } while (--attempts && count);
3714
3715 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003716 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003717 ret = -ETIMEDOUT;
3718 }
3719
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003720 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003721 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003722 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003723}
3724
3725static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3726{
3727 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003728 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003729 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3730 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003731 int ret;
3732
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003733 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3734 return -EIO;
3735
3736 if (!(buf & DP_TEST_CRC_SUPPORTED))
3737 return -ENOTTY;
3738
3739 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3740 return -EIO;
3741
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003742 if (buf & DP_TEST_SINK_START) {
3743 ret = intel_dp_sink_crc_stop(intel_dp);
3744 if (ret)
3745 return ret;
3746 }
3747
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003748 hsw_disable_ips(intel_crtc);
3749
3750 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3751 buf | DP_TEST_SINK_START) < 0) {
3752 hsw_enable_ips(intel_crtc);
3753 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003754 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003755
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003756 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003757 return 0;
3758}
3759
3760int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3761{
3762 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3763 struct drm_device *dev = dig_port->base.base.dev;
3764 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3765 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003766 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003767 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003768
3769 ret = intel_dp_sink_crc_start(intel_dp);
3770 if (ret)
3771 return ret;
3772
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003773 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003774 intel_wait_for_vblank(dev, intel_crtc->pipe);
3775
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003776 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003777 DP_TEST_SINK_MISC, &buf) < 0) {
3778 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003779 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003780 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003781 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003782
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003783 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003784
3785 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003786 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3787 ret = -ETIMEDOUT;
3788 goto stop;
3789 }
3790
3791 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3792 ret = -EIO;
3793 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003794 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003795
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003796stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003797 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003798 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003799}
3800
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003801static bool
3802intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3803{
Lyude9f085eb2016-04-13 10:58:33 -04003804 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003805 DP_DEVICE_SERVICE_IRQ_VECTOR,
3806 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003807}
3808
Dave Airlie0e32b392014-05-02 14:02:48 +10003809static bool
3810intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3811{
3812 int ret;
3813
Lyude9f085eb2016-04-13 10:58:33 -04003814 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003815 DP_SINK_COUNT_ESI,
3816 sink_irq_vector, 14);
3817 if (ret != 14)
3818 return false;
3819
3820 return true;
3821}
3822
Todd Previtec5d5ab72015-04-15 08:38:38 -07003823static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003824{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003825 uint8_t test_result = DP_TEST_ACK;
3826 return test_result;
3827}
3828
3829static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3830{
3831 uint8_t test_result = DP_TEST_NAK;
3832 return test_result;
3833}
3834
3835static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3836{
3837 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003838 struct intel_connector *intel_connector = intel_dp->attached_connector;
3839 struct drm_connector *connector = &intel_connector->base;
3840
3841 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003842 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003843 intel_dp->aux.i2c_defer_count > 6) {
3844 /* Check EDID read for NACKs, DEFERs and corruption
3845 * (DP CTS 1.2 Core r1.1)
3846 * 4.2.2.4 : Failed EDID read, I2C_NAK
3847 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3848 * 4.2.2.6 : EDID corruption detected
3849 * Use failsafe mode for all cases
3850 */
3851 if (intel_dp->aux.i2c_nack_count > 0 ||
3852 intel_dp->aux.i2c_defer_count > 0)
3853 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3854 intel_dp->aux.i2c_nack_count,
3855 intel_dp->aux.i2c_defer_count);
3856 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3857 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303858 struct edid *block = intel_connector->detect_edid;
3859
3860 /* We have to write the checksum
3861 * of the last block read
3862 */
3863 block += intel_connector->detect_edid->extensions;
3864
Todd Previte559be302015-05-04 07:48:20 -07003865 if (!drm_dp_dpcd_write(&intel_dp->aux,
3866 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303867 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003868 1))
Todd Previte559be302015-05-04 07:48:20 -07003869 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3870
3871 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3872 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3873 }
3874
3875 /* Set test active flag here so userspace doesn't interrupt things */
3876 intel_dp->compliance_test_active = 1;
3877
Todd Previtec5d5ab72015-04-15 08:38:38 -07003878 return test_result;
3879}
3880
3881static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3882{
3883 uint8_t test_result = DP_TEST_NAK;
3884 return test_result;
3885}
3886
3887static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3888{
3889 uint8_t response = DP_TEST_NAK;
3890 uint8_t rxdata = 0;
3891 int status = 0;
3892
Todd Previtec5d5ab72015-04-15 08:38:38 -07003893 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3894 if (status <= 0) {
3895 DRM_DEBUG_KMS("Could not read test request from sink\n");
3896 goto update_status;
3897 }
3898
3899 switch (rxdata) {
3900 case DP_TEST_LINK_TRAINING:
3901 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3902 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3903 response = intel_dp_autotest_link_training(intel_dp);
3904 break;
3905 case DP_TEST_LINK_VIDEO_PATTERN:
3906 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3907 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3908 response = intel_dp_autotest_video_pattern(intel_dp);
3909 break;
3910 case DP_TEST_LINK_EDID_READ:
3911 DRM_DEBUG_KMS("EDID test requested\n");
3912 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3913 response = intel_dp_autotest_edid(intel_dp);
3914 break;
3915 case DP_TEST_LINK_PHY_TEST_PATTERN:
3916 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3917 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3918 response = intel_dp_autotest_phy_pattern(intel_dp);
3919 break;
3920 default:
3921 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3922 break;
3923 }
3924
3925update_status:
3926 status = drm_dp_dpcd_write(&intel_dp->aux,
3927 DP_TEST_RESPONSE,
3928 &response, 1);
3929 if (status <= 0)
3930 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003931}
3932
Dave Airlie0e32b392014-05-02 14:02:48 +10003933static int
3934intel_dp_check_mst_status(struct intel_dp *intel_dp)
3935{
3936 bool bret;
3937
3938 if (intel_dp->is_mst) {
3939 u8 esi[16] = { 0 };
3940 int ret = 0;
3941 int retry;
3942 bool handled;
3943 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3944go_again:
3945 if (bret == true) {
3946
3947 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003948 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003949 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003950 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3951 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003952 intel_dp_stop_link_train(intel_dp);
3953 }
3954
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003955 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003956 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3957
3958 if (handled) {
3959 for (retry = 0; retry < 3; retry++) {
3960 int wret;
3961 wret = drm_dp_dpcd_write(&intel_dp->aux,
3962 DP_SINK_COUNT_ESI+1,
3963 &esi[1], 3);
3964 if (wret == 3) {
3965 break;
3966 }
3967 }
3968
3969 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3970 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003971 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003972 goto go_again;
3973 }
3974 } else
3975 ret = 0;
3976
3977 return ret;
3978 } else {
3979 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3980 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3981 intel_dp->is_mst = false;
3982 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3983 /* send a hotplug event */
3984 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3985 }
3986 }
3987 return -EINVAL;
3988}
3989
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303990static void
3991intel_dp_check_link_status(struct intel_dp *intel_dp)
3992{
3993 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
3994 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3995 u8 link_status[DP_LINK_STATUS_SIZE];
3996
3997 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
3998
3999 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4000 DRM_ERROR("Failed to get link status\n");
4001 return;
4002 }
4003
4004 if (!intel_encoder->base.crtc)
4005 return;
4006
4007 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4008 return;
4009
4010 /* if link training is requested we should perform it always */
4011 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
4012 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4013 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4014 intel_encoder->base.name);
4015 intel_dp_start_link_train(intel_dp);
4016 intel_dp_stop_link_train(intel_dp);
4017 }
4018}
4019
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004020/*
4021 * According to DP spec
4022 * 5.1.2:
4023 * 1. Read DPCD
4024 * 2. Configure link according to Receiver Capabilities
4025 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4026 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304027 *
4028 * intel_dp_short_pulse - handles short pulse interrupts
4029 * when full detection is not required.
4030 * Returns %true if short pulse is handled and full detection
4031 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004032 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304033static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304034intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004035{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004036 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004037 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304038 u8 old_sink_count = intel_dp->sink_count;
4039 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004040
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304041 /*
4042 * Clearing compliance test variables to allow capturing
4043 * of values for next automated test request.
4044 */
4045 intel_dp->compliance_test_active = 0;
4046 intel_dp->compliance_test_type = 0;
4047 intel_dp->compliance_test_data = 0;
4048
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304049 /*
4050 * Now read the DPCD to see if it's actually running
4051 * If the current value of sink count doesn't match with
4052 * the value that was stored earlier or dpcd read failed
4053 * we need to do full detection
4054 */
4055 ret = intel_dp_get_dpcd(intel_dp);
4056
4057 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4058 /* No need to proceed if we are going to do full detect */
4059 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004060 }
4061
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004062 /* Try to read the source of the interrupt */
4063 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004064 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4065 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004066 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004067 drm_dp_dpcd_writeb(&intel_dp->aux,
4068 DP_DEVICE_SERVICE_IRQ_VECTOR,
4069 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004070
4071 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004072 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004073 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4074 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4075 }
4076
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304077 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4078 intel_dp_check_link_status(intel_dp);
4079 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304080
4081 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004082}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004083
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004084/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004085static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004086intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004087{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004088 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004089 uint8_t type;
4090
4091 if (!intel_dp_get_dpcd(intel_dp))
4092 return connector_status_disconnected;
4093
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304094 if (is_edp(intel_dp))
4095 return connector_status_connected;
4096
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004097 /* if there's no downstream port, we're done */
4098 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07004099 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004100
4101 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004102 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4103 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004104
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304105 return intel_dp->sink_count ?
4106 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004107 }
4108
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004109 if (intel_dp_can_mst(intel_dp))
4110 return connector_status_connected;
4111
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004112 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004113 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004114 return connector_status_connected;
4115
4116 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004117 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4118 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4119 if (type == DP_DS_PORT_TYPE_VGA ||
4120 type == DP_DS_PORT_TYPE_NON_EDID)
4121 return connector_status_unknown;
4122 } else {
4123 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4124 DP_DWN_STRM_PORT_TYPE_MASK;
4125 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4126 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4127 return connector_status_unknown;
4128 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004129
4130 /* Anything else is out of spec, warn and ignore */
4131 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004132 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004133}
4134
4135static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004136edp_detect(struct intel_dp *intel_dp)
4137{
4138 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4139 enum drm_connector_status status;
4140
4141 status = intel_panel_detect(dev);
4142 if (status == connector_status_unknown)
4143 status = connector_status_connected;
4144
4145 return status;
4146}
4147
Jani Nikulab93433c2015-08-20 10:47:36 +03004148static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4149 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004150{
Jani Nikulab93433c2015-08-20 10:47:36 +03004151 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004152
Jani Nikula0df53b72015-08-20 10:47:40 +03004153 switch (port->port) {
4154 case PORT_A:
4155 return true;
4156 case PORT_B:
4157 bit = SDE_PORTB_HOTPLUG;
4158 break;
4159 case PORT_C:
4160 bit = SDE_PORTC_HOTPLUG;
4161 break;
4162 case PORT_D:
4163 bit = SDE_PORTD_HOTPLUG;
4164 break;
4165 default:
4166 MISSING_CASE(port->port);
4167 return false;
4168 }
4169
4170 return I915_READ(SDEISR) & bit;
4171}
4172
4173static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4174 struct intel_digital_port *port)
4175{
4176 u32 bit;
4177
4178 switch (port->port) {
4179 case PORT_A:
4180 return true;
4181 case PORT_B:
4182 bit = SDE_PORTB_HOTPLUG_CPT;
4183 break;
4184 case PORT_C:
4185 bit = SDE_PORTC_HOTPLUG_CPT;
4186 break;
4187 case PORT_D:
4188 bit = SDE_PORTD_HOTPLUG_CPT;
4189 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004190 case PORT_E:
4191 bit = SDE_PORTE_HOTPLUG_SPT;
4192 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004193 default:
4194 MISSING_CASE(port->port);
4195 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004196 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004197
Jani Nikulab93433c2015-08-20 10:47:36 +03004198 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004199}
4200
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004201static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004202 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004203{
Jani Nikula9642c812015-08-20 10:47:41 +03004204 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004205
Jani Nikula9642c812015-08-20 10:47:41 +03004206 switch (port->port) {
4207 case PORT_B:
4208 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4209 break;
4210 case PORT_C:
4211 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4212 break;
4213 case PORT_D:
4214 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4215 break;
4216 default:
4217 MISSING_CASE(port->port);
4218 return false;
4219 }
4220
4221 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4222}
4223
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004224static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4225 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004226{
4227 u32 bit;
4228
4229 switch (port->port) {
4230 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004231 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004232 break;
4233 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004234 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004235 break;
4236 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004237 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004238 break;
4239 default:
4240 MISSING_CASE(port->port);
4241 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004242 }
4243
Jani Nikula1d245982015-08-20 10:47:37 +03004244 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004245}
4246
Jani Nikulae464bfd2015-08-20 10:47:42 +03004247static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304248 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004249{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304250 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4251 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004252 u32 bit;
4253
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304254 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4255 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004256 case PORT_A:
4257 bit = BXT_DE_PORT_HP_DDIA;
4258 break;
4259 case PORT_B:
4260 bit = BXT_DE_PORT_HP_DDIB;
4261 break;
4262 case PORT_C:
4263 bit = BXT_DE_PORT_HP_DDIC;
4264 break;
4265 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304266 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004267 return false;
4268 }
4269
4270 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4271}
4272
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004273/*
4274 * intel_digital_port_connected - is the specified port connected?
4275 * @dev_priv: i915 private structure
4276 * @port: the port to test
4277 *
4278 * Return %true if @port is connected, %false otherwise.
4279 */
David Weinehall23f889b2016-08-17 15:47:48 +03004280static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004281 struct intel_digital_port *port)
4282{
Jani Nikula0df53b72015-08-20 10:47:40 +03004283 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004284 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004285 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004286 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004287 else if (IS_BROXTON(dev_priv))
4288 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004289 else if (IS_GM45(dev_priv))
4290 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004291 else
4292 return g4x_digital_port_connected(dev_priv, port);
4293}
4294
Keith Packard8c241fe2011-09-28 16:38:44 -07004295static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004296intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004297{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004298 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004299
Jani Nikula9cd300e2012-10-19 14:51:52 +03004300 /* use cached edid if we have one */
4301 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004302 /* invalid edid */
4303 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004304 return NULL;
4305
Jani Nikula55e9ede2013-10-01 10:38:54 +03004306 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004307 } else
4308 return drm_get_edid(&intel_connector->base,
4309 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004310}
4311
Chris Wilsonbeb60602014-09-02 20:04:00 +01004312static void
4313intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004314{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004315 struct intel_connector *intel_connector = intel_dp->attached_connector;
4316 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004317
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304318 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004319 edid = intel_dp_get_edid(intel_dp);
4320 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004321
Chris Wilsonbeb60602014-09-02 20:04:00 +01004322 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4323 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4324 else
4325 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4326}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004327
Chris Wilsonbeb60602014-09-02 20:04:00 +01004328static void
4329intel_dp_unset_edid(struct intel_dp *intel_dp)
4330{
4331 struct intel_connector *intel_connector = intel_dp->attached_connector;
4332
4333 kfree(intel_connector->detect_edid);
4334 intel_connector->detect_edid = NULL;
4335
4336 intel_dp->has_audio = false;
4337}
4338
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004339static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304340intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004341{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304342 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004343 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004344 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4345 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004346 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004347 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004348 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004349 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004350
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004351 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4352 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004353
Chris Wilsond410b562014-09-02 20:03:59 +01004354 /* Can't disconnect eDP, but you can close the lid... */
4355 if (is_edp(intel_dp))
4356 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004357 else if (intel_digital_port_connected(to_i915(dev),
4358 dp_to_dig_port(intel_dp)))
4359 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004360 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004361 status = connector_status_disconnected;
4362
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004363 if (status == connector_status_disconnected) {
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304364 intel_dp->compliance_test_active = 0;
4365 intel_dp->compliance_test_type = 0;
4366 intel_dp->compliance_test_data = 0;
4367
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004368 if (intel_dp->is_mst) {
4369 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4370 intel_dp->is_mst,
4371 intel_dp->mst_mgr.mst_state);
4372 intel_dp->is_mst = false;
4373 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4374 intel_dp->is_mst);
4375 }
4376
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004377 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304378 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004379
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304380 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004381 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304382
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004383 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4384 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4385 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4386
4387 intel_dp_print_rates(intel_dp);
4388
Adam Jackson0d198322012-05-14 16:05:47 -04004389 intel_dp_probe_oui(intel_dp);
4390
Mika Kahola0e390a32016-09-09 14:10:53 +03004391 intel_dp_print_hw_revision(intel_dp);
Mika Kahola1a2724f2016-09-09 14:10:54 +03004392 intel_dp_print_sw_revision(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004393
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004394 intel_dp_configure_mst(intel_dp);
4395
4396 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304397 /*
4398 * If we are in MST mode then this connector
4399 * won't appear connected or have anything
4400 * with EDID on it
4401 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004402 status = connector_status_disconnected;
4403 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304404 } else if (connector->status == connector_status_connected) {
4405 /*
4406 * If display was connected already and is still connected
4407 * check links status, there has been known issues of
4408 * link loss triggerring long pulse!!!!
4409 */
4410 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4411 intel_dp_check_link_status(intel_dp);
4412 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4413 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004414 }
4415
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304416 /*
4417 * Clearing NACK and defer counts to get their exact values
4418 * while reading EDID which are required by Compliance tests
4419 * 4.2.2.4 and 4.2.2.5
4420 */
4421 intel_dp->aux.i2c_nack_count = 0;
4422 intel_dp->aux.i2c_defer_count = 0;
4423
Chris Wilsonbeb60602014-09-02 20:04:00 +01004424 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004425 if (is_edp(intel_dp) || intel_connector->detect_edid)
4426 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304427 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004428
Todd Previte09b1eb12015-04-20 15:27:34 -07004429 /* Try to read the source of the interrupt */
4430 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004431 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4432 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004433 /* Clear interrupt source */
4434 drm_dp_dpcd_writeb(&intel_dp->aux,
4435 DP_DEVICE_SERVICE_IRQ_VECTOR,
4436 sink_irq_vector);
4437
4438 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4439 intel_dp_handle_test_request(intel_dp);
4440 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4441 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4442 }
4443
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004444out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004445 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304446 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304447
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004448 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004449 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304450}
4451
4452static enum drm_connector_status
4453intel_dp_detect(struct drm_connector *connector, bool force)
4454{
4455 struct intel_dp *intel_dp = intel_attached_dp(connector);
4456 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4457 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004458 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304459
4460 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4461 connector->base.id, connector->name);
4462
4463 if (intel_dp->is_mst) {
4464 /* MST devices are disconnected from a monitor POV */
4465 intel_dp_unset_edid(intel_dp);
4466 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004467 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304468 return connector_status_disconnected;
4469 }
4470
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304471 /* If full detect is not performed yet, do a full detect */
4472 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004473 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304474
4475 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304476
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004477 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004478}
4479
Chris Wilsonbeb60602014-09-02 20:04:00 +01004480static void
4481intel_dp_force(struct drm_connector *connector)
4482{
4483 struct intel_dp *intel_dp = intel_attached_dp(connector);
4484 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004485 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004486 enum intel_display_power_domain power_domain;
4487
4488 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4489 connector->base.id, connector->name);
4490 intel_dp_unset_edid(intel_dp);
4491
4492 if (connector->status != connector_status_connected)
4493 return;
4494
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004495 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4496 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004497
4498 intel_dp_set_edid(intel_dp);
4499
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004500 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004501
4502 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004503 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004504}
4505
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004506static int intel_dp_get_modes(struct drm_connector *connector)
4507{
Jani Nikuladd06f902012-10-19 14:51:50 +03004508 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004509 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004510
Chris Wilsonbeb60602014-09-02 20:04:00 +01004511 edid = intel_connector->detect_edid;
4512 if (edid) {
4513 int ret = intel_connector_update_modes(connector, edid);
4514 if (ret)
4515 return ret;
4516 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004517
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004518 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004519 if (is_edp(intel_attached_dp(connector)) &&
4520 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004521 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004522
4523 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004524 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004525 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004526 drm_mode_probed_add(connector, mode);
4527 return 1;
4528 }
4529 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004530
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004531 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004532}
4533
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004534static bool
4535intel_dp_detect_audio(struct drm_connector *connector)
4536{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004537 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004538 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004539
Chris Wilsonbeb60602014-09-02 20:04:00 +01004540 edid = to_intel_connector(connector)->detect_edid;
4541 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004542 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004543
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004544 return has_audio;
4545}
4546
Chris Wilsonf6849602010-09-19 09:29:33 +01004547static int
4548intel_dp_set_property(struct drm_connector *connector,
4549 struct drm_property *property,
4550 uint64_t val)
4551{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004552 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004553 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004554 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4555 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004556 int ret;
4557
Rob Clark662595d2012-10-11 20:36:04 -05004558 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004559 if (ret)
4560 return ret;
4561
Chris Wilson3f43c482011-05-12 22:17:24 +01004562 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004563 int i = val;
4564 bool has_audio;
4565
4566 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004567 return 0;
4568
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004569 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004570
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004571 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004572 has_audio = intel_dp_detect_audio(connector);
4573 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004574 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004575
4576 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004577 return 0;
4578
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004579 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004580 goto done;
4581 }
4582
Chris Wilsone953fd72011-02-21 22:23:52 +00004583 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004584 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004585 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004586
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004587 switch (val) {
4588 case INTEL_BROADCAST_RGB_AUTO:
4589 intel_dp->color_range_auto = true;
4590 break;
4591 case INTEL_BROADCAST_RGB_FULL:
4592 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004593 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004594 break;
4595 case INTEL_BROADCAST_RGB_LIMITED:
4596 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004597 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004598 break;
4599 default:
4600 return -EINVAL;
4601 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004602
4603 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004604 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004605 return 0;
4606
Chris Wilsone953fd72011-02-21 22:23:52 +00004607 goto done;
4608 }
4609
Yuly Novikov53b41832012-10-26 12:04:00 +03004610 if (is_edp(intel_dp) &&
4611 property == connector->dev->mode_config.scaling_mode_property) {
4612 if (val == DRM_MODE_SCALE_NONE) {
4613 DRM_DEBUG_KMS("no scaling not supported\n");
4614 return -EINVAL;
4615 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004616 if (HAS_GMCH_DISPLAY(dev_priv) &&
4617 val == DRM_MODE_SCALE_CENTER) {
4618 DRM_DEBUG_KMS("centering not supported\n");
4619 return -EINVAL;
4620 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004621
4622 if (intel_connector->panel.fitting_mode == val) {
4623 /* the eDP scaling property is not changed */
4624 return 0;
4625 }
4626 intel_connector->panel.fitting_mode = val;
4627
4628 goto done;
4629 }
4630
Chris Wilsonf6849602010-09-19 09:29:33 +01004631 return -EINVAL;
4632
4633done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004634 if (intel_encoder->base.crtc)
4635 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004636
4637 return 0;
4638}
4639
Chris Wilson7a418e32016-06-24 14:00:14 +01004640static int
4641intel_dp_connector_register(struct drm_connector *connector)
4642{
4643 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004644 int ret;
4645
4646 ret = intel_connector_register(connector);
4647 if (ret)
4648 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004649
4650 i915_debugfs_connector_add(connector);
4651
4652 DRM_DEBUG_KMS("registering %s bus for %s\n",
4653 intel_dp->aux.name, connector->kdev->kobj.name);
4654
4655 intel_dp->aux.dev = connector->kdev;
4656 return drm_dp_aux_register(&intel_dp->aux);
4657}
4658
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004659static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004660intel_dp_connector_unregister(struct drm_connector *connector)
4661{
4662 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4663 intel_connector_unregister(connector);
4664}
4665
4666static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004667intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004668{
Jani Nikula1d508702012-10-19 14:51:49 +03004669 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004670
Chris Wilson10e972d2014-09-04 21:43:45 +01004671 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004672
Jani Nikula9cd300e2012-10-19 14:51:52 +03004673 if (!IS_ERR_OR_NULL(intel_connector->edid))
4674 kfree(intel_connector->edid);
4675
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004676 /* Can't call is_edp() since the encoder may have been destroyed
4677 * already. */
4678 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004679 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004680
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004681 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004682 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004683}
4684
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004685void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004686{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004687 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4688 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004689
Dave Airlie0e32b392014-05-02 14:02:48 +10004690 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004691 if (is_edp(intel_dp)) {
4692 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004693 /*
4694 * vdd might still be enabled do to the delayed vdd off.
4695 * Make sure vdd is actually turned off here.
4696 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004697 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004698 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004699 pps_unlock(intel_dp);
4700
Clint Taylor01527b32014-07-07 13:01:46 -07004701 if (intel_dp->edp_notifier.notifier_call) {
4702 unregister_reboot_notifier(&intel_dp->edp_notifier);
4703 intel_dp->edp_notifier.notifier_call = NULL;
4704 }
Keith Packardbd943152011-09-18 23:09:52 -07004705 }
Chris Wilson99681882016-06-20 09:29:17 +01004706
4707 intel_dp_aux_fini(intel_dp);
4708
Imre Deakc8bd0e42014-12-12 17:57:38 +02004709 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004710 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004711}
4712
Imre Deakbf93ba62016-04-18 10:04:21 +03004713void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004714{
4715 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4716
4717 if (!is_edp(intel_dp))
4718 return;
4719
Ville Syrjälä951468f2014-09-04 14:55:31 +03004720 /*
4721 * vdd might still be enabled do to the delayed vdd off.
4722 * Make sure vdd is actually turned off here.
4723 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004724 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004725 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004726 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004727 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004728}
4729
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004730static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4731{
4732 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4733 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004734 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004735 enum intel_display_power_domain power_domain;
4736
4737 lockdep_assert_held(&dev_priv->pps_mutex);
4738
4739 if (!edp_have_panel_vdd(intel_dp))
4740 return;
4741
4742 /*
4743 * The VDD bit needs a power domain reference, so if the bit is
4744 * already enabled when we boot or resume, grab this reference and
4745 * schedule a vdd off, so we don't hold on to the reference
4746 * indefinitely.
4747 */
4748 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004749 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004750 intel_display_power_get(dev_priv, power_domain);
4751
4752 edp_panel_vdd_schedule_off(intel_dp);
4753}
4754
Imre Deakbf93ba62016-04-18 10:04:21 +03004755void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004756{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004757 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
4758 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4759
4760 if (!HAS_DDI(dev_priv))
4761 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004762
4763 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4764 return;
4765
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004766 pps_lock(intel_dp);
4767
Imre Deak335f7522016-08-10 14:07:32 +03004768 /* Reinit the power sequencer, in case BIOS did something with it. */
4769 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004770 intel_edp_panel_vdd_sanitize(intel_dp);
4771
4772 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004773}
4774
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004775static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004776 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004777 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004778 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004779 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004780 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004781 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004782 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004783 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004784 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004785 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004786 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004787};
4788
4789static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4790 .get_modes = intel_dp_get_modes,
4791 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004792};
4793
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004794static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004795 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004796 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004797};
4798
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004799enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004800intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4801{
4802 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004803 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004804 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004805 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004806 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004807 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004808
Takashi Iwai25400582015-11-19 12:09:56 +01004809 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4810 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004811 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004812
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004813 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4814 /*
4815 * vdd off can generate a long pulse on eDP which
4816 * would require vdd on to handle it, and thus we
4817 * would end up in an endless cycle of
4818 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4819 */
4820 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4821 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004822 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004823 }
4824
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004825 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4826 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004827 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004828
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004829 if (long_hpd) {
4830 intel_dp->detect_done = false;
4831 return IRQ_NONE;
4832 }
4833
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004834 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004835 intel_display_power_get(dev_priv, power_domain);
4836
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004837 if (intel_dp->is_mst) {
4838 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4839 /*
4840 * If we were in MST mode, and device is not
4841 * there, get out of MST mode
4842 */
4843 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4844 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4845 intel_dp->is_mst = false;
4846 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4847 intel_dp->is_mst);
4848 intel_dp->detect_done = false;
4849 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004850 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004851 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004852
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004853 if (!intel_dp->is_mst) {
4854 if (!intel_dp_short_pulse(intel_dp)) {
4855 intel_dp->detect_done = false;
4856 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304857 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004858 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004859
4860 ret = IRQ_HANDLED;
4861
Imre Deak1c767b32014-08-18 14:42:42 +03004862put_power:
4863 intel_display_power_put(dev_priv, power_domain);
4864
4865 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004866}
4867
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004868/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004869bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004870{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004871 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004872
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004873 /*
4874 * eDP not supported on g4x. so bail out early just
4875 * for a bit extra safety in case the VBT is bonkers.
4876 */
4877 if (INTEL_INFO(dev)->gen < 5)
4878 return false;
4879
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004880 if (port == PORT_A)
4881 return true;
4882
Jani Nikula951d9ef2016-03-16 12:43:31 +02004883 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004884}
4885
Dave Airlie0e32b392014-05-02 14:02:48 +10004886void
Chris Wilsonf6849602010-09-19 09:29:33 +01004887intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4888{
Yuly Novikov53b41832012-10-26 12:04:00 +03004889 struct intel_connector *intel_connector = to_intel_connector(connector);
4890
Chris Wilson3f43c482011-05-12 22:17:24 +01004891 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004892 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004893 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004894
4895 if (is_edp(intel_dp)) {
4896 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004897 drm_object_attach_property(
4898 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004899 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004900 DRM_MODE_SCALE_ASPECT);
4901 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004902 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004903}
4904
Imre Deakdada1a92014-01-29 13:25:41 +02004905static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4906{
Abhay Kumard28d4732016-01-22 17:39:04 -08004907 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004908 intel_dp->last_power_on = jiffies;
4909 intel_dp->last_backlight_off = jiffies;
4910}
4911
Daniel Vetter67a54562012-10-20 20:57:45 +02004912static void
Imre Deak54648612016-06-16 16:37:22 +03004913intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4914 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004915{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304916 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004917 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004918
Imre Deak8e8232d2016-06-16 16:37:21 +03004919 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004920
4921 /* Workaround: Need to write PP_CONTROL with the unlock key as
4922 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304923 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004924
Imre Deak8e8232d2016-06-16 16:37:21 +03004925 pp_on = I915_READ(regs.pp_on);
4926 pp_off = I915_READ(regs.pp_off);
Imre Deak54648612016-06-16 16:37:22 +03004927 if (!IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004928 I915_WRITE(regs.pp_ctrl, pp_ctl);
4929 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304930 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004931
4932 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004933 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4934 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004935
Imre Deak54648612016-06-16 16:37:22 +03004936 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4937 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004938
Imre Deak54648612016-06-16 16:37:22 +03004939 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4940 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004941
Imre Deak54648612016-06-16 16:37:22 +03004942 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4943 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004944
Imre Deak54648612016-06-16 16:37:22 +03004945 if (IS_BROXTON(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304946 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4947 BXT_POWER_CYCLE_DELAY_SHIFT;
4948 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004949 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304950 else
Imre Deak54648612016-06-16 16:37:22 +03004951 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304952 } else {
Imre Deak54648612016-06-16 16:37:22 +03004953 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004954 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304955 }
Imre Deak54648612016-06-16 16:37:22 +03004956}
4957
4958static void
Imre Deakde9c1b62016-06-16 20:01:46 +03004959intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
4960{
4961 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4962 state_name,
4963 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
4964}
4965
4966static void
4967intel_pps_verify_state(struct drm_i915_private *dev_priv,
4968 struct intel_dp *intel_dp)
4969{
4970 struct edp_power_seq hw;
4971 struct edp_power_seq *sw = &intel_dp->pps_delays;
4972
4973 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
4974
4975 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
4976 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
4977 DRM_ERROR("PPS state mismatch\n");
4978 intel_pps_dump_state("sw", sw);
4979 intel_pps_dump_state("hw", &hw);
4980 }
4981}
4982
4983static void
Imre Deak54648612016-06-16 16:37:22 +03004984intel_dp_init_panel_power_sequencer(struct drm_device *dev,
4985 struct intel_dp *intel_dp)
4986{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004987 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03004988 struct edp_power_seq cur, vbt, spec,
4989 *final = &intel_dp->pps_delays;
4990
4991 lockdep_assert_held(&dev_priv->pps_mutex);
4992
4993 /* already initialized? */
4994 if (final->t11_t12 != 0)
4995 return;
4996
4997 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02004998
Imre Deakde9c1b62016-06-16 20:01:46 +03004999 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005000
Jani Nikula6aa23e62016-03-24 17:50:20 +02005001 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005002
5003 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5004 * our hw here, which are all in 100usec. */
5005 spec.t1_t3 = 210 * 10;
5006 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5007 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5008 spec.t10 = 500 * 10;
5009 /* This one is special and actually in units of 100ms, but zero
5010 * based in the hw (so we need to add 100 ms). But the sw vbt
5011 * table multiplies it with 1000 to make it in units of 100usec,
5012 * too. */
5013 spec.t11_t12 = (510 + 100) * 10;
5014
Imre Deakde9c1b62016-06-16 20:01:46 +03005015 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005016
5017 /* Use the max of the register settings and vbt. If both are
5018 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005019#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005020 spec.field : \
5021 max(cur.field, vbt.field))
5022 assign_final(t1_t3);
5023 assign_final(t8);
5024 assign_final(t9);
5025 assign_final(t10);
5026 assign_final(t11_t12);
5027#undef assign_final
5028
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005029#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005030 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5031 intel_dp->backlight_on_delay = get_delay(t8);
5032 intel_dp->backlight_off_delay = get_delay(t9);
5033 intel_dp->panel_power_down_delay = get_delay(t10);
5034 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5035#undef get_delay
5036
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005037 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5038 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5039 intel_dp->panel_power_cycle_delay);
5040
5041 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5042 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005043
5044 /*
5045 * We override the HW backlight delays to 1 because we do manual waits
5046 * on them. For T8, even BSpec recommends doing it. For T9, if we
5047 * don't do this, we'll end up waiting for the backlight off delay
5048 * twice: once when we do the manual sleep, and once when we disable
5049 * the panel and wait for the PP_STATUS bit to become zero.
5050 */
5051 final->t8 = 1;
5052 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005053}
5054
5055static void
5056intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005057 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005058{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005059 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005060 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005061 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005062 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005063 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005064 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005065
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005066 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005067
Imre Deak8e8232d2016-06-16 16:37:21 +03005068 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005069
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005070 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005071 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5072 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005073 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005074 /* Compute the divisor for the pp clock, simply match the Bspec
5075 * formula. */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005076 if (IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005077 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305078 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5079 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5080 << BXT_POWER_CYCLE_DELAY_SHIFT);
5081 } else {
5082 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5083 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5084 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5085 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005086
5087 /* Haswell doesn't have any port selection bits for the panel
5088 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005089 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005090 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005091 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005092 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005093 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005094 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005095 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005096 }
5097
Jesse Barnes453c5422013-03-28 09:55:41 -07005098 pp_on |= port_sel;
5099
Imre Deak8e8232d2016-06-16 16:37:21 +03005100 I915_WRITE(regs.pp_on, pp_on);
5101 I915_WRITE(regs.pp_off, pp_off);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005102 if (IS_BROXTON(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005103 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305104 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005105 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005106
Daniel Vetter67a54562012-10-20 20:57:45 +02005107 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 +03005108 I915_READ(regs.pp_on),
5109 I915_READ(regs.pp_off),
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005110 IS_BROXTON(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005111 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5112 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005113}
5114
Imre Deak335f7522016-08-10 14:07:32 +03005115static void intel_dp_pps_init(struct drm_device *dev,
5116 struct intel_dp *intel_dp)
5117{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005118 struct drm_i915_private *dev_priv = to_i915(dev);
5119
5120 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005121 vlv_initial_power_sequencer_setup(intel_dp);
5122 } else {
5123 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5124 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5125 }
5126}
5127
Vandana Kannanb33a2812015-02-13 15:33:03 +05305128/**
5129 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005130 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005131 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305132 * @refresh_rate: RR to be programmed
5133 *
5134 * This function gets called when refresh rate (RR) has to be changed from
5135 * one frequency to another. Switches can be between high and low RR
5136 * supported by the panel or to any other RR based on media playback (in
5137 * this case, RR value needs to be passed from user space).
5138 *
5139 * The caller of this function needs to take a lock on dev_priv->drrs.
5140 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005141static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5142 struct intel_crtc_state *crtc_state,
5143 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305144{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305145 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305146 struct intel_digital_port *dig_port = NULL;
5147 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005148 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305149 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305150
5151 if (refresh_rate <= 0) {
5152 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5153 return;
5154 }
5155
Vandana Kannan96178ee2015-01-10 02:25:56 +05305156 if (intel_dp == NULL) {
5157 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305158 return;
5159 }
5160
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005161 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005162 * FIXME: This needs proper synchronization with psr state for some
5163 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005164 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305165
Vandana Kannan96178ee2015-01-10 02:25:56 +05305166 dig_port = dp_to_dig_port(intel_dp);
5167 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005168 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305169
5170 if (!intel_crtc) {
5171 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5172 return;
5173 }
5174
Vandana Kannan96178ee2015-01-10 02:25:56 +05305175 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305176 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5177 return;
5178 }
5179
Vandana Kannan96178ee2015-01-10 02:25:56 +05305180 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5181 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305182 index = DRRS_LOW_RR;
5183
Vandana Kannan96178ee2015-01-10 02:25:56 +05305184 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305185 DRM_DEBUG_KMS(
5186 "DRRS requested for previously set RR...ignoring\n");
5187 return;
5188 }
5189
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005190 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305191 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5192 return;
5193 }
5194
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005195 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305196 switch (index) {
5197 case DRRS_HIGH_RR:
5198 intel_dp_set_m_n(intel_crtc, M1_N1);
5199 break;
5200 case DRRS_LOW_RR:
5201 intel_dp_set_m_n(intel_crtc, M2_N2);
5202 break;
5203 case DRRS_MAX_RR:
5204 default:
5205 DRM_ERROR("Unsupported refreshrate type\n");
5206 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005207 } else if (INTEL_GEN(dev_priv) > 6) {
5208 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005209 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305210
Ville Syrjälä649636e2015-09-22 19:50:01 +03005211 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305212 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005213 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305214 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5215 else
5216 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305217 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005218 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305219 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5220 else
5221 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305222 }
5223 I915_WRITE(reg, val);
5224 }
5225
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305226 dev_priv->drrs.refresh_rate_type = index;
5227
5228 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5229}
5230
Vandana Kannanb33a2812015-02-13 15:33:03 +05305231/**
5232 * intel_edp_drrs_enable - init drrs struct if supported
5233 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005234 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305235 *
5236 * Initializes frontbuffer_bits and drrs.dp
5237 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005238void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5239 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305240{
5241 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005242 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305243
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005244 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305245 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5246 return;
5247 }
5248
5249 mutex_lock(&dev_priv->drrs.mutex);
5250 if (WARN_ON(dev_priv->drrs.dp)) {
5251 DRM_ERROR("DRRS already enabled\n");
5252 goto unlock;
5253 }
5254
5255 dev_priv->drrs.busy_frontbuffer_bits = 0;
5256
5257 dev_priv->drrs.dp = intel_dp;
5258
5259unlock:
5260 mutex_unlock(&dev_priv->drrs.mutex);
5261}
5262
Vandana Kannanb33a2812015-02-13 15:33:03 +05305263/**
5264 * intel_edp_drrs_disable - Disable DRRS
5265 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005266 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305267 *
5268 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005269void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5270 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305271{
5272 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005273 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305274
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005275 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305276 return;
5277
5278 mutex_lock(&dev_priv->drrs.mutex);
5279 if (!dev_priv->drrs.dp) {
5280 mutex_unlock(&dev_priv->drrs.mutex);
5281 return;
5282 }
5283
5284 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005285 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5286 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305287
5288 dev_priv->drrs.dp = NULL;
5289 mutex_unlock(&dev_priv->drrs.mutex);
5290
5291 cancel_delayed_work_sync(&dev_priv->drrs.work);
5292}
5293
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305294static void intel_edp_drrs_downclock_work(struct work_struct *work)
5295{
5296 struct drm_i915_private *dev_priv =
5297 container_of(work, typeof(*dev_priv), drrs.work.work);
5298 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305299
Vandana Kannan96178ee2015-01-10 02:25:56 +05305300 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305301
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305302 intel_dp = dev_priv->drrs.dp;
5303
5304 if (!intel_dp)
5305 goto unlock;
5306
5307 /*
5308 * The delayed work can race with an invalidate hence we need to
5309 * recheck.
5310 */
5311
5312 if (dev_priv->drrs.busy_frontbuffer_bits)
5313 goto unlock;
5314
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005315 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5316 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5317
5318 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5319 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5320 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305321
5322unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305323 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305324}
5325
Vandana Kannanb33a2812015-02-13 15:33:03 +05305326/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305327 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005328 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305329 * @frontbuffer_bits: frontbuffer plane tracking bits
5330 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305331 * This function gets called everytime rendering on the given planes start.
5332 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305333 *
5334 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5335 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005336void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5337 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305338{
Vandana Kannana93fad02015-01-10 02:25:59 +05305339 struct drm_crtc *crtc;
5340 enum pipe pipe;
5341
Daniel Vetter9da7d692015-04-09 16:44:15 +02005342 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305343 return;
5344
Daniel Vetter88f933a2015-04-09 16:44:16 +02005345 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305346
Vandana Kannana93fad02015-01-10 02:25:59 +05305347 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005348 if (!dev_priv->drrs.dp) {
5349 mutex_unlock(&dev_priv->drrs.mutex);
5350 return;
5351 }
5352
Vandana Kannana93fad02015-01-10 02:25:59 +05305353 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5354 pipe = to_intel_crtc(crtc)->pipe;
5355
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005356 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5357 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5358
Ramalingam C0ddfd202015-06-15 20:50:05 +05305359 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005360 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005361 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5362 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305363
Vandana Kannana93fad02015-01-10 02:25:59 +05305364 mutex_unlock(&dev_priv->drrs.mutex);
5365}
5366
Vandana Kannanb33a2812015-02-13 15:33:03 +05305367/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305368 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005369 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305370 * @frontbuffer_bits: frontbuffer plane tracking bits
5371 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305372 * This function gets called every time rendering on the given planes has
5373 * completed or flip on a crtc is completed. So DRRS should be upclocked
5374 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5375 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305376 *
5377 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5378 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005379void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5380 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305381{
Vandana Kannana93fad02015-01-10 02:25:59 +05305382 struct drm_crtc *crtc;
5383 enum pipe pipe;
5384
Daniel Vetter9da7d692015-04-09 16:44:15 +02005385 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305386 return;
5387
Daniel Vetter88f933a2015-04-09 16:44:16 +02005388 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305389
Vandana Kannana93fad02015-01-10 02:25:59 +05305390 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005391 if (!dev_priv->drrs.dp) {
5392 mutex_unlock(&dev_priv->drrs.mutex);
5393 return;
5394 }
5395
Vandana Kannana93fad02015-01-10 02:25:59 +05305396 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5397 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005398
5399 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305400 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5401
Ramalingam C0ddfd202015-06-15 20:50:05 +05305402 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005403 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005404 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5405 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305406
5407 /*
5408 * flush also means no more activity hence schedule downclock, if all
5409 * other fbs are quiescent too
5410 */
5411 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305412 schedule_delayed_work(&dev_priv->drrs.work,
5413 msecs_to_jiffies(1000));
5414 mutex_unlock(&dev_priv->drrs.mutex);
5415}
5416
Vandana Kannanb33a2812015-02-13 15:33:03 +05305417/**
5418 * DOC: Display Refresh Rate Switching (DRRS)
5419 *
5420 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5421 * which enables swtching between low and high refresh rates,
5422 * dynamically, based on the usage scenario. This feature is applicable
5423 * for internal panels.
5424 *
5425 * Indication that the panel supports DRRS is given by the panel EDID, which
5426 * would list multiple refresh rates for one resolution.
5427 *
5428 * DRRS is of 2 types - static and seamless.
5429 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5430 * (may appear as a blink on screen) and is used in dock-undock scenario.
5431 * Seamless DRRS involves changing RR without any visual effect to the user
5432 * and can be used during normal system usage. This is done by programming
5433 * certain registers.
5434 *
5435 * Support for static/seamless DRRS may be indicated in the VBT based on
5436 * inputs from the panel spec.
5437 *
5438 * DRRS saves power by switching to low RR based on usage scenarios.
5439 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005440 * The implementation is based on frontbuffer tracking implementation. When
5441 * there is a disturbance on the screen triggered by user activity or a periodic
5442 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5443 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5444 * made.
5445 *
5446 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5447 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305448 *
5449 * DRRS can be further extended to support other internal panels and also
5450 * the scenario of video playback wherein RR is set based on the rate
5451 * requested by userspace.
5452 */
5453
5454/**
5455 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5456 * @intel_connector: eDP connector
5457 * @fixed_mode: preferred mode of panel
5458 *
5459 * This function is called only once at driver load to initialize basic
5460 * DRRS stuff.
5461 *
5462 * Returns:
5463 * Downclock mode if panel supports it, else return NULL.
5464 * DRRS support is determined by the presence of downclock mode (apart
5465 * from VBT setting).
5466 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305467static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305468intel_dp_drrs_init(struct intel_connector *intel_connector,
5469 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305470{
5471 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305472 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005473 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305474 struct drm_display_mode *downclock_mode = NULL;
5475
Daniel Vetter9da7d692015-04-09 16:44:15 +02005476 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5477 mutex_init(&dev_priv->drrs.mutex);
5478
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305479 if (INTEL_INFO(dev)->gen <= 6) {
5480 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5481 return NULL;
5482 }
5483
5484 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005485 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305486 return NULL;
5487 }
5488
5489 downclock_mode = intel_find_panel_downclock
5490 (dev, fixed_mode, connector);
5491
5492 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305493 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305494 return NULL;
5495 }
5496
Vandana Kannan96178ee2015-01-10 02:25:56 +05305497 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305498
Vandana Kannan96178ee2015-01-10 02:25:56 +05305499 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005500 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305501 return downclock_mode;
5502}
5503
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005504static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005505 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005506{
5507 struct drm_connector *connector = &intel_connector->base;
5508 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005509 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5510 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005511 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005512 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305513 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005514 bool has_dpcd;
5515 struct drm_display_mode *scan;
5516 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005517 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005518
5519 if (!is_edp(intel_dp))
5520 return true;
5521
Imre Deak97a824e12016-06-21 11:51:47 +03005522 /*
5523 * On IBX/CPT we may get here with LVDS already registered. Since the
5524 * driver uses the only internal power sequencer available for both
5525 * eDP and LVDS bail out early in this case to prevent interfering
5526 * with an already powered-on LVDS power sequencer.
5527 */
5528 if (intel_get_lvds_encoder(dev)) {
5529 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5530 DRM_INFO("LVDS was detected, not registering eDP\n");
5531
5532 return false;
5533 }
5534
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005535 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005536
5537 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005538 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005539 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005540
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005541 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005542
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005543 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005544 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005545
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005546 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005547 /* if this fails, presume the device is a ghost */
5548 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005549 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005550 }
5551
Daniel Vetter060c8772014-03-21 23:22:35 +01005552 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005553 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005554 if (edid) {
5555 if (drm_add_edid_modes(connector, edid)) {
5556 drm_mode_connector_update_edid_property(connector,
5557 edid);
5558 drm_edid_to_eld(connector, edid);
5559 } else {
5560 kfree(edid);
5561 edid = ERR_PTR(-EINVAL);
5562 }
5563 } else {
5564 edid = ERR_PTR(-ENOENT);
5565 }
5566 intel_connector->edid = edid;
5567
5568 /* prefer fixed mode from EDID if available */
5569 list_for_each_entry(scan, &connector->probed_modes, head) {
5570 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5571 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305572 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305573 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005574 break;
5575 }
5576 }
5577
5578 /* fallback to VBT if available for eDP */
5579 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5580 fixed_mode = drm_mode_duplicate(dev,
5581 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005582 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005583 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005584 connector->display_info.width_mm = fixed_mode->width_mm;
5585 connector->display_info.height_mm = fixed_mode->height_mm;
5586 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005587 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005588 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005589
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005590 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005591 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5592 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005593
5594 /*
5595 * Figure out the current pipe for the initial backlight setup.
5596 * If the current pipe isn't valid, try the PPS pipe, and if that
5597 * fails just assume pipe A.
5598 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005599 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6517d272014-11-07 11:16:02 +02005600 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5601 else
5602 pipe = PORT_TO_PIPE(intel_dp->DP);
5603
5604 if (pipe != PIPE_A && pipe != PIPE_B)
5605 pipe = intel_dp->pps_pipe;
5606
5607 if (pipe != PIPE_A && pipe != PIPE_B)
5608 pipe = PIPE_A;
5609
5610 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5611 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005612 }
5613
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305614 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005615 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005616 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005617
5618 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005619
5620out_vdd_off:
5621 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5622 /*
5623 * vdd might still be enabled do to the delayed vdd off.
5624 * Make sure vdd is actually turned off here.
5625 */
5626 pps_lock(intel_dp);
5627 edp_panel_vdd_off_sync(intel_dp);
5628 pps_unlock(intel_dp);
5629
5630 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005631}
5632
Paulo Zanoni16c25532013-06-12 17:27:25 -03005633bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005634intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5635 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005636{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005637 struct drm_connector *connector = &intel_connector->base;
5638 struct intel_dp *intel_dp = &intel_dig_port->dp;
5639 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5640 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005641 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005642 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005643 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005644
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005645 if (WARN(intel_dig_port->max_lanes < 1,
5646 "Not enough lanes (%d) for DP on port %c\n",
5647 intel_dig_port->max_lanes, port_name(port)))
5648 return false;
5649
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005650 intel_dp->pps_pipe = INVALID_PIPE;
5651
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005652 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005653 if (INTEL_INFO(dev)->gen >= 9)
5654 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005655 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005656 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005657 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005658 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5659 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005660 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005661
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005662 if (INTEL_INFO(dev)->gen >= 9)
5663 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5664 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005665 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005666
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005667 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005668 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5669
Daniel Vetter07679352012-09-06 22:15:42 +02005670 /* Preserve the current hw state. */
5671 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005672 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005673
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005674 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305675 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005676 else
5677 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005678
Imre Deakf7d24902013-05-08 13:14:05 +03005679 /*
5680 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5681 * for DP the encoder type can be set by the caller to
5682 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5683 */
5684 if (type == DRM_MODE_CONNECTOR_eDP)
5685 intel_encoder->type = INTEL_OUTPUT_EDP;
5686
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005687 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005688 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005689 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005690 return false;
5691
Imre Deake7281ea2013-05-08 13:14:08 +03005692 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5693 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5694 port_name(port));
5695
Adam Jacksonb3295302010-07-16 14:46:28 -04005696 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005697 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5698
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005699 connector->interlace_allowed = true;
5700 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005701
Mika Kaholab6339582016-09-09 14:10:52 +03005702 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005703
Daniel Vetter66a92782012-07-12 20:08:18 +02005704 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005705 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005706
Chris Wilsondf0e9242010-09-09 16:20:55 +01005707 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005708
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005709 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005710 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5711 else
5712 intel_connector->get_hw_state = intel_connector_get_hw_state;
5713
Jani Nikula0b998362014-03-14 16:51:17 +02005714 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005715 switch (port) {
5716 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005717 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005718 break;
5719 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005720 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005721 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305722 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005723 break;
5724 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005725 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005726 break;
5727 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005728 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005729 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005730 case PORT_E:
5731 intel_encoder->hpd_pin = HPD_PORT_E;
5732 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005733 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005734 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005735 }
5736
Dave Airlie0e32b392014-05-02 14:02:48 +10005737 /* init MST on ports that can support it */
Ville Syrjäläf8e58dd2016-06-22 21:56:59 +03005738 if (HAS_DP_MST(dev) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005739 (port == PORT_B || port == PORT_C || port == PORT_D))
5740 intel_dp_mst_encoder_init(intel_dig_port,
5741 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005742
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005743 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005744 intel_dp_aux_fini(intel_dp);
5745 intel_dp_mst_encoder_cleanup(intel_dig_port);
5746 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005747 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005748
Chris Wilsonf6849602010-09-19 09:29:33 +01005749 intel_dp_add_properties(intel_dp, connector);
5750
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005751 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5752 * 0xd. Failure to do so will result in spurious interrupts being
5753 * generated on the port when a cable is not attached.
5754 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005755 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005756 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5757 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5758 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005759
5760 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005761
5762fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005763 drm_connector_cleanup(connector);
5764
5765 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005766}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005767
Chris Wilson457c52d2016-06-01 08:27:50 +01005768bool intel_dp_init(struct drm_device *dev,
5769 i915_reg_t output_reg,
5770 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005771{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005772 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005773 struct intel_digital_port *intel_dig_port;
5774 struct intel_encoder *intel_encoder;
5775 struct drm_encoder *encoder;
5776 struct intel_connector *intel_connector;
5777
Daniel Vetterb14c5672013-09-19 12:18:32 +02005778 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005779 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005780 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005781
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005782 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305783 if (!intel_connector)
5784 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005785
5786 intel_encoder = &intel_dig_port->base;
5787 encoder = &intel_encoder->base;
5788
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305789 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005790 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305791 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005792
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005793 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005794 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005795 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005796 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005797 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005798 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005799 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005800 intel_encoder->pre_enable = chv_pre_enable_dp;
5801 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005802 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005803 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005804 } else if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005805 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005806 intel_encoder->pre_enable = vlv_pre_enable_dp;
5807 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005808 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005809 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005810 intel_encoder->pre_enable = g4x_pre_enable_dp;
5811 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005812 if (INTEL_INFO(dev)->gen >= 5)
5813 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005814 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005815
Paulo Zanoni174edf12012-10-26 19:05:50 -02005816 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005817 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005818 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005819
Ville Syrjäläcca05022016-06-22 21:57:06 +03005820 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005821 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005822 if (port == PORT_D)
5823 intel_encoder->crtc_mask = 1 << 2;
5824 else
5825 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5826 } else {
5827 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5828 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005829 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005830 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005831
Dave Airlie13cf5502014-06-18 11:29:35 +10005832 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005833 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005834
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305835 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5836 goto err_init_connector;
5837
Chris Wilson457c52d2016-06-01 08:27:50 +01005838 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305839
5840err_init_connector:
5841 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305842err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305843 kfree(intel_connector);
5844err_connector_alloc:
5845 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005846 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005847}
Dave Airlie0e32b392014-05-02 14:02:48 +10005848
5849void intel_dp_mst_suspend(struct drm_device *dev)
5850{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005851 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005852 int i;
5853
5854 /* disable MST */
5855 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005856 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005857
5858 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005859 continue;
5860
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005861 if (intel_dig_port->dp.is_mst)
5862 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005863 }
5864}
5865
5866void intel_dp_mst_resume(struct drm_device *dev)
5867{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005868 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005869 int i;
5870
5871 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005872 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005873 int ret;
5874
5875 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005876 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005877
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005878 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5879 if (ret)
5880 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005881 }
5882}