Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 30 | #include <linux/export.h> |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 31 | #include <linux/notifier.h> |
| 32 | #include <linux/reboot.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 33 | #include <drm/drmP.h> |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 34 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drm_crtc.h> |
| 36 | #include <drm/drm_crtc_helper.h> |
| 37 | #include <drm/drm_edid.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 38 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 39 | #include <drm/i915_drm.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 40 | #include "i915_drv.h" |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 41 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 42 | #define DP_LINK_CHECK_TIMEOUT (10 * 1000) |
| 43 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 44 | /* 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 Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 50 | struct dp_link_dpll { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 51 | int clock; |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 52 | struct dpll dpll; |
| 53 | }; |
| 54 | |
| 55 | static const struct dp_link_dpll gen4_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 56 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 57 | { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 58 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 59 | { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } } |
| 60 | }; |
| 61 | |
| 62 | static const struct dp_link_dpll pch_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 63 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 64 | { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 65 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 66 | { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } } |
| 67 | }; |
| 68 | |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 69 | static const struct dp_link_dpll vlv_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 70 | { 162000, |
Chon Ming Lee | 58f6e63 | 2013-09-25 15:47:51 +0800 | [diff] [blame] | 71 | { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 72 | { 270000, |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 73 | { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } } |
| 74 | }; |
| 75 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 76 | /* |
| 77 | * CHV supports eDP 1.4 that have more link rates. |
| 78 | * Below only provides the fixed rate but exclude variable rate. |
| 79 | */ |
| 80 | static 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ä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 86 | { 162000, /* m2_int = 32, m2_fraction = 1677722 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 87 | { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 88 | { 270000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 89 | { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 90 | { 540000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 91 | { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } } |
| 92 | }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 93 | |
Sonika Jindal | 64987fc | 2015-05-26 17:50:13 +0530 | [diff] [blame] | 94 | static const int bxt_rates[] = { 162000, 216000, 243000, 270000, |
| 95 | 324000, 432000, 540000 }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 96 | static const int skl_rates[] = { 162000, 216000, 270000, |
Ville Syrjälä | f4896f1 | 2015-03-12 17:10:27 +0200 | [diff] [blame] | 97 | 324000, 432000, 540000 }; |
| 98 | static const int default_rates[] = { 162000, 270000, 540000 }; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 99 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 100 | /** |
| 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 | */ |
| 107 | static bool is_edp(struct intel_dp *intel_dp) |
| 108 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 109 | 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 Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 114 | static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp) |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 115 | { |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 116 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 117 | |
| 118 | return intel_dig_port->base.base.dev; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 121 | static struct intel_dp *intel_attached_dp(struct drm_connector *connector) |
| 122 | { |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 123 | return enc_to_intel_dp(&intel_attached_encoder(connector)->base); |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 126 | static void intel_dp_link_down(struct intel_dp *intel_dp); |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 127 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 128 | static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 129 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 130 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 131 | enum pipe pipe); |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 132 | static void intel_dp_unset_edid(struct intel_dp *intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 133 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 134 | static int |
| 135 | intel_dp_max_link_bw(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 136 | { |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 137 | int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 138 | |
| 139 | switch (max_link_bw) { |
| 140 | case DP_LINK_BW_1_62: |
| 141 | case DP_LINK_BW_2_7: |
Ville Syrjälä | 1db10e2 | 2015-03-12 17:10:32 +0200 | [diff] [blame] | 142 | case DP_LINK_BW_5_4: |
Imre Deak | d4eead5 | 2013-07-09 17:05:26 +0300 | [diff] [blame] | 143 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 144 | default: |
Imre Deak | d4eead5 | 2013-07-09 17:05:26 +0300 | [diff] [blame] | 145 | WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n", |
| 146 | max_link_bw); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 147 | max_link_bw = DP_LINK_BW_1_62; |
| 148 | break; |
| 149 | } |
| 150 | return max_link_bw; |
| 151 | } |
| 152 | |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 153 | static 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 Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 156 | u8 source_max, sink_max; |
| 157 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 158 | source_max = intel_dig_port->max_lanes; |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 159 | sink_max = intel_dp->max_sink_lane_count; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 160 | |
| 161 | return min(source_max, sink_max); |
| 162 | } |
| 163 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 164 | int |
Keith Packard | c898261 | 2012-01-25 08:16:25 -0800 | [diff] [blame] | 165 | intel_dp_link_required(int pixel_clock, int bpp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 166 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 167 | /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */ |
| 168 | return DIV_ROUND_UP(pixel_clock * bpp, 8); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 171 | int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 172 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 173 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 174 | /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the |
| 175 | * link rate that is generally expressed in Gbps. Since, 8 bits of data |
| 176 | * is transmitted every LS_Clk per lane, there is no need to account for |
| 177 | * the channel encoding that is done in the PHY layer here. |
| 178 | */ |
| 179 | |
| 180 | return max_link_clock * max_lanes; |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 181 | } |
| 182 | |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 183 | static int |
| 184 | intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp) |
| 185 | { |
| 186 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 187 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 188 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 189 | int max_dotclk = dev_priv->max_dotclk_freq; |
| 190 | int ds_max_dotclk; |
| 191 | |
| 192 | int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 193 | |
| 194 | if (type != DP_DS_PORT_TYPE_VGA) |
| 195 | return max_dotclk; |
| 196 | |
| 197 | ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd, |
| 198 | intel_dp->downstream_ports); |
| 199 | |
| 200 | if (ds_max_dotclk != 0) |
| 201 | max_dotclk = min(max_dotclk, ds_max_dotclk); |
| 202 | |
| 203 | return max_dotclk; |
| 204 | } |
| 205 | |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 206 | static int |
| 207 | intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates) |
| 208 | { |
| 209 | if (intel_dp->num_sink_rates) { |
| 210 | *sink_rates = intel_dp->sink_rates; |
| 211 | return intel_dp->num_sink_rates; |
| 212 | } |
| 213 | |
| 214 | *sink_rates = default_rates; |
| 215 | |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 216 | return (intel_dp->max_sink_link_bw >> 3) + 1; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static int |
| 220 | intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates) |
| 221 | { |
| 222 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 223 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 224 | int size; |
| 225 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 226 | if (IS_GEN9_LP(dev_priv)) { |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 227 | *source_rates = bxt_rates; |
| 228 | size = ARRAY_SIZE(bxt_rates); |
| 229 | } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 230 | *source_rates = skl_rates; |
| 231 | size = ARRAY_SIZE(skl_rates); |
| 232 | } else { |
| 233 | *source_rates = default_rates; |
| 234 | size = ARRAY_SIZE(default_rates); |
| 235 | } |
| 236 | |
| 237 | /* This depends on the fact that 5.4 is last value in the array */ |
| 238 | if (!intel_dp_source_supports_hbr2(intel_dp)) |
| 239 | size--; |
| 240 | |
| 241 | return size; |
| 242 | } |
| 243 | |
| 244 | static int intersect_rates(const int *source_rates, int source_len, |
| 245 | const int *sink_rates, int sink_len, |
| 246 | int *common_rates) |
| 247 | { |
| 248 | int i = 0, j = 0, k = 0; |
| 249 | |
| 250 | while (i < source_len && j < sink_len) { |
| 251 | if (source_rates[i] == sink_rates[j]) { |
| 252 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
| 253 | return k; |
| 254 | common_rates[k] = source_rates[i]; |
| 255 | ++k; |
| 256 | ++i; |
| 257 | ++j; |
| 258 | } else if (source_rates[i] < sink_rates[j]) { |
| 259 | ++i; |
| 260 | } else { |
| 261 | ++j; |
| 262 | } |
| 263 | } |
| 264 | return k; |
| 265 | } |
| 266 | |
| 267 | static int intel_dp_common_rates(struct intel_dp *intel_dp, |
| 268 | int *common_rates) |
| 269 | { |
| 270 | const int *source_rates, *sink_rates; |
| 271 | int source_len, sink_len; |
| 272 | |
| 273 | sink_len = intel_dp_sink_rates(intel_dp, &sink_rates); |
| 274 | source_len = intel_dp_source_rates(intel_dp, &source_rates); |
| 275 | |
| 276 | return intersect_rates(source_rates, source_len, |
| 277 | sink_rates, sink_len, |
| 278 | common_rates); |
| 279 | } |
| 280 | |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 281 | static int intel_dp_link_rate_index(struct intel_dp *intel_dp, |
| 282 | int *common_rates, int link_rate) |
| 283 | { |
| 284 | int common_len; |
| 285 | int index; |
| 286 | |
| 287 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
| 288 | for (index = 0; index < common_len; index++) { |
| 289 | if (link_rate == common_rates[common_len - index - 1]) |
| 290 | return common_len - index - 1; |
| 291 | } |
| 292 | |
| 293 | return -1; |
| 294 | } |
| 295 | |
| 296 | int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, |
| 297 | int link_rate, uint8_t lane_count) |
| 298 | { |
| 299 | int common_rates[DP_MAX_SUPPORTED_RATES]; |
| 300 | int link_rate_index; |
| 301 | |
| 302 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 303 | common_rates, |
| 304 | link_rate); |
| 305 | if (link_rate_index > 0) { |
| 306 | intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]); |
| 307 | intel_dp->max_sink_lane_count = lane_count; |
| 308 | } else if (lane_count > 1) { |
| 309 | intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp); |
| 310 | intel_dp->max_sink_lane_count = lane_count >> 1; |
| 311 | } else { |
| 312 | DRM_ERROR("Link Training Unsuccessful\n"); |
| 313 | return -1; |
| 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 319 | static enum drm_mode_status |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 320 | intel_dp_mode_valid(struct drm_connector *connector, |
| 321 | struct drm_display_mode *mode) |
| 322 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 323 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 324 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 325 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 326 | int target_clock = mode->clock; |
| 327 | int max_rate, mode_rate, max_lanes, max_link_clock; |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 328 | int max_dotclk; |
| 329 | |
| 330 | max_dotclk = intel_dp_downstream_max_dotclock(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 331 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 332 | if (is_edp(intel_dp) && fixed_mode) { |
| 333 | if (mode->hdisplay > fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 334 | return MODE_PANEL; |
| 335 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 336 | if (mode->vdisplay > fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 337 | return MODE_PANEL; |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 338 | |
| 339 | target_clock = fixed_mode->clock; |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 342 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 343 | max_lanes = intel_dp_max_lane_count(intel_dp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 344 | |
| 345 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); |
| 346 | mode_rate = intel_dp_link_required(target_clock, 18); |
| 347 | |
Mika Kahola | 799487f | 2016-02-02 15:16:38 +0200 | [diff] [blame] | 348 | if (mode_rate > max_rate || target_clock > max_dotclk) |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 349 | return MODE_CLOCK_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 350 | |
| 351 | if (mode->clock < 10000) |
| 352 | return MODE_CLOCK_LOW; |
| 353 | |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 354 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 355 | return MODE_H_ILLEGAL; |
| 356 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 357 | return MODE_OK; |
| 358 | } |
| 359 | |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 360 | uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 361 | { |
| 362 | int i; |
| 363 | uint32_t v = 0; |
| 364 | |
| 365 | if (src_bytes > 4) |
| 366 | src_bytes = 4; |
| 367 | for (i = 0; i < src_bytes; i++) |
| 368 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 369 | return v; |
| 370 | } |
| 371 | |
Damien Lespiau | c2af70e | 2015-02-10 19:32:23 +0000 | [diff] [blame] | 372 | static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 373 | { |
| 374 | int i; |
| 375 | if (dst_bytes > 4) |
| 376 | dst_bytes = 4; |
| 377 | for (i = 0; i < dst_bytes; i++) |
| 378 | dst[i] = src >> ((3-i) * 8); |
| 379 | } |
| 380 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 381 | static void |
| 382 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 383 | struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 384 | static void |
| 385 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 386 | struct intel_dp *intel_dp); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 387 | static void |
| 388 | intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 389 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 390 | static void pps_lock(struct intel_dp *intel_dp) |
| 391 | { |
| 392 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 393 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 394 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 395 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 396 | enum intel_display_power_domain power_domain; |
| 397 | |
| 398 | /* |
| 399 | * See vlv_power_sequencer_reset() why we need |
| 400 | * a power domain reference here. |
| 401 | */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 402 | power_domain = intel_display_port_aux_power_domain(encoder); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 403 | intel_display_power_get(dev_priv, power_domain); |
| 404 | |
| 405 | mutex_lock(&dev_priv->pps_mutex); |
| 406 | } |
| 407 | |
| 408 | static void pps_unlock(struct intel_dp *intel_dp) |
| 409 | { |
| 410 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 411 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 412 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 413 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 414 | enum intel_display_power_domain power_domain; |
| 415 | |
| 416 | mutex_unlock(&dev_priv->pps_mutex); |
| 417 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 418 | power_domain = intel_display_port_aux_power_domain(encoder); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 419 | intel_display_power_put(dev_priv, power_domain); |
| 420 | } |
| 421 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 422 | static void |
| 423 | vlv_power_sequencer_kick(struct intel_dp *intel_dp) |
| 424 | { |
| 425 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 426 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 427 | enum pipe pipe = intel_dp->pps_pipe; |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 428 | bool pll_enabled, release_cl_override = false; |
| 429 | enum dpio_phy phy = DPIO_PHY(pipe); |
| 430 | enum dpio_channel ch = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 431 | uint32_t DP; |
| 432 | |
| 433 | if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN, |
| 434 | "skipping pipe %c power seqeuncer kick due to port %c being active\n", |
| 435 | pipe_name(pipe), port_name(intel_dig_port->port))) |
| 436 | return; |
| 437 | |
| 438 | DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n", |
| 439 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 440 | |
| 441 | /* Preserve the BIOS-computed detected bit. This is |
| 442 | * supposed to be read-only. |
| 443 | */ |
| 444 | DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
| 445 | DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
| 446 | DP |= DP_PORT_WIDTH(1); |
| 447 | DP |= DP_LINK_TRAIN_PAT_1; |
| 448 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 449 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 450 | DP |= DP_PIPE_SELECT_CHV(pipe); |
| 451 | else if (pipe == PIPE_B) |
| 452 | DP |= DP_PIPEB_SELECT; |
| 453 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 454 | pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE; |
| 455 | |
| 456 | /* |
| 457 | * The DPLL for the pipe must be enabled for this to work. |
| 458 | * So enable temporarily it if it's not already enabled. |
| 459 | */ |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 460 | if (!pll_enabled) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 461 | release_cl_override = IS_CHERRYVIEW(dev_priv) && |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 462 | !chv_phy_powergate_ch(dev_priv, phy, ch, true); |
| 463 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 464 | if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ? |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 465 | &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) { |
| 466 | DRM_ERROR("Failed to force on pll for pipe %c!\n", |
| 467 | pipe_name(pipe)); |
| 468 | return; |
| 469 | } |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 470 | } |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 471 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 472 | /* |
| 473 | * Similar magic as in intel_dp_enable_port(). |
| 474 | * We _must_ do this port enable + disable trick |
| 475 | * to make this power seqeuencer lock onto the port. |
| 476 | * Otherwise even VDD force bit won't work. |
| 477 | */ |
| 478 | I915_WRITE(intel_dp->output_reg, DP); |
| 479 | POSTING_READ(intel_dp->output_reg); |
| 480 | |
| 481 | I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN); |
| 482 | POSTING_READ(intel_dp->output_reg); |
| 483 | |
| 484 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
| 485 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 486 | |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 487 | if (!pll_enabled) { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 488 | vlv_force_pll_off(dev_priv, pipe); |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 489 | |
| 490 | if (release_cl_override) |
| 491 | chv_phy_powergate_ch(dev_priv, phy, ch, false); |
| 492 | } |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 493 | } |
| 494 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 495 | static enum pipe |
| 496 | vlv_power_sequencer_pipe(struct intel_dp *intel_dp) |
| 497 | { |
| 498 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 499 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 500 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 501 | struct intel_encoder *encoder; |
| 502 | unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 503 | enum pipe pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 504 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 505 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 506 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 507 | /* We should never land here with regular DP ports */ |
| 508 | WARN_ON(!is_edp(intel_dp)); |
| 509 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 510 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 511 | return intel_dp->pps_pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 512 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 513 | /* |
| 514 | * We don't have power sequencer currently. |
| 515 | * Pick one that's not used by other ports. |
| 516 | */ |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 517 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 518 | struct intel_dp *tmp; |
| 519 | |
| 520 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 521 | continue; |
| 522 | |
| 523 | tmp = enc_to_intel_dp(&encoder->base); |
| 524 | |
| 525 | if (tmp->pps_pipe != INVALID_PIPE) |
| 526 | pipes &= ~(1 << tmp->pps_pipe); |
| 527 | } |
| 528 | |
| 529 | /* |
| 530 | * Didn't find one. This should not happen since there |
| 531 | * are two power sequencers and up to two eDP ports. |
| 532 | */ |
| 533 | if (WARN_ON(pipes == 0)) |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 534 | pipe = PIPE_A; |
| 535 | else |
| 536 | pipe = ffs(pipes) - 1; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 537 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 538 | vlv_steal_power_sequencer(dev, pipe); |
| 539 | intel_dp->pps_pipe = pipe; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 540 | |
| 541 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", |
| 542 | pipe_name(intel_dp->pps_pipe), |
| 543 | port_name(intel_dig_port->port)); |
| 544 | |
| 545 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 546 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
| 547 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 548 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 549 | /* |
| 550 | * Even vdd force doesn't work until we've made |
| 551 | * the power sequencer lock in on the port. |
| 552 | */ |
| 553 | vlv_power_sequencer_kick(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 554 | |
| 555 | return intel_dp->pps_pipe; |
| 556 | } |
| 557 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 558 | static int |
| 559 | bxt_power_sequencer_idx(struct intel_dp *intel_dp) |
| 560 | { |
| 561 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 562 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 563 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 564 | |
| 565 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 566 | |
| 567 | /* We should never land here with regular DP ports */ |
| 568 | WARN_ON(!is_edp(intel_dp)); |
| 569 | |
| 570 | /* |
| 571 | * TODO: BXT has 2 PPS instances. The correct port->PPS instance |
| 572 | * mapping needs to be retrieved from VBT, for now just hard-code to |
| 573 | * use instance #0 always. |
| 574 | */ |
| 575 | if (!intel_dp->pps_reset) |
| 576 | return 0; |
| 577 | |
| 578 | intel_dp->pps_reset = false; |
| 579 | |
| 580 | /* |
| 581 | * Only the HW needs to be reprogrammed, the SW state is fixed and |
| 582 | * has been setup during connector init. |
| 583 | */ |
| 584 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); |
| 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 589 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
| 590 | enum pipe pipe); |
| 591 | |
| 592 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, |
| 593 | enum pipe pipe) |
| 594 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 595 | return I915_READ(PP_STATUS(pipe)) & PP_ON; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, |
| 599 | enum pipe pipe) |
| 600 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 601 | return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, |
| 605 | enum pipe pipe) |
| 606 | { |
| 607 | return true; |
| 608 | } |
| 609 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 610 | static enum pipe |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 611 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
| 612 | enum port port, |
| 613 | vlv_pipe_check pipe_check) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 614 | { |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 615 | enum pipe pipe; |
| 616 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 617 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 618 | u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) & |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 619 | PANEL_PORT_SELECT_MASK; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 620 | |
| 621 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) |
| 622 | continue; |
| 623 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 624 | if (!pipe_check(dev_priv, pipe)) |
| 625 | continue; |
| 626 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 627 | return pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 628 | } |
| 629 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 630 | return INVALID_PIPE; |
| 631 | } |
| 632 | |
| 633 | static void |
| 634 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) |
| 635 | { |
| 636 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 637 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 638 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 639 | enum port port = intel_dig_port->port; |
| 640 | |
| 641 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 642 | |
| 643 | /* try to find a pipe with this port selected */ |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 644 | /* first pick one where the panel is on */ |
| 645 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 646 | vlv_pipe_has_pp_on); |
| 647 | /* didn't find one? pick one where vdd is on */ |
| 648 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 649 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 650 | vlv_pipe_has_vdd_on); |
| 651 | /* didn't find one? pick one with just the correct port */ |
| 652 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 653 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 654 | vlv_pipe_any); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 655 | |
| 656 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ |
| 657 | if (intel_dp->pps_pipe == INVALID_PIPE) { |
| 658 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", |
| 659 | port_name(port)); |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
| 664 | port_name(port), pipe_name(intel_dp->pps_pipe)); |
| 665 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 666 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
| 667 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 668 | } |
| 669 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 670 | void intel_power_sequencer_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 671 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 672 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 673 | struct intel_encoder *encoder; |
| 674 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 675 | if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 676 | !IS_GEN9_LP(dev_priv))) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 677 | return; |
| 678 | |
| 679 | /* |
| 680 | * We can't grab pps_mutex here due to deadlock with power_domain |
| 681 | * mutex when power_domain functions are called while holding pps_mutex. |
| 682 | * That also means that in order to use pps_pipe the code needs to |
| 683 | * hold both a power domain reference and pps_mutex, and the power domain |
| 684 | * reference get/put must be done while _not_ holding pps_mutex. |
| 685 | * pps_{lock,unlock}() do these steps in the correct order, so one |
| 686 | * should use them always. |
| 687 | */ |
| 688 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 689 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 690 | struct intel_dp *intel_dp; |
| 691 | |
| 692 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 693 | continue; |
| 694 | |
| 695 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 696 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 697 | intel_dp->pps_reset = true; |
| 698 | else |
| 699 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 700 | } |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 701 | } |
| 702 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 703 | struct pps_registers { |
| 704 | i915_reg_t pp_ctrl; |
| 705 | i915_reg_t pp_stat; |
| 706 | i915_reg_t pp_on; |
| 707 | i915_reg_t pp_off; |
| 708 | i915_reg_t pp_div; |
| 709 | }; |
| 710 | |
| 711 | static void intel_pps_get_registers(struct drm_i915_private *dev_priv, |
| 712 | struct intel_dp *intel_dp, |
| 713 | struct pps_registers *regs) |
| 714 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 715 | int pps_idx = 0; |
| 716 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 717 | memset(regs, 0, sizeof(*regs)); |
| 718 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 719 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 720 | pps_idx = bxt_power_sequencer_idx(intel_dp); |
| 721 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 722 | pps_idx = vlv_power_sequencer_pipe(intel_dp); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 723 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 724 | regs->pp_ctrl = PP_CONTROL(pps_idx); |
| 725 | regs->pp_stat = PP_STATUS(pps_idx); |
| 726 | regs->pp_on = PP_ON_DELAYS(pps_idx); |
| 727 | regs->pp_off = PP_OFF_DELAYS(pps_idx); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 728 | if (!IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 729 | regs->pp_div = PP_DIVISOR(pps_idx); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 730 | } |
| 731 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 732 | static i915_reg_t |
| 733 | _pp_ctrl_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 734 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 735 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 736 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 737 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 738 | ®s); |
| 739 | |
| 740 | return regs.pp_ctrl; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 741 | } |
| 742 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 743 | static i915_reg_t |
| 744 | _pp_stat_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 745 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 746 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 747 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 748 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 749 | ®s); |
| 750 | |
| 751 | return regs.pp_stat; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 752 | } |
| 753 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 754 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
| 755 | This function only applicable when panel PM state is not to be tracked */ |
| 756 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, |
| 757 | void *unused) |
| 758 | { |
| 759 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), |
| 760 | edp_notifier); |
| 761 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 762 | struct drm_i915_private *dev_priv = to_i915(dev); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 763 | |
| 764 | if (!is_edp(intel_dp) || code != SYS_RESTART) |
| 765 | return 0; |
| 766 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 767 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 768 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 769 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 770 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 771 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 772 | u32 pp_div; |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 773 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 774 | pp_ctrl_reg = PP_CONTROL(pipe); |
| 775 | pp_div_reg = PP_DIVISOR(pipe); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 776 | pp_div = I915_READ(pp_div_reg); |
| 777 | pp_div &= PP_REFERENCE_DIVIDER_MASK; |
| 778 | |
| 779 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ |
| 780 | I915_WRITE(pp_div_reg, pp_div | 0x1F); |
| 781 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 782 | msleep(intel_dp->panel_power_cycle_delay); |
| 783 | } |
| 784 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 785 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 786 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 787 | return 0; |
| 788 | } |
| 789 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 790 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 791 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 792 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 793 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 794 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 795 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 796 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 797 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 798 | intel_dp->pps_pipe == INVALID_PIPE) |
| 799 | return false; |
| 800 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 801 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 804 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 805 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 806 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 807 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 808 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 809 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 810 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 811 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 812 | intel_dp->pps_pipe == INVALID_PIPE) |
| 813 | return false; |
| 814 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 815 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 818 | static void |
| 819 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 820 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 821 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 822 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 823 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 824 | if (!is_edp(intel_dp)) |
| 825 | return; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 826 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 827 | if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) { |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 828 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 829 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 830 | I915_READ(_pp_stat_reg(intel_dp)), |
| 831 | I915_READ(_pp_ctrl_reg(intel_dp))); |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 835 | static uint32_t |
| 836 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) |
| 837 | { |
| 838 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 839 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 840 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 841 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 842 | uint32_t status; |
| 843 | bool done; |
| 844 | |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 845 | #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 846 | if (has_aux_irq) |
Paulo Zanoni | b18ac46 | 2013-02-18 19:00:24 -0300 | [diff] [blame] | 847 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
Imre Deak | 3598706 | 2013-05-21 20:03:20 +0300 | [diff] [blame] | 848 | msecs_to_jiffies_timeout(10)); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 849 | else |
Imre Deak | 713a6b66 | 2016-06-28 13:37:33 +0300 | [diff] [blame] | 850 | done = wait_for(C, 10) == 0; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 851 | if (!done) |
| 852 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", |
| 853 | has_aux_irq); |
| 854 | #undef C |
| 855 | |
| 856 | return status; |
| 857 | } |
| 858 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 859 | static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 860 | { |
| 861 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 862 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 863 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 864 | if (index) |
| 865 | return 0; |
| 866 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 867 | /* |
| 868 | * The clock divider is based off the hrawclk, and would like to run at |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 869 | * 2MHz. So, take the hrawclk value and divide by 2000 and use that |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 870 | */ |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 871 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 875 | { |
| 876 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 877 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 878 | |
| 879 | if (index) |
| 880 | return 0; |
| 881 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 882 | /* |
| 883 | * The clock divider is based off the cdclk or PCH rawclk, and would |
| 884 | * like to run at 2MHz. So, take the cdclk or PCH rawclk value and |
| 885 | * divide by 2000 and use that |
| 886 | */ |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 887 | if (intel_dig_port->port == PORT_A) |
Ville Syrjälä | fce18c4 | 2015-11-30 16:23:46 +0200 | [diff] [blame] | 888 | return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 889 | else |
| 890 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 894 | { |
| 895 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 896 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 897 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 898 | if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) { |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 899 | /* Workaround for non-ULT HSW */ |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 900 | switch (index) { |
| 901 | case 0: return 63; |
| 902 | case 1: return 72; |
| 903 | default: return 0; |
| 904 | } |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 905 | } |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 906 | |
| 907 | return ilk_get_aux_clock_divider(intel_dp, index); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 908 | } |
| 909 | |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 910 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 911 | { |
| 912 | /* |
| 913 | * SKL doesn't need us to program the AUX clock divider (Hardware will |
| 914 | * derive the clock from CDCLK automatically). We still implement the |
| 915 | * get_aux_clock_divider vfunc to plug-in into the existing code. |
| 916 | */ |
| 917 | return index ? 0 : 1; |
| 918 | } |
| 919 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 920 | static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 921 | bool has_aux_irq, |
| 922 | int send_bytes, |
| 923 | uint32_t aux_clock_divider) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 924 | { |
| 925 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 926 | struct drm_i915_private *dev_priv = |
| 927 | to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 928 | uint32_t precharge, timeout; |
| 929 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 930 | if (IS_GEN6(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 931 | precharge = 3; |
| 932 | else |
| 933 | precharge = 5; |
| 934 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 935 | if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 936 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
| 937 | else |
| 938 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; |
| 939 | |
| 940 | return DP_AUX_CH_CTL_SEND_BUSY | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 941 | DP_AUX_CH_CTL_DONE | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 942 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 943 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 944 | timeout | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 945 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 946 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 947 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 948 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 951 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 952 | bool has_aux_irq, |
| 953 | int send_bytes, |
| 954 | uint32_t unused) |
| 955 | { |
| 956 | return DP_AUX_CH_CTL_SEND_BUSY | |
| 957 | DP_AUX_CH_CTL_DONE | |
| 958 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
| 959 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 960 | DP_AUX_CH_CTL_TIME_OUT_1600us | |
| 961 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
| 962 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 963 | DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 964 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); |
| 965 | } |
| 966 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 967 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 968 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
Daniel Vetter | bd9f74a | 2014-10-02 09:45:35 +0200 | [diff] [blame] | 969 | const uint8_t *send, int send_bytes, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 970 | uint8_t *recv, int recv_size) |
| 971 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 972 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 973 | struct drm_i915_private *dev_priv = |
| 974 | to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 975 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 976 | uint32_t aux_clock_divider; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 977 | int i, ret, recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 978 | uint32_t status; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 979 | int try, clock = 0; |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 980 | bool has_aux_irq = HAS_AUX_IRQ(dev_priv); |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 981 | bool vdd; |
| 982 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 983 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 984 | |
Ville Syrjälä | 72c3500 | 2014-08-18 22:16:00 +0300 | [diff] [blame] | 985 | /* |
| 986 | * We will be called with VDD already enabled for dpcd/edid/oui reads. |
| 987 | * In such cases we want to leave VDD enabled and it's up to upper layers |
| 988 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off |
| 989 | * ourselves. |
| 990 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 991 | vdd = edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 992 | |
| 993 | /* dp aux is extremely sensitive to irq latency, hence request the |
| 994 | * lowest possible wakeup latency and so prevent the cpu from going into |
| 995 | * deep sleep states. |
| 996 | */ |
| 997 | pm_qos_update_request(&dev_priv->pm_qos, 0); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 998 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 999 | intel_dp_check_edp(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1000 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1001 | /* Try to wait for any previous AUX channel activity */ |
| 1002 | for (try = 0; try < 3; try++) { |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 1003 | status = I915_READ_NOTRACE(ch_ctl); |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1004 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 1005 | break; |
| 1006 | msleep(1); |
| 1007 | } |
| 1008 | |
| 1009 | if (try == 3) { |
Mika Kuoppala | 02196c7 | 2015-08-06 16:48:58 +0300 | [diff] [blame] | 1010 | static u32 last_status = -1; |
| 1011 | const u32 status = I915_READ(ch_ctl); |
| 1012 | |
| 1013 | if (status != last_status) { |
| 1014 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 1015 | status); |
| 1016 | last_status = status; |
| 1017 | } |
| 1018 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1019 | ret = -EBUSY; |
| 1020 | goto out; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1023 | /* Only 5 data registers! */ |
| 1024 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { |
| 1025 | ret = -E2BIG; |
| 1026 | goto out; |
| 1027 | } |
| 1028 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 1029 | while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) { |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 1030 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
| 1031 | has_aux_irq, |
| 1032 | send_bytes, |
| 1033 | aux_clock_divider); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1034 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1035 | /* Must try at least 3 times according to DP spec */ |
| 1036 | for (try = 0; try < 5; try++) { |
| 1037 | /* Load the send data into the aux channel data registers */ |
| 1038 | for (i = 0; i < send_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1039 | I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2], |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1040 | intel_dp_pack_aux(send + i, |
| 1041 | send_bytes - i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1042 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1043 | /* Send the command and wait for it to complete */ |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1044 | I915_WRITE(ch_ctl, send_ctl); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1045 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1046 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1047 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1048 | /* Clear done status and any errors */ |
| 1049 | I915_WRITE(ch_ctl, |
| 1050 | status | |
| 1051 | DP_AUX_CH_CTL_DONE | |
| 1052 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1053 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Adam Jackson | d7e96fe | 2011-07-26 15:39:46 -0400 | [diff] [blame] | 1054 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1055 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1056 | continue; |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1057 | |
| 1058 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 |
| 1059 | * 400us delay required for errors and timeouts |
| 1060 | * Timeout errors from the HW already meet this |
| 1061 | * requirement so skip to next iteration |
| 1062 | */ |
| 1063 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
| 1064 | usleep_range(400, 500); |
| 1065 | continue; |
| 1066 | } |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1067 | if (status & DP_AUX_CH_CTL_DONE) |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1068 | goto done; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1069 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1072 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1073 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1074 | ret = -EBUSY; |
| 1075 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1078 | done: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1079 | /* Check for timeout or receive error. |
| 1080 | * Timeouts occur when the sink is not connected |
| 1081 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1082 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1083 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1084 | ret = -EIO; |
| 1085 | goto out; |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1086 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1087 | |
| 1088 | /* Timeouts occur when the device isn't connected, so they're |
| 1089 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1090 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1091 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1092 | ret = -ETIMEDOUT; |
| 1093 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | /* Unload any bytes sent back from the other side */ |
| 1097 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 1098 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1099 | |
| 1100 | /* |
| 1101 | * By BSpec: "Message sizes of 0 or >20 are not allowed." |
| 1102 | * We have no idea of what happened so we return -EBUSY so |
| 1103 | * drm layer takes care for the necessary retries. |
| 1104 | */ |
| 1105 | if (recv_bytes == 0 || recv_bytes > 20) { |
| 1106 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", |
| 1107 | recv_bytes); |
| 1108 | /* |
| 1109 | * FIXME: This patch was created on top of a series that |
| 1110 | * organize the retries at drm level. There EBUSY should |
| 1111 | * also take care for 1ms wait before retrying. |
| 1112 | * That aux retries re-org is still needed and after that is |
| 1113 | * merged we remove this sleep from here. |
| 1114 | */ |
| 1115 | usleep_range(1000, 1500); |
| 1116 | ret = -EBUSY; |
| 1117 | goto out; |
| 1118 | } |
| 1119 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1120 | if (recv_bytes > recv_size) |
| 1121 | recv_bytes = recv_size; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1122 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1123 | for (i = 0; i < recv_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1124 | intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]), |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1125 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1126 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1127 | ret = recv_bytes; |
| 1128 | out: |
| 1129 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); |
| 1130 | |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1131 | if (vdd) |
| 1132 | edp_panel_vdd_off(intel_dp, false); |
| 1133 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1134 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1135 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1136 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1139 | #define BARE_ADDRESS_SIZE 3 |
| 1140 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1141 | static ssize_t |
| 1142 | intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1143 | { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1144 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
| 1145 | uint8_t txbuf[20], rxbuf[20]; |
| 1146 | size_t txsize, rxsize; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1147 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1148 | |
Ville Syrjälä | d2d9cbb | 2015-03-19 11:44:06 +0200 | [diff] [blame] | 1149 | txbuf[0] = (msg->request << 4) | |
| 1150 | ((msg->address >> 16) & 0xf); |
| 1151 | txbuf[1] = (msg->address >> 8) & 0xff; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1152 | txbuf[2] = msg->address & 0xff; |
| 1153 | txbuf[3] = msg->size - 1; |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1154 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1155 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
| 1156 | case DP_AUX_NATIVE_WRITE: |
| 1157 | case DP_AUX_I2C_WRITE: |
Ville Syrjälä | c1e74122 | 2015-08-27 17:23:27 +0300 | [diff] [blame] | 1158 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1159 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1160 | rxsize = 2; /* 0 or 1 data bytes */ |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1161 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1162 | if (WARN_ON(txsize > 20)) |
| 1163 | return -E2BIG; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1164 | |
Ville Syrjälä | dd78809 | 2016-07-28 17:55:04 +0300 | [diff] [blame] | 1165 | WARN_ON(!msg->buffer != !msg->size); |
| 1166 | |
Imre Deak | d81a67c | 2016-01-29 14:52:26 +0200 | [diff] [blame] | 1167 | if (msg->buffer) |
| 1168 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1169 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1170 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1171 | if (ret > 0) { |
| 1172 | msg->reply = rxbuf[0] >> 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1173 | |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1174 | if (ret > 1) { |
| 1175 | /* Number of bytes written in a short write. */ |
| 1176 | ret = clamp_t(int, rxbuf[1], 0, msg->size); |
| 1177 | } else { |
| 1178 | /* Return payload size. */ |
| 1179 | ret = msg->size; |
| 1180 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1181 | } |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1182 | break; |
| 1183 | |
| 1184 | case DP_AUX_NATIVE_READ: |
| 1185 | case DP_AUX_I2C_READ: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1186 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1187 | rxsize = msg->size + 1; |
| 1188 | |
| 1189 | if (WARN_ON(rxsize > 20)) |
| 1190 | return -E2BIG; |
| 1191 | |
| 1192 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1193 | if (ret > 0) { |
| 1194 | msg->reply = rxbuf[0] >> 4; |
| 1195 | /* |
| 1196 | * Assume happy day, and copy the data. The caller is |
| 1197 | * expected to check msg->reply before touching it. |
| 1198 | * |
| 1199 | * Return payload size. |
| 1200 | */ |
| 1201 | ret--; |
| 1202 | memcpy(msg->buffer, rxbuf + 1, ret); |
| 1203 | } |
| 1204 | break; |
| 1205 | |
| 1206 | default: |
| 1207 | ret = -EINVAL; |
| 1208 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1209 | } |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1210 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1211 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1214 | static enum port intel_aux_port(struct drm_i915_private *dev_priv, |
| 1215 | enum port port) |
| 1216 | { |
| 1217 | const struct ddi_vbt_port_info *info = |
| 1218 | &dev_priv->vbt.ddi_port_info[port]; |
| 1219 | enum port aux_port; |
| 1220 | |
| 1221 | if (!info->alternate_aux_channel) { |
| 1222 | DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n", |
| 1223 | port_name(port), port_name(port)); |
| 1224 | return port; |
| 1225 | } |
| 1226 | |
| 1227 | switch (info->alternate_aux_channel) { |
| 1228 | case DP_AUX_A: |
| 1229 | aux_port = PORT_A; |
| 1230 | break; |
| 1231 | case DP_AUX_B: |
| 1232 | aux_port = PORT_B; |
| 1233 | break; |
| 1234 | case DP_AUX_C: |
| 1235 | aux_port = PORT_C; |
| 1236 | break; |
| 1237 | case DP_AUX_D: |
| 1238 | aux_port = PORT_D; |
| 1239 | break; |
| 1240 | default: |
| 1241 | MISSING_CASE(info->alternate_aux_channel); |
| 1242 | aux_port = PORT_A; |
| 1243 | break; |
| 1244 | } |
| 1245 | |
| 1246 | DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n", |
| 1247 | port_name(aux_port), port_name(port)); |
| 1248 | |
| 1249 | return aux_port; |
| 1250 | } |
| 1251 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1252 | static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1253 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1254 | { |
| 1255 | switch (port) { |
| 1256 | case PORT_B: |
| 1257 | case PORT_C: |
| 1258 | case PORT_D: |
| 1259 | return DP_AUX_CH_CTL(port); |
| 1260 | default: |
| 1261 | MISSING_CASE(port); |
| 1262 | return DP_AUX_CH_CTL(PORT_B); |
| 1263 | } |
| 1264 | } |
| 1265 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1266 | static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1267 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1268 | { |
| 1269 | switch (port) { |
| 1270 | case PORT_B: |
| 1271 | case PORT_C: |
| 1272 | case PORT_D: |
| 1273 | return DP_AUX_CH_DATA(port, index); |
| 1274 | default: |
| 1275 | MISSING_CASE(port); |
| 1276 | return DP_AUX_CH_DATA(PORT_B, index); |
| 1277 | } |
| 1278 | } |
| 1279 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1280 | static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1281 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1282 | { |
| 1283 | switch (port) { |
| 1284 | case PORT_A: |
| 1285 | return DP_AUX_CH_CTL(port); |
| 1286 | case PORT_B: |
| 1287 | case PORT_C: |
| 1288 | case PORT_D: |
| 1289 | return PCH_DP_AUX_CH_CTL(port); |
| 1290 | default: |
| 1291 | MISSING_CASE(port); |
| 1292 | return DP_AUX_CH_CTL(PORT_A); |
| 1293 | } |
| 1294 | } |
| 1295 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1296 | static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1297 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1298 | { |
| 1299 | switch (port) { |
| 1300 | case PORT_A: |
| 1301 | return DP_AUX_CH_DATA(port, index); |
| 1302 | case PORT_B: |
| 1303 | case PORT_C: |
| 1304 | case PORT_D: |
| 1305 | return PCH_DP_AUX_CH_DATA(port, index); |
| 1306 | default: |
| 1307 | MISSING_CASE(port); |
| 1308 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1309 | } |
| 1310 | } |
| 1311 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1312 | static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1313 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1314 | { |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1315 | switch (port) { |
| 1316 | case PORT_A: |
| 1317 | case PORT_B: |
| 1318 | case PORT_C: |
| 1319 | case PORT_D: |
| 1320 | return DP_AUX_CH_CTL(port); |
| 1321 | default: |
| 1322 | MISSING_CASE(port); |
| 1323 | return DP_AUX_CH_CTL(PORT_A); |
| 1324 | } |
| 1325 | } |
| 1326 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1327 | static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1328 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1329 | { |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1330 | switch (port) { |
| 1331 | case PORT_A: |
| 1332 | case PORT_B: |
| 1333 | case PORT_C: |
| 1334 | case PORT_D: |
| 1335 | return DP_AUX_CH_DATA(port, index); |
| 1336 | default: |
| 1337 | MISSING_CASE(port); |
| 1338 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1339 | } |
| 1340 | } |
| 1341 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1342 | static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1343 | enum port port) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1344 | { |
| 1345 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1346 | return skl_aux_ctl_reg(dev_priv, port); |
| 1347 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1348 | return ilk_aux_ctl_reg(dev_priv, port); |
| 1349 | else |
| 1350 | return g4x_aux_ctl_reg(dev_priv, port); |
| 1351 | } |
| 1352 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1353 | static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1354 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1355 | { |
| 1356 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1357 | return skl_aux_data_reg(dev_priv, port, index); |
| 1358 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1359 | return ilk_aux_data_reg(dev_priv, port, index); |
| 1360 | else |
| 1361 | return g4x_aux_data_reg(dev_priv, port, index); |
| 1362 | } |
| 1363 | |
| 1364 | static void intel_aux_reg_init(struct intel_dp *intel_dp) |
| 1365 | { |
| 1366 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1367 | enum port port = intel_aux_port(dev_priv, |
| 1368 | dp_to_dig_port(intel_dp)->port); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1369 | int i; |
| 1370 | |
| 1371 | intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); |
| 1372 | for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++) |
| 1373 | intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i); |
| 1374 | } |
| 1375 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1376 | static void |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1377 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
| 1378 | { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1379 | kfree(intel_dp->aux.name); |
| 1380 | } |
| 1381 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1382 | static void |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 1383 | intel_dp_aux_init(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1384 | { |
Jani Nikula | 33ad662 | 2014-03-14 16:51:16 +0200 | [diff] [blame] | 1385 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 1386 | enum port port = intel_dig_port->port; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1387 | |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1388 | intel_aux_reg_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1389 | drm_dp_aux_init(&intel_dp->aux); |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 1390 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1391 | /* Failure to allocate our preferred name is not critical */ |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1392 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port)); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1393 | intel_dp->aux.transfer = intel_dp_aux_transfer; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1396 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1397 | { |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1398 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
Navare, Manasi D | 577c543 | 2016-09-27 16:36:53 -0700 | [diff] [blame] | 1399 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1400 | |
Navare, Manasi D | 577c543 | 2016-09-27 16:36:53 -0700 | [diff] [blame] | 1401 | if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) || |
| 1402 | IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9)) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1403 | return true; |
| 1404 | else |
| 1405 | return false; |
| 1406 | } |
| 1407 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 1408 | static void |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1409 | intel_dp_set_clock(struct intel_encoder *encoder, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1410 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1411 | { |
| 1412 | struct drm_device *dev = encoder->base.dev; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1413 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1414 | const struct dp_link_dpll *divisor = NULL; |
| 1415 | int i, count = 0; |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1416 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 1417 | if (IS_G4X(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1418 | divisor = gen4_dpll; |
| 1419 | count = ARRAY_SIZE(gen4_dpll); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1420 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1421 | divisor = pch_dpll; |
| 1422 | count = ARRAY_SIZE(pch_dpll); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1423 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1424 | divisor = chv_dpll; |
| 1425 | count = ARRAY_SIZE(chv_dpll); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 1426 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 1427 | divisor = vlv_dpll; |
| 1428 | count = ARRAY_SIZE(vlv_dpll); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1429 | } |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1430 | |
| 1431 | if (divisor && count) { |
| 1432 | for (i = 0; i < count; i++) { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1433 | if (pipe_config->port_clock == divisor[i].clock) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1434 | pipe_config->dpll = divisor[i].dpll; |
| 1435 | pipe_config->clock_set = true; |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1442 | static void snprintf_int_array(char *str, size_t len, |
| 1443 | const int *array, int nelem) |
| 1444 | { |
| 1445 | int i; |
| 1446 | |
| 1447 | str[0] = '\0'; |
| 1448 | |
| 1449 | for (i = 0; i < nelem; i++) { |
Jani Nikula | b2f505b | 2015-05-18 16:01:45 +0300 | [diff] [blame] | 1450 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1451 | if (r >= len) |
| 1452 | return; |
| 1453 | str += r; |
| 1454 | len -= r; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | static void intel_dp_print_rates(struct intel_dp *intel_dp) |
| 1459 | { |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1460 | const int *source_rates, *sink_rates; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1461 | int source_len, sink_len, common_len; |
| 1462 | int common_rates[DP_MAX_SUPPORTED_RATES]; |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1463 | char str[128]; /* FIXME: too big for stack? */ |
| 1464 | |
| 1465 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 1466 | return; |
| 1467 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1468 | source_len = intel_dp_source_rates(intel_dp, &source_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1469 | snprintf_int_array(str, sizeof(str), source_rates, source_len); |
| 1470 | DRM_DEBUG_KMS("source rates: %s\n", str); |
| 1471 | |
| 1472 | sink_len = intel_dp_sink_rates(intel_dp, &sink_rates); |
| 1473 | snprintf_int_array(str, sizeof(str), sink_rates, sink_len); |
| 1474 | DRM_DEBUG_KMS("sink rates: %s\n", str); |
| 1475 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1476 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
| 1477 | snprintf_int_array(str, sizeof(str), common_rates, common_len); |
| 1478 | DRM_DEBUG_KMS("common rates: %s\n", str); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
Imre Deak | 489375c | 2016-10-24 19:33:31 +0300 | [diff] [blame] | 1481 | bool |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1482 | __intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc) |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1483 | { |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1484 | u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI : |
| 1485 | DP_SINK_OUI; |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1486 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1487 | return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) == |
| 1488 | sizeof(*desc); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1489 | } |
| 1490 | |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 1491 | bool intel_dp_read_desc(struct intel_dp *intel_dp) |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1492 | { |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1493 | struct intel_dp_desc *desc = &intel_dp->desc; |
| 1494 | bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & |
| 1495 | DP_OUI_SUPPORT; |
| 1496 | int dev_id_len; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1497 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1498 | if (!__intel_dp_read_desc(intel_dp, desc)) |
| 1499 | return false; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1500 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1501 | dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id)); |
| 1502 | DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n", |
| 1503 | drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink", |
| 1504 | (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)", |
| 1505 | dev_id_len, desc->device_id, |
| 1506 | desc->hw_rev >> 4, desc->hw_rev & 0xf, |
| 1507 | desc->sw_major_rev, desc->sw_minor_rev); |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1508 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1509 | return true; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1510 | } |
| 1511 | |
Ville Syrjälä | f4896f1 | 2015-03-12 17:10:27 +0200 | [diff] [blame] | 1512 | static int rate_to_index(int find, const int *rates) |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1513 | { |
| 1514 | int i = 0; |
| 1515 | |
| 1516 | for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i) |
| 1517 | if (find == rates[i]) |
| 1518 | break; |
| 1519 | |
| 1520 | return i; |
| 1521 | } |
| 1522 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1523 | int |
| 1524 | intel_dp_max_link_rate(struct intel_dp *intel_dp) |
| 1525 | { |
| 1526 | int rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 1527 | int len; |
| 1528 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1529 | len = intel_dp_common_rates(intel_dp, rates); |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1530 | if (WARN_ON(len <= 0)) |
| 1531 | return 162000; |
| 1532 | |
Ville Syrjälä | 1354f73 | 2016-07-28 17:50:45 +0300 | [diff] [blame] | 1533 | return rates[len - 1]; |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1534 | } |
| 1535 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1536 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
| 1537 | { |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1538 | return rate_to_index(rate, intel_dp->sink_rates); |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1539 | } |
| 1540 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 1541 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
| 1542 | uint8_t *link_bw, uint8_t *rate_select) |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1543 | { |
| 1544 | if (intel_dp->num_sink_rates) { |
| 1545 | *link_bw = 0; |
| 1546 | *rate_select = |
| 1547 | intel_dp_rate_select(intel_dp, port_clock); |
| 1548 | } else { |
| 1549 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); |
| 1550 | *rate_select = 0; |
| 1551 | } |
| 1552 | } |
| 1553 | |
Jani Nikula | f580bea | 2016-09-15 16:28:52 +0300 | [diff] [blame] | 1554 | static int intel_dp_compute_bpp(struct intel_dp *intel_dp, |
| 1555 | struct intel_crtc_state *pipe_config) |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1556 | { |
| 1557 | int bpp, bpc; |
| 1558 | |
| 1559 | bpp = pipe_config->pipe_bpp; |
| 1560 | bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports); |
| 1561 | |
| 1562 | if (bpc > 0) |
| 1563 | bpp = min(bpp, 3*bpc); |
| 1564 | |
| 1565 | return bpp; |
| 1566 | } |
| 1567 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1568 | bool |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1569 | intel_dp_compute_config(struct intel_encoder *encoder, |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 1570 | struct intel_crtc_state *pipe_config, |
| 1571 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1572 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1573 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 1574 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1575 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1576 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ander Conselvan de Oliveira | 84556d5 | 2015-03-20 16:18:10 +0200 | [diff] [blame] | 1577 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1578 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1579 | int lane_count, clock; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1580 | int min_lane_count = 1; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 1581 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
Todd Previte | 06ea66b | 2014-01-20 10:19:39 -0700 | [diff] [blame] | 1582 | /* Conveniently, the link BW constants become indices with a shift...*/ |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1583 | int min_clock = 0; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1584 | int max_clock; |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1585 | int bpp, mode_rate; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1586 | int link_avail, link_clock; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1587 | int common_rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 1588 | int common_len; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1589 | uint8_t link_bw, rate_select; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1590 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1591 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1592 | |
| 1593 | /* No common link rates between source and sink */ |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1594 | WARN_ON(common_len <= 0); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1595 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1596 | max_clock = common_len - 1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1597 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1598 | if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A) |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1599 | pipe_config->has_pch_encoder = true; |
| 1600 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1601 | pipe_config->has_drrs = false; |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 1602 | pipe_config->has_audio = intel_dp->has_audio && port != PORT_A; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1603 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1604 | if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
| 1605 | intel_fixed_panel_mode(intel_connector->panel.fixed_mode, |
| 1606 | adjusted_mode); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1607 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1608 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1609 | int ret; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 1610 | ret = skl_update_scaler_crtc(pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1611 | if (ret) |
| 1612 | return ret; |
| 1613 | } |
| 1614 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 1615 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1616 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
| 1617 | intel_connector->panel.fitting_mode); |
| 1618 | else |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 1619 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
| 1620 | intel_connector->panel.fitting_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 1621 | } |
| 1622 | |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 1623 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 1624 | return false; |
| 1625 | |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1626 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1627 | "max bw %d pixel clock %iKHz\n", |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1628 | max_lane_count, common_rates[max_clock], |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1629 | adjusted_mode->crtc_clock); |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1630 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1631 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
| 1632 | * bpc in between. */ |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1633 | bpp = intel_dp_compute_bpp(intel_dp, pipe_config); |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1634 | if (is_edp(intel_dp)) { |
Thulasimani,Sivakumar | 22ce562 | 2015-07-31 11:05:27 +0530 | [diff] [blame] | 1635 | |
| 1636 | /* Get bpp from vbt only for panels that dont have bpp in edid */ |
| 1637 | if (intel_connector->base.display_info.bpc == 0 && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1638 | (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) { |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1639 | DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n", |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1640 | dev_priv->vbt.edp.bpp); |
| 1641 | bpp = dev_priv->vbt.edp.bpp; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1642 | } |
| 1643 | |
Jani Nikula | 344c5bb | 2014-09-09 11:25:13 +0300 | [diff] [blame] | 1644 | /* |
| 1645 | * Use the maximum clock and number of lanes the eDP panel |
| 1646 | * advertizes being capable of. The panels are generally |
| 1647 | * designed to support only a single clock and lane |
| 1648 | * configuration, and typically these values correspond to the |
| 1649 | * native resolution of the panel. |
| 1650 | */ |
| 1651 | min_lane_count = max_lane_count; |
| 1652 | min_clock = max_clock; |
Imre Deak | 7984211 | 2013-07-18 17:44:13 +0300 | [diff] [blame] | 1653 | } |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1654 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1655 | for (; bpp >= 6*3; bpp -= 2*3) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1656 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
| 1657 | bpp); |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1658 | |
Dave Airlie | c693099 | 2014-07-14 11:04:39 +1000 | [diff] [blame] | 1659 | for (clock = min_clock; clock <= max_clock; clock++) { |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1660 | for (lane_count = min_lane_count; |
| 1661 | lane_count <= max_lane_count; |
| 1662 | lane_count <<= 1) { |
| 1663 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1664 | link_clock = common_rates[clock]; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1665 | link_avail = intel_dp_max_data_rate(link_clock, |
| 1666 | lane_count); |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 1667 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1668 | if (mode_rate <= link_avail) { |
| 1669 | goto found; |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | return false; |
| 1676 | |
| 1677 | found: |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1678 | if (intel_dp->color_range_auto) { |
| 1679 | /* |
| 1680 | * See: |
| 1681 | * CEA-861-E - 5.1 Default Encoding Parameters |
| 1682 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry |
| 1683 | */ |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1684 | pipe_config->limited_color_range = |
| 1685 | bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1; |
| 1686 | } else { |
| 1687 | pipe_config->limited_color_range = |
| 1688 | intel_dp->limited_color_range; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1689 | } |
| 1690 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1691 | pipe_config->lane_count = lane_count; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1692 | |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1693 | pipe_config->pipe_bpp = bpp; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1694 | pipe_config->port_clock = common_rates[clock]; |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1695 | |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1696 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
| 1697 | &link_bw, &rate_select); |
| 1698 | |
| 1699 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", |
| 1700 | link_bw, rate_select, pipe_config->lane_count, |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1701 | pipe_config->port_clock, bpp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1702 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
| 1703 | mode_rate, link_avail); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1704 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1705 | intel_link_compute_m_n(bpp, lane_count, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1706 | adjusted_mode->crtc_clock, |
| 1707 | pipe_config->port_clock, |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1708 | &pipe_config->dp_m_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1709 | |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1710 | if (intel_connector->panel.downclock_mode != NULL && |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 1711 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1712 | pipe_config->has_drrs = true; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1713 | intel_link_compute_m_n(bpp, lane_count, |
| 1714 | intel_connector->panel.downclock_mode->clock, |
| 1715 | pipe_config->port_clock, |
| 1716 | &pipe_config->dp_m2_n2); |
| 1717 | } |
| 1718 | |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1719 | /* |
| 1720 | * DPLL0 VCO may need to be adjusted to get the correct |
| 1721 | * clock for eDP. This will affect cdclk as well. |
| 1722 | */ |
| 1723 | if (is_edp(intel_dp) && |
| 1724 | (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) { |
| 1725 | int vco; |
| 1726 | |
| 1727 | switch (pipe_config->port_clock / 2) { |
| 1728 | case 108000: |
| 1729 | case 216000: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1730 | vco = 8640000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1731 | break; |
| 1732 | default: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1733 | vco = 8100000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1734 | break; |
| 1735 | } |
| 1736 | |
| 1737 | to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco; |
| 1738 | } |
| 1739 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1740 | if (!HAS_DDI(dev_priv)) |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1741 | intel_dp_set_clock(encoder, pipe_config); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1742 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1743 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1746 | void intel_dp_set_link_params(struct intel_dp *intel_dp, |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1747 | int link_rate, uint8_t lane_count, |
| 1748 | bool link_mst) |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1749 | { |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1750 | intel_dp->link_rate = link_rate; |
| 1751 | intel_dp->lane_count = lane_count; |
| 1752 | intel_dp->link_mst = link_mst; |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1753 | } |
| 1754 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1755 | static void intel_dp_prepare(struct intel_encoder *encoder, |
| 1756 | struct intel_crtc_state *pipe_config) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1757 | { |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1758 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1759 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1760 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1761 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1762 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1763 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1764 | |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1765 | intel_dp_set_link_params(intel_dp, pipe_config->port_clock, |
| 1766 | pipe_config->lane_count, |
| 1767 | intel_crtc_has_type(pipe_config, |
| 1768 | INTEL_OUTPUT_DP_MST)); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1769 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1770 | /* |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1771 | * There are four kinds of DP registers: |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1772 | * |
| 1773 | * IBX PCH |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1774 | * SNB CPU |
| 1775 | * IVB CPU |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1776 | * CPT PCH |
| 1777 | * |
| 1778 | * IBX PCH and CPU are the same for almost everything, |
| 1779 | * except that the CPU DP PLL is configured in this |
| 1780 | * register |
| 1781 | * |
| 1782 | * CPT PCH is quite different, having many bits moved |
| 1783 | * to the TRANS_DP_CTL register instead. That |
| 1784 | * configuration happens (oddly) in ironlake_pch_enable |
| 1785 | */ |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 1786 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1787 | /* Preserve the BIOS-computed detected bit. This is |
| 1788 | * supposed to be read-only. |
| 1789 | */ |
| 1790 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1791 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1792 | /* Handle DP bits in common between all three register formats */ |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1793 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1794 | intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1795 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1796 | /* Split out the IBX/CPU vs CPT settings */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1797 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1798 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1799 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1800 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1801 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1802 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1803 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
| 1804 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1805 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1806 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1807 | |
Daniel Vetter | 7c62a16 | 2013-06-01 17:16:20 +0200 | [diff] [blame] | 1808 | intel_dp->DP |= crtc->pipe << 29; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1809 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1810 | u32 trans_dp; |
| 1811 | |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1812 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1813 | |
| 1814 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 1815 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 1816 | trans_dp |= TRANS_DP_ENH_FRAMING; |
| 1817 | else |
| 1818 | trans_dp &= ~TRANS_DP_ENH_FRAMING; |
| 1819 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1820 | } else { |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 1821 | if (IS_G4X(dev_priv) && pipe_config->limited_color_range) |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1822 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1823 | |
| 1824 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1825 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1826 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1827 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1828 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
| 1829 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1830 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1831 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1832 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1833 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1834 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1835 | else if (crtc->pipe == PIPE_B) |
| 1836 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1837 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1840 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
| 1841 | #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1842 | |
Paulo Zanoni | 1a5ef5b | 2013-12-19 14:29:43 -0200 | [diff] [blame] | 1843 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
| 1844 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1845 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1846 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
| 1847 | #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1848 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1849 | static void intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 1850 | struct intel_dp *intel_dp); |
| 1851 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1852 | static void wait_panel_status(struct intel_dp *intel_dp, |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1853 | u32 mask, |
| 1854 | u32 value) |
| 1855 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 1856 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1857 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1858 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1859 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1860 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1861 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1862 | intel_pps_verify_state(dev_priv, intel_dp); |
| 1863 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1864 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 1865 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1866 | |
| 1867 | DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1868 | mask, value, |
| 1869 | I915_READ(pp_stat_reg), |
| 1870 | I915_READ(pp_ctrl_reg)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1871 | |
Chris Wilson | 9036ff0 | 2016-06-30 15:33:09 +0100 | [diff] [blame] | 1872 | if (intel_wait_for_register(dev_priv, |
| 1873 | pp_stat_reg, mask, value, |
| 1874 | 5000)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1875 | DRM_ERROR("Panel status timeout: status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1876 | I915_READ(pp_stat_reg), |
| 1877 | I915_READ(pp_ctrl_reg)); |
Chris Wilson | 54c136d | 2013-12-02 09:57:16 +0000 | [diff] [blame] | 1878 | |
| 1879 | DRM_DEBUG_KMS("Wait complete\n"); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1882 | static void wait_panel_on(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1883 | { |
| 1884 | DRM_DEBUG_KMS("Wait for panel power on\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1885 | wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1888 | static void wait_panel_off(struct intel_dp *intel_dp) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1889 | { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1890 | DRM_DEBUG_KMS("Wait for panel power off time\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1891 | wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1892 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1893 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1894 | static void wait_panel_power_cycle(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1895 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1896 | ktime_t panel_power_on_time; |
| 1897 | s64 panel_power_off_duration; |
| 1898 | |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1899 | DRM_DEBUG_KMS("Wait for panel power cycle\n"); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1900 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1901 | /* take the difference of currrent time and panel power off time |
| 1902 | * and then make panel wait for t11_t12 if needed. */ |
| 1903 | panel_power_on_time = ktime_get_boottime(); |
| 1904 | panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time); |
| 1905 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1906 | /* When we disable the VDD override bit last we have to do the manual |
| 1907 | * wait. */ |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1908 | if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay) |
| 1909 | wait_remaining_ms_from_jiffies(jiffies, |
| 1910 | intel_dp->panel_power_cycle_delay - panel_power_off_duration); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1911 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1912 | wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1913 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1914 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1915 | static void wait_backlight_on(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1916 | { |
| 1917 | wait_remaining_ms_from_jiffies(intel_dp->last_power_on, |
| 1918 | intel_dp->backlight_on_delay); |
| 1919 | } |
| 1920 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1921 | static void edp_wait_backlight_off(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1922 | { |
| 1923 | wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off, |
| 1924 | intel_dp->backlight_off_delay); |
| 1925 | } |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1926 | |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 1927 | /* Read the current pp_control value, unlocking the register if it |
| 1928 | * is locked |
| 1929 | */ |
| 1930 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1931 | static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 1932 | { |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1933 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1934 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1935 | u32 control; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1936 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1937 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1938 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1939 | control = I915_READ(_pp_ctrl_reg(intel_dp)); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 1940 | if (WARN_ON(!HAS_DDI(dev_priv) && |
| 1941 | (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 1942 | control &= ~PANEL_UNLOCK_MASK; |
| 1943 | control |= PANEL_UNLOCK_REGS; |
| 1944 | } |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 1945 | return control; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 1948 | /* |
| 1949 | * Must be paired with edp_panel_vdd_off(). |
| 1950 | * Must hold pps_mutex around the whole on/off sequence. |
| 1951 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 1952 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 1953 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 1954 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 1955 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 1956 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 1957 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1958 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 1959 | enum intel_display_power_domain power_domain; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 1960 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1961 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 1962 | bool need_to_disable = !intel_dp->want_panel_vdd; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 1963 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1964 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1965 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 1966 | if (!is_edp(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 1967 | return false; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1968 | |
Egbert Eich | 2c623c1 | 2014-11-25 12:54:57 +0100 | [diff] [blame] | 1969 | cancel_delayed_work(&intel_dp->panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1970 | intel_dp->want_panel_vdd = true; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1971 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1972 | if (edp_have_panel_vdd(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 1973 | return need_to_disable; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 1974 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 1975 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 1976 | intel_display_power_get(dev_priv, power_domain); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 1977 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 1978 | DRM_DEBUG_KMS("Turning eDP port %c VDD on\n", |
| 1979 | port_name(intel_dig_port->port)); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1980 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1981 | if (!edp_have_panel_power(intel_dp)) |
| 1982 | wait_panel_power_cycle(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1983 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1984 | pp = ironlake_get_pp_control(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 1985 | pp |= EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 1986 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1987 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 1988 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1989 | |
| 1990 | I915_WRITE(pp_ctrl_reg, pp); |
| 1991 | POSTING_READ(pp_ctrl_reg); |
| 1992 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 1993 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 1994 | /* |
| 1995 | * If the panel wasn't on, delay before accessing aux channel |
| 1996 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1997 | if (!edp_have_panel_power(intel_dp)) { |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 1998 | DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n", |
| 1999 | port_name(intel_dig_port->port)); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2000 | msleep(intel_dp->panel_power_up_delay); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2001 | } |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2002 | |
| 2003 | return need_to_disable; |
| 2004 | } |
| 2005 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2006 | /* |
| 2007 | * Must be paired with intel_edp_panel_vdd_off() or |
| 2008 | * intel_edp_panel_off(). |
| 2009 | * Nested calls to these functions are not allowed since |
| 2010 | * we drop the lock. Caller must use some higher level |
| 2011 | * locking to prevent nested calls from other threads. |
| 2012 | */ |
Daniel Vetter | b80d6c7 | 2014-03-19 15:54:37 +0100 | [diff] [blame] | 2013 | void intel_edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2014 | { |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2015 | bool vdd; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2016 | |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2017 | if (!is_edp(intel_dp)) |
| 2018 | return; |
| 2019 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2020 | pps_lock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2021 | vdd = edp_panel_vdd_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2022 | pps_unlock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2023 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2024 | I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n", |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2025 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2026 | } |
| 2027 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2028 | static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2029 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2030 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2031 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2032 | struct intel_digital_port *intel_dig_port = |
| 2033 | dp_to_dig_port(intel_dp); |
| 2034 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 2035 | enum intel_display_power_domain power_domain; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2036 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2037 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2038 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2039 | lockdep_assert_held(&dev_priv->pps_mutex); |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 2040 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2041 | WARN_ON(intel_dp->want_panel_vdd); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2042 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2043 | if (!edp_have_panel_vdd(intel_dp)) |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2044 | return; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2045 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2046 | DRM_DEBUG_KMS("Turning eDP port %c VDD off\n", |
| 2047 | port_name(intel_dig_port->port)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2048 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2049 | pp = ironlake_get_pp_control(intel_dp); |
| 2050 | pp &= ~EDP_FORCE_VDD; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2051 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2052 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
| 2053 | pp_stat_reg = _pp_stat_reg(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2054 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2055 | I915_WRITE(pp_ctrl_reg, pp); |
| 2056 | POSTING_READ(pp_ctrl_reg); |
Paulo Zanoni | 90791a5 | 2013-12-06 17:32:42 -0200 | [diff] [blame] | 2057 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2058 | /* Make sure sequencer is idle before allowing subsequent activity */ |
| 2059 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2060 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2061 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2062 | if ((pp & PANEL_POWER_ON) == 0) |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2063 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2064 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 2065 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2066 | intel_display_power_put(dev_priv, power_domain); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2069 | static void edp_panel_vdd_work(struct work_struct *__work) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2070 | { |
| 2071 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), |
| 2072 | struct intel_dp, panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2073 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2074 | pps_lock(intel_dp); |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2075 | if (!intel_dp->want_panel_vdd) |
| 2076 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2077 | pps_unlock(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2080 | static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) |
| 2081 | { |
| 2082 | unsigned long delay; |
| 2083 | |
| 2084 | /* |
| 2085 | * Queue the timer to fire a long time from now (relative to the power |
| 2086 | * down delay) to keep the panel power up across a sequence of |
| 2087 | * operations. |
| 2088 | */ |
| 2089 | delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5); |
| 2090 | schedule_delayed_work(&intel_dp->panel_vdd_work, delay); |
| 2091 | } |
| 2092 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2093 | /* |
| 2094 | * Must be paired with edp_panel_vdd_on(). |
| 2095 | * Must hold pps_mutex around the whole on/off sequence. |
| 2096 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2097 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2098 | static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2099 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2100 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2101 | |
| 2102 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2103 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2104 | if (!is_edp(intel_dp)) |
| 2105 | return; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2106 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2107 | I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on", |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2108 | port_name(dp_to_dig_port(intel_dp)->port)); |
Keith Packard | f2e8b18 | 2011-11-01 20:01:35 -0700 | [diff] [blame] | 2109 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2110 | intel_dp->want_panel_vdd = false; |
| 2111 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2112 | if (sync) |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2113 | edp_panel_vdd_off_sync(intel_dp); |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2114 | else |
| 2115 | edp_panel_vdd_schedule_off(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2116 | } |
| 2117 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2118 | static void edp_panel_on(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2119 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2120 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2121 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2122 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2123 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2124 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2125 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2126 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2127 | if (!is_edp(intel_dp)) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2128 | return; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2129 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2130 | DRM_DEBUG_KMS("Turn eDP port %c panel power on\n", |
| 2131 | port_name(dp_to_dig_port(intel_dp)->port)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2132 | |
Ville Syrjälä | e7a89ac | 2014-10-16 21:30:07 +0300 | [diff] [blame] | 2133 | if (WARN(edp_have_panel_power(intel_dp), |
| 2134 | "eDP port %c panel power already on\n", |
| 2135 | port_name(dp_to_dig_port(intel_dp)->port))) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2136 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2137 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2138 | wait_panel_power_cycle(intel_dp); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2139 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2140 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2141 | pp = ironlake_get_pp_control(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2142 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2143 | /* ILK workaround: disable reset around power sequence */ |
| 2144 | pp &= ~PANEL_POWER_RESET; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2145 | I915_WRITE(pp_ctrl_reg, pp); |
| 2146 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2147 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2148 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2149 | pp |= PANEL_POWER_ON; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2150 | if (!IS_GEN5(dev_priv)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2151 | pp |= PANEL_POWER_RESET; |
| 2152 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2153 | I915_WRITE(pp_ctrl_reg, pp); |
| 2154 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2155 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2156 | wait_panel_on(intel_dp); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2157 | intel_dp->last_power_on = jiffies; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2158 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2159 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2160 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2161 | I915_WRITE(pp_ctrl_reg, pp); |
| 2162 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2163 | } |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2164 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2165 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2166 | void intel_edp_panel_on(struct intel_dp *intel_dp) |
| 2167 | { |
| 2168 | if (!is_edp(intel_dp)) |
| 2169 | return; |
| 2170 | |
| 2171 | pps_lock(intel_dp); |
| 2172 | edp_panel_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2173 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2176 | |
| 2177 | static void edp_panel_off(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2178 | { |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2179 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2180 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2181 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2182 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2183 | enum intel_display_power_domain power_domain; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2184 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2185 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2186 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2187 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2188 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2189 | if (!is_edp(intel_dp)) |
| 2190 | return; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2191 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2192 | DRM_DEBUG_KMS("Turn eDP port %c panel power off\n", |
| 2193 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2194 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2195 | WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n", |
| 2196 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2197 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2198 | pp = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 35a3855 | 2012-08-12 22:17:14 +0200 | [diff] [blame] | 2199 | /* We need to switch off panel power _and_ force vdd, for otherwise some |
| 2200 | * panels get very unhappy and cease to work. */ |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2201 | pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | |
Patrik Jakobsson | b306415 | 2014-03-04 00:42:44 +0100 | [diff] [blame] | 2202 | EDP_BLC_ENABLE); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2203 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2204 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2205 | |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2206 | intel_dp->want_panel_vdd = false; |
| 2207 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2208 | I915_WRITE(pp_ctrl_reg, pp); |
| 2209 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2210 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2211 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2212 | wait_panel_off(intel_dp); |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2213 | |
| 2214 | /* We got a reference when we enabled the VDD. */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 2215 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2216 | intel_display_power_put(dev_priv, power_domain); |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2217 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2218 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2219 | void intel_edp_panel_off(struct intel_dp *intel_dp) |
| 2220 | { |
| 2221 | if (!is_edp(intel_dp)) |
| 2222 | return; |
| 2223 | |
| 2224 | pps_lock(intel_dp); |
| 2225 | edp_panel_off(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2226 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2229 | /* Enable backlight in the panel power control. */ |
| 2230 | static void _intel_edp_backlight_on(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2231 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2232 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2233 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2234 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2235 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2236 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2237 | |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 2238 | /* |
| 2239 | * If we enable the backlight right away following a panel power |
| 2240 | * on, we may see slight flicker as the panel syncs with the eDP |
| 2241 | * link. So delay a bit to make sure the image is solid before |
| 2242 | * allowing it to appear. |
| 2243 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2244 | wait_backlight_on(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2245 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2246 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2247 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2248 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2249 | pp |= EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2250 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2251 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2252 | |
| 2253 | I915_WRITE(pp_ctrl_reg, pp); |
| 2254 | POSTING_READ(pp_ctrl_reg); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2255 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2256 | pps_unlock(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2257 | } |
| 2258 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2259 | /* Enable backlight PWM and backlight PP control. */ |
| 2260 | void intel_edp_backlight_on(struct intel_dp *intel_dp) |
| 2261 | { |
| 2262 | if (!is_edp(intel_dp)) |
| 2263 | return; |
| 2264 | |
| 2265 | DRM_DEBUG_KMS("\n"); |
| 2266 | |
| 2267 | intel_panel_enable_backlight(intel_dp->attached_connector); |
| 2268 | _intel_edp_backlight_on(intel_dp); |
| 2269 | } |
| 2270 | |
| 2271 | /* Disable backlight in the panel power control. */ |
| 2272 | static void _intel_edp_backlight_off(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2273 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2274 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2275 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2276 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2277 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2278 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2279 | if (!is_edp(intel_dp)) |
| 2280 | return; |
| 2281 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2282 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2283 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2284 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2285 | pp &= ~EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2286 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2287 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2288 | |
| 2289 | I915_WRITE(pp_ctrl_reg, pp); |
| 2290 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2291 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2292 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2293 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2294 | intel_dp->last_backlight_off = jiffies; |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2295 | edp_wait_backlight_off(intel_dp); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2296 | } |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2297 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2298 | /* Disable backlight PP control and backlight PWM. */ |
| 2299 | void intel_edp_backlight_off(struct intel_dp *intel_dp) |
| 2300 | { |
| 2301 | if (!is_edp(intel_dp)) |
| 2302 | return; |
| 2303 | |
| 2304 | DRM_DEBUG_KMS("\n"); |
| 2305 | |
| 2306 | _intel_edp_backlight_off(intel_dp); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2307 | intel_panel_disable_backlight(intel_dp->attached_connector); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2308 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2309 | |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2310 | /* |
| 2311 | * Hook for controlling the panel power control backlight through the bl_power |
| 2312 | * sysfs attribute. Take care to handle multiple calls. |
| 2313 | */ |
| 2314 | static void intel_edp_backlight_power(struct intel_connector *connector, |
| 2315 | bool enable) |
| 2316 | { |
| 2317 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2318 | bool is_enabled; |
| 2319 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2320 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2321 | is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2322 | pps_unlock(intel_dp); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2323 | |
| 2324 | if (is_enabled == enable) |
| 2325 | return; |
| 2326 | |
Jani Nikula | 23ba937 | 2014-08-27 14:08:43 +0300 | [diff] [blame] | 2327 | DRM_DEBUG_KMS("panel power control backlight %s\n", |
| 2328 | enable ? "enable" : "disable"); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2329 | |
| 2330 | if (enable) |
| 2331 | _intel_edp_backlight_on(intel_dp); |
| 2332 | else |
| 2333 | _intel_edp_backlight_off(intel_dp); |
| 2334 | } |
| 2335 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2336 | static void assert_dp_port(struct intel_dp *intel_dp, bool state) |
| 2337 | { |
| 2338 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 2339 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 2340 | bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN; |
| 2341 | |
| 2342 | I915_STATE_WARN(cur_state != state, |
| 2343 | "DP port %c state assertion failure (expected %s, current %s)\n", |
| 2344 | port_name(dig_port->port), |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2345 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2346 | } |
| 2347 | #define assert_dp_port_disabled(d) assert_dp_port((d), false) |
| 2348 | |
| 2349 | static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state) |
| 2350 | { |
| 2351 | bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE; |
| 2352 | |
| 2353 | I915_STATE_WARN(cur_state != state, |
| 2354 | "eDP PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2355 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2356 | } |
| 2357 | #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) |
| 2358 | #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) |
| 2359 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2360 | static void ironlake_edp_pll_on(struct intel_dp *intel_dp, |
| 2361 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2362 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2363 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2364 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2365 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2366 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2367 | assert_dp_port_disabled(intel_dp); |
| 2368 | assert_edp_pll_disabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2369 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2370 | DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n", |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2371 | pipe_config->port_clock); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2372 | |
| 2373 | intel_dp->DP &= ~DP_PLL_FREQ_MASK; |
| 2374 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2375 | if (pipe_config->port_clock == 162000) |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2376 | intel_dp->DP |= DP_PLL_FREQ_162MHZ; |
| 2377 | else |
| 2378 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
| 2379 | |
| 2380 | I915_WRITE(DP_A, intel_dp->DP); |
| 2381 | POSTING_READ(DP_A); |
| 2382 | udelay(500); |
| 2383 | |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2384 | /* |
| 2385 | * [DevILK] Work around required when enabling DP PLL |
| 2386 | * while a pipe is enabled going to FDI: |
| 2387 | * 1. Wait for the start of vertical blank on the enabled pipe going to FDI |
| 2388 | * 2. Program DP PLL enable |
| 2389 | */ |
| 2390 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 2391 | intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe); |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2392 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2393 | intel_dp->DP |= DP_PLL_ENABLE; |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2394 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2395 | I915_WRITE(DP_A, intel_dp->DP); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 2396 | POSTING_READ(DP_A); |
| 2397 | udelay(200); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2400 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2401 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2402 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2403 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
| 2404 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2405 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2406 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2407 | assert_dp_port_disabled(intel_dp); |
| 2408 | assert_edp_pll_enabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2409 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2410 | DRM_DEBUG_KMS("disabling eDP PLL\n"); |
| 2411 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2412 | intel_dp->DP &= ~DP_PLL_ENABLE; |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2413 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2414 | I915_WRITE(DP_A, intel_dp->DP); |
Chris Wilson | 1af5fa1 | 2010-09-08 21:07:28 +0100 | [diff] [blame] | 2415 | POSTING_READ(DP_A); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2416 | udelay(200); |
| 2417 | } |
| 2418 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2419 | /* If the sink supports it, try to set the power state appropriately */ |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2420 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2421 | { |
| 2422 | int ret, i; |
| 2423 | |
| 2424 | /* Should have a valid DPCD by this point */ |
| 2425 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 2426 | return; |
| 2427 | |
| 2428 | if (mode != DRM_MODE_DPMS_ON) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2429 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2430 | DP_SET_POWER_D3); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2431 | } else { |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2432 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
| 2433 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2434 | /* |
| 2435 | * When turning on, we need to retry for 1ms to give the sink |
| 2436 | * time to wake up. |
| 2437 | */ |
| 2438 | for (i = 0; i < 3; i++) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2439 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2440 | DP_SET_POWER_D0); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2441 | if (ret == 1) |
| 2442 | break; |
| 2443 | msleep(1); |
| 2444 | } |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2445 | |
| 2446 | if (ret == 1 && lspcon->active) |
| 2447 | lspcon_wait_pcon_mode(lspcon); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2448 | } |
Jani Nikula | f9cac72 | 2014-09-02 16:33:52 +0300 | [diff] [blame] | 2449 | |
| 2450 | if (ret != 1) |
| 2451 | DRM_DEBUG_KMS("failed to %s sink power state\n", |
| 2452 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2455 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
| 2456 | enum pipe *pipe) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2457 | { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2458 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 2459 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2460 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2461 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2462 | enum intel_display_power_domain power_domain; |
| 2463 | u32 tmp; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2464 | bool ret; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2465 | |
| 2466 | power_domain = intel_display_port_power_domain(encoder); |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2467 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2468 | return false; |
| 2469 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2470 | ret = false; |
| 2471 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2472 | tmp = I915_READ(intel_dp->output_reg); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2473 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2474 | if (!(tmp & DP_PORT_EN)) |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2475 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2476 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2477 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2478 | *pipe = PORT_TO_PIPE_CPT(tmp); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2479 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2480 | enum pipe p; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2481 | |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2482 | for_each_pipe(dev_priv, p) { |
| 2483 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); |
| 2484 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { |
| 2485 | *pipe = p; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2486 | ret = true; |
| 2487 | |
| 2488 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2489 | } |
| 2490 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2491 | |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2492 | DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2493 | i915_mmio_reg_offset(intel_dp->output_reg)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2494 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2495 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); |
| 2496 | } else { |
| 2497 | *pipe = PORT_TO_PIPE(tmp); |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2498 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2499 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2500 | ret = true; |
| 2501 | |
| 2502 | out: |
| 2503 | intel_display_power_put(dev_priv, power_domain); |
| 2504 | |
| 2505 | return ret; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2506 | } |
| 2507 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2508 | static void intel_dp_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2509 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2510 | { |
| 2511 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2512 | u32 tmp, flags = 0; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2513 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2514 | struct drm_i915_private *dev_priv = to_i915(dev); |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2515 | enum port port = dp_to_dig_port(intel_dp)->port; |
| 2516 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2517 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2518 | tmp = I915_READ(intel_dp->output_reg); |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 2519 | |
| 2520 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2521 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2522 | if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2523 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 2524 | |
| 2525 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2526 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2527 | else |
| 2528 | flags |= DRM_MODE_FLAG_NHSYNC; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2529 | |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2530 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2531 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2532 | else |
| 2533 | flags |= DRM_MODE_FLAG_NVSYNC; |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2534 | } else { |
| 2535 | if (tmp & DP_SYNC_HS_HIGH) |
| 2536 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2537 | else |
| 2538 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2539 | |
| 2540 | if (tmp & DP_SYNC_VS_HIGH) |
| 2541 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2542 | else |
| 2543 | flags |= DRM_MODE_FLAG_NVSYNC; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2544 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2545 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2546 | pipe_config->base.adjusted_mode.flags |= flags; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2547 | |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 2548 | if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235) |
Ville Syrjälä | 8c875fc | 2014-09-12 15:46:29 +0300 | [diff] [blame] | 2549 | pipe_config->limited_color_range = true; |
| 2550 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2551 | pipe_config->lane_count = |
| 2552 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; |
| 2553 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2554 | intel_dp_get_m_n(crtc, pipe_config); |
| 2555 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2556 | if (port == PORT_A) { |
Ville Syrjälä | b377e0d | 2015-10-29 21:25:59 +0200 | [diff] [blame] | 2557 | if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2558 | pipe_config->port_clock = 162000; |
| 2559 | else |
| 2560 | pipe_config->port_clock = 270000; |
| 2561 | } |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2562 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 2563 | pipe_config->base.adjusted_mode.crtc_clock = |
| 2564 | intel_dotclock_calculate(pipe_config->port_clock, |
| 2565 | &pipe_config->dp_m_n); |
Daniel Vetter | 7f16e5c | 2013-11-04 16:28:47 +0100 | [diff] [blame] | 2566 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2567 | if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp && |
| 2568 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2569 | /* |
| 2570 | * This is a big fat ugly hack. |
| 2571 | * |
| 2572 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2573 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2574 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2575 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2576 | * max, not what it tells us to use. |
| 2577 | * |
| 2578 | * Note: This will still be broken if the eDP panel is not lit |
| 2579 | * up by the BIOS, and thus we can't get the mode at module |
| 2580 | * load. |
| 2581 | */ |
| 2582 | DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2583 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2584 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2585 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2588 | static void intel_disable_dp(struct intel_encoder *encoder, |
| 2589 | struct intel_crtc_state *old_crtc_state, |
| 2590 | struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2591 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2592 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2593 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2594 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2595 | if (old_crtc_state->has_audio) |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2596 | intel_audio_codec_disable(encoder); |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2597 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2598 | if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv)) |
Rodrigo Vivi | b32c6f4 | 2014-11-20 03:44:37 -0800 | [diff] [blame] | 2599 | intel_psr_disable(intel_dp); |
| 2600 | |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2601 | /* Make sure the panel is off before trying to change the mode. But also |
| 2602 | * ensure that we have vdd while we switch off the panel. */ |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2603 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2604 | intel_edp_backlight_off(intel_dp); |
Jani Nikula | fdbc3b1 | 2013-11-12 17:10:13 +0200 | [diff] [blame] | 2605 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2606 | intel_edp_panel_off(intel_dp); |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2607 | |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2608 | /* disable the port before the pipe on g4x */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2609 | if (INTEL_GEN(dev_priv) < 5) |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2610 | intel_dp_link_down(intel_dp); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2613 | static void ilk_post_disable_dp(struct intel_encoder *encoder, |
| 2614 | struct intel_crtc_state *old_crtc_state, |
| 2615 | struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2616 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2617 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | 982a386 | 2013-05-23 19:39:40 +0300 | [diff] [blame] | 2618 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2619 | |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2620 | intel_dp_link_down(intel_dp); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2621 | |
| 2622 | /* Only ilk+ has port A */ |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2623 | if (port == PORT_A) |
| 2624 | ironlake_edp_pll_off(intel_dp); |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2625 | } |
| 2626 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2627 | static void vlv_post_disable_dp(struct intel_encoder *encoder, |
| 2628 | struct intel_crtc_state *old_crtc_state, |
| 2629 | struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2630 | { |
| 2631 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2632 | |
| 2633 | intel_dp_link_down(intel_dp); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2634 | } |
| 2635 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2636 | static void chv_post_disable_dp(struct intel_encoder *encoder, |
| 2637 | struct intel_crtc_state *old_crtc_state, |
| 2638 | struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2639 | { |
| 2640 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2641 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2642 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2643 | |
| 2644 | intel_dp_link_down(intel_dp); |
| 2645 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2646 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2647 | |
Ville Syrjälä | a8f327f | 2015-07-09 20:14:11 +0300 | [diff] [blame] | 2648 | /* Assert data lane reset */ |
| 2649 | chv_data_lane_soft_reset(encoder, true); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2650 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2651 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2652 | } |
| 2653 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2654 | static void |
| 2655 | _intel_dp_set_link_train(struct intel_dp *intel_dp, |
| 2656 | uint32_t *DP, |
| 2657 | uint8_t dp_train_pat) |
| 2658 | { |
| 2659 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2660 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2661 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2662 | enum port port = intel_dig_port->port; |
| 2663 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2664 | if (dp_train_pat & DP_TRAINING_PATTERN_MASK) |
| 2665 | DRM_DEBUG_KMS("Using DP training pattern TPS%d\n", |
| 2666 | dp_train_pat & DP_TRAINING_PATTERN_MASK); |
| 2667 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 2668 | if (HAS_DDI(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2669 | uint32_t temp = I915_READ(DP_TP_CTL(port)); |
| 2670 | |
| 2671 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) |
| 2672 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2673 | else |
| 2674 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2675 | |
| 2676 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 2677 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2678 | case DP_TRAINING_PATTERN_DISABLE: |
| 2679 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; |
| 2680 | |
| 2681 | break; |
| 2682 | case DP_TRAINING_PATTERN_1: |
| 2683 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2684 | break; |
| 2685 | case DP_TRAINING_PATTERN_2: |
| 2686 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; |
| 2687 | break; |
| 2688 | case DP_TRAINING_PATTERN_3: |
| 2689 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; |
| 2690 | break; |
| 2691 | } |
| 2692 | I915_WRITE(DP_TP_CTL(port), temp); |
| 2693 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2694 | } else if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2695 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2696 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 2697 | |
| 2698 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2699 | case DP_TRAINING_PATTERN_DISABLE: |
| 2700 | *DP |= DP_LINK_TRAIN_OFF_CPT; |
| 2701 | break; |
| 2702 | case DP_TRAINING_PATTERN_1: |
| 2703 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; |
| 2704 | break; |
| 2705 | case DP_TRAINING_PATTERN_2: |
| 2706 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2707 | break; |
| 2708 | case DP_TRAINING_PATTERN_3: |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2709 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2710 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2711 | break; |
| 2712 | } |
| 2713 | |
| 2714 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2715 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2716 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 2717 | else |
| 2718 | *DP &= ~DP_LINK_TRAIN_MASK; |
| 2719 | |
| 2720 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2721 | case DP_TRAINING_PATTERN_DISABLE: |
| 2722 | *DP |= DP_LINK_TRAIN_OFF; |
| 2723 | break; |
| 2724 | case DP_TRAINING_PATTERN_1: |
| 2725 | *DP |= DP_LINK_TRAIN_PAT_1; |
| 2726 | break; |
| 2727 | case DP_TRAINING_PATTERN_2: |
| 2728 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2729 | break; |
| 2730 | case DP_TRAINING_PATTERN_3: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2731 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2732 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; |
| 2733 | } else { |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2734 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2735 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2736 | } |
| 2737 | break; |
| 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2742 | static void intel_dp_enable_port(struct intel_dp *intel_dp, |
| 2743 | struct intel_crtc_state *old_crtc_state) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2744 | { |
| 2745 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2746 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2747 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2748 | /* enable with pattern 1 (as per spec) */ |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2749 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2750 | intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1); |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2751 | |
| 2752 | /* |
| 2753 | * Magic for VLV/CHV. We _must_ first set up the register |
| 2754 | * without actually enabling the port, and then do another |
| 2755 | * write to enable the port. Otherwise link training will |
| 2756 | * fail when the power sequencer is freshly used for this port. |
| 2757 | */ |
| 2758 | intel_dp->DP |= DP_PORT_EN; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2759 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2760 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2761 | |
| 2762 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 2763 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2764 | } |
| 2765 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2766 | static void intel_enable_dp(struct intel_encoder *encoder, |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2767 | struct intel_crtc_state *pipe_config, |
| 2768 | struct drm_connector_state *conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2769 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2770 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2771 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2772 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2773 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2774 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2775 | enum pipe pipe = crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2776 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 2777 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
| 2778 | return; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2779 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2780 | pps_lock(intel_dp); |
| 2781 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2782 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2783 | vlv_init_panel_power_sequencer(intel_dp); |
| 2784 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2785 | intel_dp_enable_port(intel_dp, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2786 | |
| 2787 | edp_panel_vdd_on(intel_dp); |
| 2788 | edp_panel_on(intel_dp); |
| 2789 | edp_panel_vdd_off(intel_dp, true); |
| 2790 | |
| 2791 | pps_unlock(intel_dp); |
| 2792 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2793 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2794 | unsigned int lane_mask = 0x0; |
| 2795 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2796 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2797 | lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2798 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 2799 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
| 2800 | lane_mask); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2801 | } |
Ville Syrjälä | 61234fa | 2014-10-16 21:27:34 +0300 | [diff] [blame] | 2802 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2803 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 2804 | intel_dp_start_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2805 | intel_dp_stop_link_train(intel_dp); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2806 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2807 | if (pipe_config->has_audio) { |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2808 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2809 | pipe_name(pipe)); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2810 | intel_audio_codec_enable(encoder, pipe_config, conn_state); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2811 | } |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2812 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2813 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2814 | static void g4x_enable_dp(struct intel_encoder *encoder, |
| 2815 | struct intel_crtc_state *pipe_config, |
| 2816 | struct drm_connector_state *conn_state) |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 2817 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2818 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2819 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2820 | intel_enable_dp(encoder, pipe_config, conn_state); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2821 | intel_edp_backlight_on(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2822 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2823 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2824 | static void vlv_enable_dp(struct intel_encoder *encoder, |
| 2825 | struct intel_crtc_state *pipe_config, |
| 2826 | struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2827 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2828 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2829 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2830 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | b32c6f4 | 2014-11-20 03:44:37 -0800 | [diff] [blame] | 2831 | intel_psr_enable(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2834 | static void g4x_pre_enable_dp(struct intel_encoder *encoder, |
| 2835 | struct intel_crtc_state *pipe_config, |
| 2836 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2837 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2838 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2839 | enum port port = dp_to_dig_port(intel_dp)->port; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2840 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2841 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 2842 | |
Daniel Vetter | d41f1ef | 2014-04-24 23:54:53 +0200 | [diff] [blame] | 2843 | /* Only ilk+ has port A */ |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2844 | if (port == PORT_A) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2845 | ironlake_edp_pll_on(intel_dp, pipe_config); |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2846 | } |
| 2847 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2848 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
| 2849 | { |
| 2850 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2851 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2852 | enum pipe pipe = intel_dp->pps_pipe; |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 2853 | i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2854 | |
| 2855 | edp_panel_vdd_off_sync(intel_dp); |
| 2856 | |
| 2857 | /* |
| 2858 | * VLV seems to get confused when multiple power seqeuencers |
| 2859 | * have the same port selected (even if only one has power/vdd |
| 2860 | * enabled). The failure manifests as vlv_wait_port_ready() failing |
| 2861 | * CHV on the other hand doesn't seem to mind having the same port |
| 2862 | * selected in multiple power seqeuencers, but let's clear the |
| 2863 | * port select always when logically disconnecting a power sequencer |
| 2864 | * from a port. |
| 2865 | */ |
| 2866 | DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n", |
| 2867 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 2868 | I915_WRITE(pp_on_reg, 0); |
| 2869 | POSTING_READ(pp_on_reg); |
| 2870 | |
| 2871 | intel_dp->pps_pipe = INVALID_PIPE; |
| 2872 | } |
| 2873 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2874 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 2875 | enum pipe pipe) |
| 2876 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2877 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2878 | struct intel_encoder *encoder; |
| 2879 | |
| 2880 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2881 | |
Ville Syrjälä | ac3c12e | 2014-10-16 21:29:56 +0300 | [diff] [blame] | 2882 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 2883 | return; |
| 2884 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 2885 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2886 | struct intel_dp *intel_dp; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2887 | enum port port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2888 | |
| 2889 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 2890 | continue; |
| 2891 | |
| 2892 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2893 | port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2894 | |
| 2895 | if (intel_dp->pps_pipe != pipe) |
| 2896 | continue; |
| 2897 | |
| 2898 | DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n", |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2899 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2900 | |
Maarten Lankhorst | e02f9a0 | 2015-08-05 12:37:08 +0200 | [diff] [blame] | 2901 | WARN(encoder->base.crtc, |
Ville Syrjälä | 034e43c | 2014-10-16 21:27:28 +0300 | [diff] [blame] | 2902 | "stealing pipe %c power sequencer from active eDP port %c\n", |
| 2903 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2904 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2905 | /* make sure vdd is off before we steal it */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2906 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp) |
| 2911 | { |
| 2912 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2913 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 2914 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2915 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2916 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2917 | |
| 2918 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2919 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2920 | if (!is_edp(intel_dp)) |
| 2921 | return; |
| 2922 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2923 | if (intel_dp->pps_pipe == crtc->pipe) |
| 2924 | return; |
| 2925 | |
| 2926 | /* |
| 2927 | * If another power sequencer was being used on this |
| 2928 | * port previously make sure to turn off vdd there while |
| 2929 | * we still have control of it. |
| 2930 | */ |
| 2931 | if (intel_dp->pps_pipe != INVALID_PIPE) |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2932 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2933 | |
| 2934 | /* |
| 2935 | * We may be stealing the power |
| 2936 | * sequencer from another port. |
| 2937 | */ |
| 2938 | vlv_steal_power_sequencer(dev, crtc->pipe); |
| 2939 | |
| 2940 | /* now it's all ours */ |
| 2941 | intel_dp->pps_pipe = crtc->pipe; |
| 2942 | |
| 2943 | DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n", |
| 2944 | pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port)); |
| 2945 | |
| 2946 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 2947 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
| 2948 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2949 | } |
| 2950 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2951 | static void vlv_pre_enable_dp(struct intel_encoder *encoder, |
| 2952 | struct intel_crtc_state *pipe_config, |
| 2953 | struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2954 | { |
Ander Conselvan de Oliveira | 5f68c27 | 2016-04-27 15:44:24 +0300 | [diff] [blame] | 2955 | vlv_phy_pre_encoder_enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2956 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2957 | intel_enable_dp(encoder, pipe_config, conn_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2960 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder, |
| 2961 | struct intel_crtc_state *pipe_config, |
| 2962 | struct drm_connector_state *conn_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2963 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2964 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 2965 | |
Ander Conselvan de Oliveira | 6da2e61 | 2016-04-27 15:44:23 +0300 | [diff] [blame] | 2966 | vlv_phy_pre_pll_enable(encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2969 | static void chv_pre_enable_dp(struct intel_encoder *encoder, |
| 2970 | struct intel_crtc_state *pipe_config, |
| 2971 | struct drm_connector_state *conn_state) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 2972 | { |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 2973 | chv_phy_pre_encoder_enable(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 2974 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2975 | intel_enable_dp(encoder, pipe_config, conn_state); |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 2976 | |
| 2977 | /* Second common lane will stay alive on its own now */ |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 2978 | chv_phy_release_cl2_override(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 2979 | } |
| 2980 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2981 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder, |
| 2982 | struct intel_crtc_state *pipe_config, |
| 2983 | struct drm_connector_state *conn_state) |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 2984 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2985 | intel_dp_prepare(encoder, pipe_config); |
Ville Syrjälä | 625695f | 2014-06-28 02:04:02 +0300 | [diff] [blame] | 2986 | |
Ander Conselvan de Oliveira | 419b1b7 | 2016-04-27 15:44:19 +0300 | [diff] [blame] | 2987 | chv_phy_pre_pll_enable(encoder); |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 2988 | } |
| 2989 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2990 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder, |
| 2991 | struct intel_crtc_state *pipe_config, |
| 2992 | struct drm_connector_state *conn_state) |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 2993 | { |
Ander Conselvan de Oliveira | 204970b | 2016-04-27 15:44:21 +0300 | [diff] [blame] | 2994 | chv_phy_post_pll_disable(encoder); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 2995 | } |
| 2996 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2997 | /* |
| 2998 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 2999 | * link status information |
| 3000 | */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3001 | bool |
Keith Packard | 93f62da | 2011-11-01 19:45:03 -0700 | [diff] [blame] | 3002 | intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE]) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3003 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3004 | return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status, |
| 3005 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Paulo Zanoni | 1100244 | 2014-06-13 18:45:41 -0300 | [diff] [blame] | 3008 | /* These are source-specific values. */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3009 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3010 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3011 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3012 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3013 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3014 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 3015 | if (IS_GEN9_LP(dev_priv)) |
Vandana Kannan | 9314726 | 2014-11-18 15:45:29 +0530 | [diff] [blame] | 3016 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3017 | else if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 06411f0 | 2016-03-24 17:50:21 +0200 | [diff] [blame] | 3018 | if (dev_priv->vbt.edp.low_vswing && port == PORT_A) |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3019 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3020 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3021 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3022 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3023 | else if (IS_GEN7(dev_priv) && port == PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3024 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3025 | else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3026 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3027 | else |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3028 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3029 | } |
| 3030 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3031 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3032 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
| 3033 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3034 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3035 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3036 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3037 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3038 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 3039 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3040 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3041 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3042 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3043 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3044 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3045 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
| 3046 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3047 | default: |
| 3048 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
| 3049 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3050 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3051 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3052 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3053 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3054 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3055 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3056 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3057 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3058 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3059 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3060 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3061 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3062 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3063 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3064 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3065 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3066 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3067 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3068 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3069 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3070 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3071 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3072 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3073 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3074 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3075 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3076 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3077 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3078 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3079 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3080 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3081 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3082 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3083 | } |
| 3084 | } else { |
| 3085 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3086 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3087 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3088 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3089 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3090 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3091 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3092 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3093 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3094 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3095 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3096 | } |
| 3097 | } |
| 3098 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3099 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3100 | { |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3101 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3102 | unsigned long demph_reg_value, preemph_reg_value, |
| 3103 | uniqtranscale_reg_value; |
| 3104 | uint8_t train_set = intel_dp->train_set[0]; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3105 | |
| 3106 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3107 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3108 | preemph_reg_value = 0x0004000; |
| 3109 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3110 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3111 | demph_reg_value = 0x2B405555; |
| 3112 | uniqtranscale_reg_value = 0x552AB83A; |
| 3113 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3114 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3115 | demph_reg_value = 0x2B404040; |
| 3116 | uniqtranscale_reg_value = 0x5548B83A; |
| 3117 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3118 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3119 | demph_reg_value = 0x2B245555; |
| 3120 | uniqtranscale_reg_value = 0x5560B83A; |
| 3121 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3122 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3123 | demph_reg_value = 0x2B405555; |
| 3124 | uniqtranscale_reg_value = 0x5598DA3A; |
| 3125 | break; |
| 3126 | default: |
| 3127 | return 0; |
| 3128 | } |
| 3129 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3130 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3131 | preemph_reg_value = 0x0002000; |
| 3132 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3133 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3134 | demph_reg_value = 0x2B404040; |
| 3135 | uniqtranscale_reg_value = 0x5552B83A; |
| 3136 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3137 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3138 | demph_reg_value = 0x2B404848; |
| 3139 | uniqtranscale_reg_value = 0x5580B83A; |
| 3140 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3141 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3142 | demph_reg_value = 0x2B404040; |
| 3143 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3144 | break; |
| 3145 | default: |
| 3146 | return 0; |
| 3147 | } |
| 3148 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3149 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3150 | preemph_reg_value = 0x0000000; |
| 3151 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3152 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3153 | demph_reg_value = 0x2B305555; |
| 3154 | uniqtranscale_reg_value = 0x5570B83A; |
| 3155 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3156 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3157 | demph_reg_value = 0x2B2B4040; |
| 3158 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3159 | break; |
| 3160 | default: |
| 3161 | return 0; |
| 3162 | } |
| 3163 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3164 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3165 | preemph_reg_value = 0x0006000; |
| 3166 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3167 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3168 | demph_reg_value = 0x1B405555; |
| 3169 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3170 | break; |
| 3171 | default: |
| 3172 | return 0; |
| 3173 | } |
| 3174 | break; |
| 3175 | default: |
| 3176 | return 0; |
| 3177 | } |
| 3178 | |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3179 | vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value, |
| 3180 | uniqtranscale_reg_value, 0); |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3181 | |
| 3182 | return 0; |
| 3183 | } |
| 3184 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3185 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3186 | { |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3187 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3188 | u32 deemph_reg_value, margin_reg_value; |
| 3189 | bool uniq_trans_scale = false; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3190 | uint8_t train_set = intel_dp->train_set[0]; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3191 | |
| 3192 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3193 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3194 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3195 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3196 | deemph_reg_value = 128; |
| 3197 | margin_reg_value = 52; |
| 3198 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3199 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3200 | deemph_reg_value = 128; |
| 3201 | margin_reg_value = 77; |
| 3202 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3203 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3204 | deemph_reg_value = 128; |
| 3205 | margin_reg_value = 102; |
| 3206 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3207 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3208 | deemph_reg_value = 128; |
| 3209 | margin_reg_value = 154; |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3210 | uniq_trans_scale = true; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3211 | break; |
| 3212 | default: |
| 3213 | return 0; |
| 3214 | } |
| 3215 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3216 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3217 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3218 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3219 | deemph_reg_value = 85; |
| 3220 | margin_reg_value = 78; |
| 3221 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3222 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3223 | deemph_reg_value = 85; |
| 3224 | margin_reg_value = 116; |
| 3225 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3226 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3227 | deemph_reg_value = 85; |
| 3228 | margin_reg_value = 154; |
| 3229 | break; |
| 3230 | default: |
| 3231 | return 0; |
| 3232 | } |
| 3233 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3234 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3235 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3236 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3237 | deemph_reg_value = 64; |
| 3238 | margin_reg_value = 104; |
| 3239 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3240 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3241 | deemph_reg_value = 64; |
| 3242 | margin_reg_value = 154; |
| 3243 | break; |
| 3244 | default: |
| 3245 | return 0; |
| 3246 | } |
| 3247 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3248 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3249 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3250 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3251 | deemph_reg_value = 43; |
| 3252 | margin_reg_value = 154; |
| 3253 | break; |
| 3254 | default: |
| 3255 | return 0; |
| 3256 | } |
| 3257 | break; |
| 3258 | default: |
| 3259 | return 0; |
| 3260 | } |
| 3261 | |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3262 | chv_set_phy_signal_level(encoder, deemph_reg_value, |
| 3263 | margin_reg_value, uniq_trans_scale); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3264 | |
| 3265 | return 0; |
| 3266 | } |
| 3267 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3268 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3269 | gen4_signal_levels(uint8_t train_set) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3270 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3271 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3272 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3273 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3274 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3275 | default: |
| 3276 | signal_levels |= DP_VOLTAGE_0_4; |
| 3277 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3278 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3279 | signal_levels |= DP_VOLTAGE_0_6; |
| 3280 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3281 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3282 | signal_levels |= DP_VOLTAGE_0_8; |
| 3283 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3284 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3285 | signal_levels |= DP_VOLTAGE_1_2; |
| 3286 | break; |
| 3287 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3288 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3289 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3290 | default: |
| 3291 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 3292 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3293 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3294 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 3295 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3296 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3297 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 3298 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3299 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3300 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 3301 | break; |
| 3302 | } |
| 3303 | return signal_levels; |
| 3304 | } |
| 3305 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3306 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 3307 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3308 | gen6_edp_signal_levels(uint8_t train_set) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3309 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3310 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3311 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3312 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3313 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3314 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3315 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3316 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3317 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3318 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 3319 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3320 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3321 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 3322 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3323 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3324 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3325 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3326 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3327 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3328 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3329 | "0x%x\n", signal_levels); |
| 3330 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3331 | } |
| 3332 | } |
| 3333 | |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3334 | /* Gen7's DP voltage swing and pre-emphasis control */ |
| 3335 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3336 | gen7_edp_signal_levels(uint8_t train_set) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3337 | { |
| 3338 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3339 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3340 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3341 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3342 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3343 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3344 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3345 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3346 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
| 3347 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3348 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3349 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3350 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3351 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
| 3352 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3353 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3354 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3355 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3356 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
| 3357 | |
| 3358 | default: |
| 3359 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3360 | "0x%x\n", signal_levels); |
| 3361 | return EDP_LINK_TRAIN_500MV_0DB_IVB; |
| 3362 | } |
| 3363 | } |
| 3364 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3365 | void |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3366 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3367 | { |
| 3368 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3369 | enum port port = intel_dig_port->port; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3370 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3371 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3372 | uint32_t signal_levels, mask = 0; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3373 | uint8_t train_set = intel_dp->train_set[0]; |
| 3374 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3375 | if (HAS_DDI(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3376 | signal_levels = ddi_signal_levels(intel_dp); |
| 3377 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 3378 | if (IS_BROXTON(dev_priv)) |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3379 | signal_levels = 0; |
| 3380 | else |
| 3381 | mask = DDI_BUF_EMP_MASK; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3382 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3383 | signal_levels = chv_signal_levels(intel_dp); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 3384 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3385 | signal_levels = vlv_signal_levels(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3386 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3387 | signal_levels = gen7_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3388 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3389 | } else if (IS_GEN6(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3390 | signal_levels = gen6_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3391 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
| 3392 | } else { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3393 | signal_levels = gen4_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3394 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
| 3395 | } |
| 3396 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 3397 | if (mask) |
| 3398 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); |
| 3399 | |
| 3400 | DRM_DEBUG_KMS("Using vswing level %d\n", |
| 3401 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); |
| 3402 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", |
| 3403 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> |
| 3404 | DP_TRAIN_PRE_EMPHASIS_SHIFT); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3405 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3406 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3407 | |
| 3408 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 3409 | POSTING_READ(intel_dp->output_reg); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3410 | } |
| 3411 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3412 | void |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3413 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
| 3414 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3415 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 3416 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 3417 | struct drm_i915_private *dev_priv = |
| 3418 | to_i915(intel_dig_port->base.base.dev); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3419 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3420 | _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat); |
Paulo Zanoni | 47ea754 | 2012-07-17 16:55:16 -0300 | [diff] [blame] | 3421 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3422 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3423 | POSTING_READ(intel_dp->output_reg); |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3424 | } |
| 3425 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3426 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3427 | { |
| 3428 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3429 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3430 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3431 | enum port port = intel_dig_port->port; |
| 3432 | uint32_t val; |
| 3433 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3434 | if (!HAS_DDI(dev_priv)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3435 | return; |
| 3436 | |
| 3437 | val = I915_READ(DP_TP_CTL(port)); |
| 3438 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 3439 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; |
| 3440 | I915_WRITE(DP_TP_CTL(port), val); |
| 3441 | |
| 3442 | /* |
| 3443 | * On PORT_A we can have only eDP in SST mode. There the only reason |
| 3444 | * we need to set idle transmission mode is to work around a HW issue |
| 3445 | * where we enable the pipe while not in idle link-training mode. |
| 3446 | * In this case there is requirement to wait for a minimum number of |
| 3447 | * idle patterns to be sent. |
| 3448 | */ |
| 3449 | if (port == PORT_A) |
| 3450 | return; |
| 3451 | |
Chris Wilson | a767017 | 2016-06-30 15:33:10 +0100 | [diff] [blame] | 3452 | if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port), |
| 3453 | DP_TP_STATUS_IDLE_DONE, |
| 3454 | DP_TP_STATUS_IDLE_DONE, |
| 3455 | 1)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3456 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); |
| 3457 | } |
| 3458 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3459 | static void |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3460 | intel_dp_link_down(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3461 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3462 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3463 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3464 | enum port port = intel_dig_port->port; |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3465 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3466 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3467 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3468 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3469 | if (WARN_ON(HAS_DDI(dev_priv))) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 3470 | return; |
| 3471 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 3472 | if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)) |
Chris Wilson | 1b39d6f | 2010-12-06 11:20:45 +0000 | [diff] [blame] | 3473 | return; |
| 3474 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3475 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3476 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3477 | if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3478 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3479 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3480 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3481 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3482 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | aad3d14 | 2014-06-28 02:04:25 +0300 | [diff] [blame] | 3483 | DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 3484 | else |
| 3485 | DP &= ~DP_LINK_TRAIN_MASK; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3486 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3487 | } |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3488 | I915_WRITE(intel_dp->output_reg, DP); |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 3489 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3490 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3491 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
| 3492 | I915_WRITE(intel_dp->output_reg, DP); |
| 3493 | POSTING_READ(intel_dp->output_reg); |
| 3494 | |
| 3495 | /* |
| 3496 | * HW workaround for IBX, we need to move the port |
| 3497 | * to transcoder A after disabling it to allow the |
| 3498 | * matching HDMI port to be enabled on transcoder A. |
| 3499 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3500 | if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) { |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3501 | /* |
| 3502 | * We get CPU/PCH FIFO underruns on the other pipe when |
| 3503 | * doing the workaround. Sweep them under the rug. |
| 3504 | */ |
| 3505 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3506 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3507 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3508 | /* always enable with pattern 1 (as per spec) */ |
| 3509 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); |
| 3510 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; |
| 3511 | I915_WRITE(intel_dp->output_reg, DP); |
| 3512 | POSTING_READ(intel_dp->output_reg); |
| 3513 | |
| 3514 | DP &= ~DP_PORT_EN; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3515 | I915_WRITE(intel_dp->output_reg, DP); |
Daniel Vetter | 0ca0968 | 2014-11-24 16:54:11 +0100 | [diff] [blame] | 3516 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3517 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3518 | intel_wait_for_vblank_if_active(dev_priv, PIPE_A); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3519 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
| 3520 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3521 | } |
| 3522 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 3523 | msleep(intel_dp->panel_power_down_delay); |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 3524 | |
| 3525 | intel_dp->DP = DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Imre Deak | 24e807e | 2016-10-24 19:33:28 +0300 | [diff] [blame] | 3528 | bool |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3529 | intel_dp_read_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3530 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3531 | if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, |
| 3532 | sizeof(intel_dp->dpcd)) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3533 | return false; /* aux transfer failed */ |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3534 | |
Andy Shevchenko | a8e9815 | 2014-09-01 14:12:01 +0300 | [diff] [blame] | 3535 | DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd); |
Damien Lespiau | 577c7a5 | 2012-12-13 16:09:02 +0000 | [diff] [blame] | 3536 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3537 | return intel_dp->dpcd[DP_DPCD_REV] != 0; |
| 3538 | } |
| 3539 | |
| 3540 | static bool |
| 3541 | intel_edp_init_dpcd(struct intel_dp *intel_dp) |
| 3542 | { |
| 3543 | struct drm_i915_private *dev_priv = |
| 3544 | to_i915(dp_to_dig_port(intel_dp)->base.base.dev); |
| 3545 | |
| 3546 | /* this function is meant to be called only once */ |
| 3547 | WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0); |
| 3548 | |
| 3549 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3550 | return false; |
| 3551 | |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 3552 | intel_dp_read_desc(intel_dp); |
| 3553 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3554 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 3555 | dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
| 3556 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 3557 | |
| 3558 | /* Check if the panel supports PSR */ |
| 3559 | drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT, |
| 3560 | intel_dp->psr_dpcd, |
| 3561 | sizeof(intel_dp->psr_dpcd)); |
| 3562 | if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) { |
| 3563 | dev_priv->psr.sink_support = true; |
| 3564 | DRM_DEBUG_KMS("Detected EDP PSR Panel.\n"); |
| 3565 | } |
| 3566 | |
| 3567 | if (INTEL_GEN(dev_priv) >= 9 && |
| 3568 | (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) { |
| 3569 | uint8_t frame_sync_cap; |
| 3570 | |
| 3571 | dev_priv->psr.sink_support = true; |
| 3572 | drm_dp_dpcd_read(&intel_dp->aux, |
| 3573 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP, |
| 3574 | &frame_sync_cap, 1); |
| 3575 | dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false; |
| 3576 | /* PSR2 needs frame sync as well */ |
| 3577 | dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync; |
| 3578 | DRM_DEBUG_KMS("PSR2 %s on sink", |
| 3579 | dev_priv->psr.psr2_support ? "supported" : "not supported"); |
| 3580 | } |
| 3581 | |
| 3582 | /* Read the eDP Display control capabilities registers */ |
| 3583 | if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) && |
| 3584 | drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, |
Dan Carpenter | f7170e2 | 2016-10-13 11:55:08 +0300 | [diff] [blame] | 3585 | intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == |
| 3586 | sizeof(intel_dp->edp_dpcd)) |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3587 | DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd), |
| 3588 | intel_dp->edp_dpcd); |
| 3589 | |
| 3590 | /* Intermediate frequency support */ |
| 3591 | if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */ |
| 3592 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
| 3593 | int i; |
| 3594 | |
| 3595 | drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES, |
| 3596 | sink_rates, sizeof(sink_rates)); |
| 3597 | |
| 3598 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
| 3599 | int val = le16_to_cpu(sink_rates[i]); |
| 3600 | |
| 3601 | if (val == 0) |
| 3602 | break; |
| 3603 | |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 3604 | /* Value read multiplied by 200kHz gives the per-lane |
| 3605 | * link rate in kHz. The source rates are, however, |
| 3606 | * stored in terms of LS_Clk kHz. The full conversion |
| 3607 | * back to symbols is |
| 3608 | * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) |
| 3609 | */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3610 | intel_dp->sink_rates[i] = (val * 200) / 10; |
| 3611 | } |
| 3612 | intel_dp->num_sink_rates = i; |
| 3613 | } |
| 3614 | |
| 3615 | return true; |
| 3616 | } |
| 3617 | |
| 3618 | |
| 3619 | static bool |
| 3620 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
| 3621 | { |
| 3622 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3623 | return false; |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3624 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3625 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT, |
| 3626 | &intel_dp->sink_count, 1) < 0) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3627 | return false; |
| 3628 | |
| 3629 | /* |
| 3630 | * Sink count can change between short pulse hpd hence |
| 3631 | * a member variable in intel_dp will track any changes |
| 3632 | * between short pulse interrupts. |
| 3633 | */ |
| 3634 | intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count); |
| 3635 | |
| 3636 | /* |
| 3637 | * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that |
| 3638 | * a dongle is present but no display. Unless we require to know |
| 3639 | * if a dongle is present or not, we don't need to update |
| 3640 | * downstream port information. So, an early return here saves |
| 3641 | * time from performing other operations which are not required. |
| 3642 | */ |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 3643 | if (!is_edp(intel_dp) && !intel_dp->sink_count) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3644 | return false; |
| 3645 | |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 3646 | if (!drm_dp_is_branch(intel_dp->dpcd)) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3647 | return true; /* native DP sink */ |
| 3648 | |
| 3649 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) |
| 3650 | return true; /* no per-port downstream info */ |
| 3651 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3652 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
| 3653 | intel_dp->downstream_ports, |
| 3654 | DP_MAX_DOWNSTREAM_PORTS) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3655 | return false; /* downstream port status fetch failed */ |
| 3656 | |
| 3657 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3660 | static bool |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3661 | intel_dp_can_mst(struct intel_dp *intel_dp) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3662 | { |
| 3663 | u8 buf[1]; |
| 3664 | |
Nathan Schulte | 7cc9613 | 2016-03-15 10:14:05 -0500 | [diff] [blame] | 3665 | if (!i915.enable_dp_mst) |
| 3666 | return false; |
| 3667 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3668 | if (!intel_dp->can_mst) |
| 3669 | return false; |
| 3670 | |
| 3671 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) |
| 3672 | return false; |
| 3673 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3674 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1) |
| 3675 | return false; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3676 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3677 | return buf[0] & DP_MST_CAP; |
| 3678 | } |
| 3679 | |
| 3680 | static void |
| 3681 | intel_dp_configure_mst(struct intel_dp *intel_dp) |
| 3682 | { |
| 3683 | if (!i915.enable_dp_mst) |
| 3684 | return; |
| 3685 | |
| 3686 | if (!intel_dp->can_mst) |
| 3687 | return; |
| 3688 | |
| 3689 | intel_dp->is_mst = intel_dp_can_mst(intel_dp); |
| 3690 | |
| 3691 | if (intel_dp->is_mst) |
| 3692 | DRM_DEBUG_KMS("Sink is MST capable\n"); |
| 3693 | else |
| 3694 | DRM_DEBUG_KMS("Sink is not MST capable\n"); |
| 3695 | |
| 3696 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 3697 | intel_dp->is_mst); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3698 | } |
| 3699 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3700 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp) |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3701 | { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3702 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3703 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3704 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3705 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3706 | int ret = 0; |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3707 | int count = 0; |
| 3708 | int attempts = 10; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3709 | |
| 3710 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3711 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3712 | ret = -EIO; |
| 3713 | goto out; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3714 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3715 | |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3716 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3717 | buf & ~DP_TEST_SINK_START) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3718 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3719 | ret = -EIO; |
| 3720 | goto out; |
| 3721 | } |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3722 | |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3723 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3724 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3725 | |
| 3726 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3727 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3728 | ret = -EIO; |
| 3729 | goto out; |
| 3730 | } |
| 3731 | count = buf & DP_TEST_COUNT_MASK; |
| 3732 | } while (--attempts && count); |
| 3733 | |
| 3734 | if (attempts == 0) { |
Rodrigo Vivi | dc5a903 | 2016-01-29 14:44:59 -0800 | [diff] [blame] | 3735 | DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n"); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3736 | ret = -ETIMEDOUT; |
| 3737 | } |
| 3738 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3739 | out: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3740 | hsw_enable_ips(intel_crtc); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3741 | return ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp) |
| 3745 | { |
| 3746 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3747 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3748 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3749 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3750 | int ret; |
| 3751 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3752 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0) |
| 3753 | return -EIO; |
| 3754 | |
| 3755 | if (!(buf & DP_TEST_CRC_SUPPORTED)) |
| 3756 | return -ENOTTY; |
| 3757 | |
| 3758 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) |
| 3759 | return -EIO; |
| 3760 | |
Rodrigo Vivi | 6d8175d | 2015-11-05 10:50:22 -0800 | [diff] [blame] | 3761 | if (buf & DP_TEST_SINK_START) { |
| 3762 | ret = intel_dp_sink_crc_stop(intel_dp); |
| 3763 | if (ret) |
| 3764 | return ret; |
| 3765 | } |
| 3766 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3767 | hsw_disable_ips(intel_crtc); |
| 3768 | |
| 3769 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
| 3770 | buf | DP_TEST_SINK_START) < 0) { |
| 3771 | hsw_enable_ips(intel_crtc); |
| 3772 | return -EIO; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3773 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3774 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3775 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3776 | return 0; |
| 3777 | } |
| 3778 | |
| 3779 | int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc) |
| 3780 | { |
| 3781 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3782 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3783 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3784 | u8 buf; |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3785 | int count, ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3786 | int attempts = 6; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3787 | |
| 3788 | ret = intel_dp_sink_crc_start(intel_dp); |
| 3789 | if (ret) |
| 3790 | return ret; |
| 3791 | |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3792 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3793 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3794 | |
Rodrigo Vivi | 1dda5f9 | 2014-10-01 07:32:37 -0700 | [diff] [blame] | 3795 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3796 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3797 | ret = -EIO; |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3798 | goto stop; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3799 | } |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3800 | count = buf & DP_TEST_COUNT_MASK; |
Rodrigo Vivi | aabc95d | 2015-07-23 16:35:50 -0700 | [diff] [blame] | 3801 | |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3802 | } while (--attempts && count == 0); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3803 | |
| 3804 | if (attempts == 0) { |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3805 | DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n"); |
| 3806 | ret = -ETIMEDOUT; |
| 3807 | goto stop; |
| 3808 | } |
| 3809 | |
| 3810 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) { |
| 3811 | ret = -EIO; |
| 3812 | goto stop; |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3813 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3814 | |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3815 | stop: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3816 | intel_dp_sink_crc_stop(intel_dp); |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3817 | return ret; |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3818 | } |
| 3819 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3820 | static bool |
| 3821 | intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3822 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3823 | return drm_dp_dpcd_read(&intel_dp->aux, |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 3824 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 3825 | sink_irq_vector, 1) == 1; |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3828 | static bool |
| 3829 | intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3830 | { |
| 3831 | int ret; |
| 3832 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3833 | ret = drm_dp_dpcd_read(&intel_dp->aux, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3834 | DP_SINK_COUNT_ESI, |
| 3835 | sink_irq_vector, 14); |
| 3836 | if (ret != 14) |
| 3837 | return false; |
| 3838 | |
| 3839 | return true; |
| 3840 | } |
| 3841 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3842 | static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp) |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3843 | { |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3844 | uint8_t test_result = DP_TEST_ACK; |
| 3845 | return test_result; |
| 3846 | } |
| 3847 | |
| 3848 | static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp) |
| 3849 | { |
| 3850 | uint8_t test_result = DP_TEST_NAK; |
| 3851 | return test_result; |
| 3852 | } |
| 3853 | |
| 3854 | static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp) |
| 3855 | { |
| 3856 | uint8_t test_result = DP_TEST_NAK; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3857 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 3858 | struct drm_connector *connector = &intel_connector->base; |
| 3859 | |
| 3860 | if (intel_connector->detect_edid == NULL || |
Daniel Vetter | ac6f2e2 | 2015-05-08 16:15:41 +0200 | [diff] [blame] | 3861 | connector->edid_corrupt || |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3862 | intel_dp->aux.i2c_defer_count > 6) { |
| 3863 | /* Check EDID read for NACKs, DEFERs and corruption |
| 3864 | * (DP CTS 1.2 Core r1.1) |
| 3865 | * 4.2.2.4 : Failed EDID read, I2C_NAK |
| 3866 | * 4.2.2.5 : Failed EDID read, I2C_DEFER |
| 3867 | * 4.2.2.6 : EDID corruption detected |
| 3868 | * Use failsafe mode for all cases |
| 3869 | */ |
| 3870 | if (intel_dp->aux.i2c_nack_count > 0 || |
| 3871 | intel_dp->aux.i2c_defer_count > 0) |
| 3872 | DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n", |
| 3873 | intel_dp->aux.i2c_nack_count, |
| 3874 | intel_dp->aux.i2c_defer_count); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3875 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3876 | } else { |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 3877 | struct edid *block = intel_connector->detect_edid; |
| 3878 | |
| 3879 | /* We have to write the checksum |
| 3880 | * of the last block read |
| 3881 | */ |
| 3882 | block += intel_connector->detect_edid->extensions; |
| 3883 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3884 | if (!drm_dp_dpcd_write(&intel_dp->aux, |
| 3885 | DP_TEST_EDID_CHECKSUM, |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 3886 | &block->checksum, |
Dan Carpenter | 5a1cc65 | 2015-05-12 21:07:37 +0300 | [diff] [blame] | 3887 | 1)) |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3888 | DRM_DEBUG_KMS("Failed to write EDID checksum\n"); |
| 3889 | |
| 3890 | test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE; |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3891 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | /* Set test active flag here so userspace doesn't interrupt things */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3895 | intel_dp->compliance.test_active = 1; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 3896 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3897 | return test_result; |
| 3898 | } |
| 3899 | |
| 3900 | static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp) |
| 3901 | { |
| 3902 | uint8_t test_result = DP_TEST_NAK; |
| 3903 | return test_result; |
| 3904 | } |
| 3905 | |
| 3906 | static void intel_dp_handle_test_request(struct intel_dp *intel_dp) |
| 3907 | { |
| 3908 | uint8_t response = DP_TEST_NAK; |
| 3909 | uint8_t rxdata = 0; |
| 3910 | int status = 0; |
| 3911 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3912 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1); |
| 3913 | if (status <= 0) { |
| 3914 | DRM_DEBUG_KMS("Could not read test request from sink\n"); |
| 3915 | goto update_status; |
| 3916 | } |
| 3917 | |
| 3918 | switch (rxdata) { |
| 3919 | case DP_TEST_LINK_TRAINING: |
| 3920 | DRM_DEBUG_KMS("LINK_TRAINING test requested\n"); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3921 | intel_dp->compliance.test_type = DP_TEST_LINK_TRAINING; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3922 | response = intel_dp_autotest_link_training(intel_dp); |
| 3923 | break; |
| 3924 | case DP_TEST_LINK_VIDEO_PATTERN: |
| 3925 | DRM_DEBUG_KMS("TEST_PATTERN test requested\n"); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3926 | intel_dp->compliance.test_type = DP_TEST_LINK_VIDEO_PATTERN; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3927 | response = intel_dp_autotest_video_pattern(intel_dp); |
| 3928 | break; |
| 3929 | case DP_TEST_LINK_EDID_READ: |
| 3930 | DRM_DEBUG_KMS("EDID test requested\n"); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3931 | intel_dp->compliance.test_type = DP_TEST_LINK_EDID_READ; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3932 | response = intel_dp_autotest_edid(intel_dp); |
| 3933 | break; |
| 3934 | case DP_TEST_LINK_PHY_TEST_PATTERN: |
| 3935 | DRM_DEBUG_KMS("PHY_PATTERN test requested\n"); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 3936 | intel_dp->compliance.test_type = DP_TEST_LINK_PHY_TEST_PATTERN; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3937 | response = intel_dp_autotest_phy_pattern(intel_dp); |
| 3938 | break; |
| 3939 | default: |
| 3940 | DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata); |
| 3941 | break; |
| 3942 | } |
| 3943 | |
| 3944 | update_status: |
| 3945 | status = drm_dp_dpcd_write(&intel_dp->aux, |
| 3946 | DP_TEST_RESPONSE, |
| 3947 | &response, 1); |
| 3948 | if (status <= 0) |
| 3949 | DRM_DEBUG_KMS("Could not write test response to sink\n"); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3950 | } |
| 3951 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3952 | static int |
| 3953 | intel_dp_check_mst_status(struct intel_dp *intel_dp) |
| 3954 | { |
| 3955 | bool bret; |
| 3956 | |
| 3957 | if (intel_dp->is_mst) { |
| 3958 | u8 esi[16] = { 0 }; |
| 3959 | int ret = 0; |
| 3960 | int retry; |
| 3961 | bool handled; |
| 3962 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 3963 | go_again: |
| 3964 | if (bret == true) { |
| 3965 | |
| 3966 | /* check link status - esi[10] = 0x200c */ |
Ville Syrjälä | 19e0b4c | 2016-08-05 19:05:42 +0300 | [diff] [blame] | 3967 | if (intel_dp->active_mst_links && |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 3968 | !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3969 | DRM_DEBUG_KMS("channel EQ not ok, retraining\n"); |
| 3970 | intel_dp_start_link_train(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3971 | intel_dp_stop_link_train(intel_dp); |
| 3972 | } |
| 3973 | |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 3974 | DRM_DEBUG_KMS("got esi %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3975 | ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); |
| 3976 | |
| 3977 | if (handled) { |
| 3978 | for (retry = 0; retry < 3; retry++) { |
| 3979 | int wret; |
| 3980 | wret = drm_dp_dpcd_write(&intel_dp->aux, |
| 3981 | DP_SINK_COUNT_ESI+1, |
| 3982 | &esi[1], 3); |
| 3983 | if (wret == 3) { |
| 3984 | break; |
| 3985 | } |
| 3986 | } |
| 3987 | |
| 3988 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 3989 | if (bret == true) { |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 3990 | DRM_DEBUG_KMS("got esi2 %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3991 | goto go_again; |
| 3992 | } |
| 3993 | } else |
| 3994 | ret = 0; |
| 3995 | |
| 3996 | return ret; |
| 3997 | } else { |
| 3998 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3999 | DRM_DEBUG_KMS("failed to get ESI - device may have failed\n"); |
| 4000 | intel_dp->is_mst = false; |
| 4001 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); |
| 4002 | /* send a hotplug event */ |
| 4003 | drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev); |
| 4004 | } |
| 4005 | } |
| 4006 | return -EINVAL; |
| 4007 | } |
| 4008 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4009 | static void |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4010 | intel_dp_retrain_link(struct intel_dp *intel_dp) |
| 4011 | { |
| 4012 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 4013 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4014 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 4015 | |
| 4016 | /* Suppress underruns caused by re-training */ |
| 4017 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
| 4018 | if (crtc->config->has_pch_encoder) |
| 4019 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4020 | intel_crtc_pch_transcoder(crtc), false); |
| 4021 | |
| 4022 | intel_dp_start_link_train(intel_dp); |
| 4023 | intel_dp_stop_link_train(intel_dp); |
| 4024 | |
| 4025 | /* Keep underrun reporting disabled until things are stable */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4026 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4027 | |
| 4028 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 4029 | if (crtc->config->has_pch_encoder) |
| 4030 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4031 | intel_crtc_pch_transcoder(crtc), true); |
| 4032 | } |
| 4033 | |
| 4034 | static void |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4035 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
| 4036 | { |
| 4037 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
| 4038 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
| 4039 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 4040 | |
| 4041 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 4042 | |
| 4043 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
| 4044 | DRM_ERROR("Failed to get link status\n"); |
| 4045 | return; |
| 4046 | } |
| 4047 | |
| 4048 | if (!intel_encoder->base.crtc) |
| 4049 | return; |
| 4050 | |
| 4051 | if (!to_intel_crtc(intel_encoder->base.crtc)->active) |
| 4052 | return; |
| 4053 | |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4054 | /* FIXME: we need to synchronize this sort of stuff with hardware |
| 4055 | * readout */ |
| 4056 | if (WARN_ON_ONCE(!intel_dp->lane_count)) |
| 4057 | return; |
| 4058 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4059 | /* if link training is requested we should perform it always */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4060 | if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) || |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4061 | (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) { |
| 4062 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
| 4063 | intel_encoder->base.name); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4064 | |
| 4065 | intel_dp_retrain_link(intel_dp); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4066 | } |
| 4067 | } |
| 4068 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4069 | /* |
| 4070 | * According to DP spec |
| 4071 | * 5.1.2: |
| 4072 | * 1. Read DPCD |
| 4073 | * 2. Configure link according to Receiver Capabilities |
| 4074 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 4075 | * 4. Check link status on receipt of hot-plug interrupt |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4076 | * |
| 4077 | * intel_dp_short_pulse - handles short pulse interrupts |
| 4078 | * when full detection is not required. |
| 4079 | * Returns %true if short pulse is handled and full detection |
| 4080 | * is NOT required and %false otherwise. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4081 | */ |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4082 | static bool |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4083 | intel_dp_short_pulse(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4084 | { |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4085 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4086 | u8 sink_irq_vector = 0; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4087 | u8 old_sink_count = intel_dp->sink_count; |
| 4088 | bool ret; |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4089 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4090 | /* |
| 4091 | * Clearing compliance test variables to allow capturing |
| 4092 | * of values for next automated test request. |
| 4093 | */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4094 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4095 | |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4096 | /* |
| 4097 | * Now read the DPCD to see if it's actually running |
| 4098 | * If the current value of sink count doesn't match with |
| 4099 | * the value that was stored earlier or dpcd read failed |
| 4100 | * we need to do full detection |
| 4101 | */ |
| 4102 | ret = intel_dp_get_dpcd(intel_dp); |
| 4103 | |
| 4104 | if ((old_sink_count != intel_dp->sink_count) || !ret) { |
| 4105 | /* No need to proceed if we are going to do full detect */ |
| 4106 | return false; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4109 | /* Try to read the source of the interrupt */ |
| 4110 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4111 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4112 | sink_irq_vector != 0) { |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4113 | /* Clear interrupt source */ |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4114 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4115 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4116 | sink_irq_vector); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4117 | |
| 4118 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4119 | DRM_DEBUG_DRIVER("Test request in short pulse not handled\n"); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4120 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4121 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4122 | } |
| 4123 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4124 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4125 | intel_dp_check_link_status(intel_dp); |
| 4126 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4127 | |
| 4128 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4129 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4130 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4131 | /* XXX this is probably wrong for multiple downstream ports */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4132 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4133 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4134 | { |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4135 | uint8_t *dpcd = intel_dp->dpcd; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4136 | uint8_t type; |
| 4137 | |
| 4138 | if (!intel_dp_get_dpcd(intel_dp)) |
| 4139 | return connector_status_disconnected; |
| 4140 | |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 4141 | if (is_edp(intel_dp)) |
| 4142 | return connector_status_connected; |
| 4143 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4144 | /* if there's no downstream port, we're done */ |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 4145 | if (!drm_dp_is_branch(dpcd)) |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4146 | return connector_status_connected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4147 | |
| 4148 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4149 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 4150 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4151 | |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 4152 | return intel_dp->sink_count ? |
| 4153 | connector_status_connected : connector_status_disconnected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4154 | } |
| 4155 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4156 | if (intel_dp_can_mst(intel_dp)) |
| 4157 | return connector_status_connected; |
| 4158 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4159 | /* If no HPD, poke DDC gently */ |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 4160 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4161 | return connector_status_connected; |
| 4162 | |
| 4163 | /* Well we tried, say unknown for unreliable port types */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4164 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 4165 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 4166 | if (type == DP_DS_PORT_TYPE_VGA || |
| 4167 | type == DP_DS_PORT_TYPE_NON_EDID) |
| 4168 | return connector_status_unknown; |
| 4169 | } else { |
| 4170 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
| 4171 | DP_DWN_STRM_PORT_TYPE_MASK; |
| 4172 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || |
| 4173 | type == DP_DWN_STRM_PORT_TYPE_OTHER) |
| 4174 | return connector_status_unknown; |
| 4175 | } |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4176 | |
| 4177 | /* Anything else is out of spec, warn and ignore */ |
| 4178 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4179 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | static enum drm_connector_status |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4183 | edp_detect(struct intel_dp *intel_dp) |
| 4184 | { |
| 4185 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4186 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4187 | enum drm_connector_status status; |
| 4188 | |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4189 | status = intel_panel_detect(dev_priv); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4190 | if (status == connector_status_unknown) |
| 4191 | status = connector_status_connected; |
| 4192 | |
| 4193 | return status; |
| 4194 | } |
| 4195 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4196 | static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4197 | struct intel_digital_port *port) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4198 | { |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4199 | u32 bit; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 4200 | |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4201 | switch (port->port) { |
| 4202 | case PORT_A: |
| 4203 | return true; |
| 4204 | case PORT_B: |
| 4205 | bit = SDE_PORTB_HOTPLUG; |
| 4206 | break; |
| 4207 | case PORT_C: |
| 4208 | bit = SDE_PORTC_HOTPLUG; |
| 4209 | break; |
| 4210 | case PORT_D: |
| 4211 | bit = SDE_PORTD_HOTPLUG; |
| 4212 | break; |
| 4213 | default: |
| 4214 | MISSING_CASE(port->port); |
| 4215 | return false; |
| 4216 | } |
| 4217 | |
| 4218 | return I915_READ(SDEISR) & bit; |
| 4219 | } |
| 4220 | |
| 4221 | static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4222 | struct intel_digital_port *port) |
| 4223 | { |
| 4224 | u32 bit; |
| 4225 | |
| 4226 | switch (port->port) { |
| 4227 | case PORT_A: |
| 4228 | return true; |
| 4229 | case PORT_B: |
| 4230 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 4231 | break; |
| 4232 | case PORT_C: |
| 4233 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 4234 | break; |
| 4235 | case PORT_D: |
| 4236 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 4237 | break; |
Jani Nikula | a78695d | 2015-09-18 15:54:50 +0300 | [diff] [blame] | 4238 | case PORT_E: |
| 4239 | bit = SDE_PORTE_HOTPLUG_SPT; |
| 4240 | break; |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4241 | default: |
| 4242 | MISSING_CASE(port->port); |
| 4243 | return false; |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4244 | } |
Damien Lespiau | 1b46963 | 2012-12-13 16:09:01 +0000 | [diff] [blame] | 4245 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4246 | return I915_READ(SDEISR) & bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4247 | } |
| 4248 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4249 | static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv, |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4250 | struct intel_digital_port *port) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4251 | { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4252 | u32 bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4253 | |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4254 | switch (port->port) { |
| 4255 | case PORT_B: |
| 4256 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; |
| 4257 | break; |
| 4258 | case PORT_C: |
| 4259 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; |
| 4260 | break; |
| 4261 | case PORT_D: |
| 4262 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; |
| 4263 | break; |
| 4264 | default: |
| 4265 | MISSING_CASE(port->port); |
| 4266 | return false; |
| 4267 | } |
| 4268 | |
| 4269 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 4270 | } |
| 4271 | |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4272 | static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4273 | struct intel_digital_port *port) |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4274 | { |
| 4275 | u32 bit; |
| 4276 | |
| 4277 | switch (port->port) { |
| 4278 | case PORT_B: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4279 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4280 | break; |
| 4281 | case PORT_C: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4282 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4283 | break; |
| 4284 | case PORT_D: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4285 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4286 | break; |
| 4287 | default: |
| 4288 | MISSING_CASE(port->port); |
| 4289 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4292 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
Dave Airlie | 2a592be | 2014-09-01 16:58:12 +1000 | [diff] [blame] | 4293 | } |
| 4294 | |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4295 | static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv, |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4296 | struct intel_digital_port *intel_dig_port) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4297 | { |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4298 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 4299 | enum port port; |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4300 | u32 bit; |
| 4301 | |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4302 | intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port); |
| 4303 | switch (port) { |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4304 | case PORT_A: |
| 4305 | bit = BXT_DE_PORT_HP_DDIA; |
| 4306 | break; |
| 4307 | case PORT_B: |
| 4308 | bit = BXT_DE_PORT_HP_DDIB; |
| 4309 | break; |
| 4310 | case PORT_C: |
| 4311 | bit = BXT_DE_PORT_HP_DDIC; |
| 4312 | break; |
| 4313 | default: |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4314 | MISSING_CASE(port); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4315 | return false; |
| 4316 | } |
| 4317 | |
| 4318 | return I915_READ(GEN8_DE_PORT_ISR) & bit; |
| 4319 | } |
| 4320 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4321 | /* |
| 4322 | * intel_digital_port_connected - is the specified port connected? |
| 4323 | * @dev_priv: i915 private structure |
| 4324 | * @port: the port to test |
| 4325 | * |
| 4326 | * Return %true if @port is connected, %false otherwise. |
| 4327 | */ |
David Weinehall | 23f889b | 2016-08-17 15:47:48 +0300 | [diff] [blame] | 4328 | static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4329 | struct intel_digital_port *port) |
| 4330 | { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4331 | if (HAS_PCH_IBX(dev_priv)) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4332 | return ibx_digital_port_connected(dev_priv, port); |
Ville Syrjälä | 22824fa | 2016-02-11 16:44:28 +0200 | [diff] [blame] | 4333 | else if (HAS_PCH_SPLIT(dev_priv)) |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4334 | return cpt_digital_port_connected(dev_priv, port); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4335 | else if (IS_GEN9_LP(dev_priv)) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4336 | return bxt_digital_port_connected(dev_priv, port); |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4337 | else if (IS_GM45(dev_priv)) |
| 4338 | return gm45_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4339 | else |
| 4340 | return g4x_digital_port_connected(dev_priv, port); |
| 4341 | } |
| 4342 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4343 | static struct edid * |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4344 | intel_dp_get_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4345 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4346 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4347 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4348 | /* use cached edid if we have one */ |
| 4349 | if (intel_connector->edid) { |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4350 | /* invalid edid */ |
| 4351 | if (IS_ERR(intel_connector->edid)) |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4352 | return NULL; |
| 4353 | |
Jani Nikula | 55e9ede | 2013-10-01 10:38:54 +0300 | [diff] [blame] | 4354 | return drm_edid_duplicate(intel_connector->edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4355 | } else |
| 4356 | return drm_get_edid(&intel_connector->base, |
| 4357 | &intel_dp->aux.ddc); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4360 | static void |
| 4361 | intel_dp_set_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4362 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4363 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4364 | struct edid *edid; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4365 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4366 | intel_dp_unset_edid(intel_dp); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4367 | edid = intel_dp_get_edid(intel_dp); |
| 4368 | intel_connector->detect_edid = edid; |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4369 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4370 | if (intel_dp->force_audio != HDMI_AUDIO_AUTO) |
| 4371 | intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON; |
| 4372 | else |
| 4373 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
| 4374 | } |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4375 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4376 | static void |
| 4377 | intel_dp_unset_edid(struct intel_dp *intel_dp) |
| 4378 | { |
| 4379 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4380 | |
| 4381 | kfree(intel_connector->detect_edid); |
| 4382 | intel_connector->detect_edid = NULL; |
| 4383 | |
| 4384 | intel_dp->has_audio = false; |
| 4385 | } |
| 4386 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4387 | static enum drm_connector_status |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4388 | intel_dp_long_pulse(struct intel_connector *intel_connector) |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4389 | { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4390 | struct drm_connector *connector = &intel_connector->base; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4391 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Paulo Zanoni | d63885d | 2012-10-26 19:05:49 -0200 | [diff] [blame] | 4392 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4393 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 4394 | struct drm_device *dev = connector->dev; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4395 | enum drm_connector_status status; |
Imre Deak | 671dedd | 2014-03-05 16:20:53 +0200 | [diff] [blame] | 4396 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4397 | u8 sink_irq_vector = 0; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4398 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4399 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
| 4400 | intel_display_power_get(to_i915(dev), power_domain); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4401 | |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4402 | /* Can't disconnect eDP, but you can close the lid... */ |
| 4403 | if (is_edp(intel_dp)) |
| 4404 | status = edp_detect(intel_dp); |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4405 | else if (intel_digital_port_connected(to_i915(dev), |
| 4406 | dp_to_dig_port(intel_dp))) |
| 4407 | status = intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4408 | else |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4409 | status = connector_status_disconnected; |
| 4410 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4411 | if (status == connector_status_disconnected) { |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4412 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4413 | |
jim.bride@linux.intel.com | 0e505a0 | 2016-04-11 10:11:24 -0700 | [diff] [blame] | 4414 | if (intel_dp->is_mst) { |
| 4415 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4416 | intel_dp->is_mst, |
| 4417 | intel_dp->mst_mgr.mst_state); |
| 4418 | intel_dp->is_mst = false; |
| 4419 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4420 | intel_dp->is_mst); |
| 4421 | } |
| 4422 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4423 | goto out; |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4424 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4425 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4426 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4427 | intel_encoder->type = INTEL_OUTPUT_DP; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4428 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4429 | DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n", |
| 4430 | yesno(intel_dp_source_supports_hbr2(intel_dp)), |
| 4431 | yesno(drm_dp_tps3_supported(intel_dp->dpcd))); |
| 4432 | |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4433 | /* Set the max lane count for sink */ |
| 4434 | intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd); |
| 4435 | |
| 4436 | /* Set the max link BW for sink */ |
| 4437 | intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp); |
| 4438 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4439 | intel_dp_print_rates(intel_dp); |
| 4440 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 4441 | intel_dp_read_desc(intel_dp); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 4442 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4443 | intel_dp_configure_mst(intel_dp); |
| 4444 | |
| 4445 | if (intel_dp->is_mst) { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4446 | /* |
| 4447 | * If we are in MST mode then this connector |
| 4448 | * won't appear connected or have anything |
| 4449 | * with EDID on it |
| 4450 | */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4451 | status = connector_status_disconnected; |
| 4452 | goto out; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4453 | } else if (connector->status == connector_status_connected) { |
| 4454 | /* |
| 4455 | * If display was connected already and is still connected |
| 4456 | * check links status, there has been known issues of |
| 4457 | * link loss triggerring long pulse!!!! |
| 4458 | */ |
| 4459 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4460 | intel_dp_check_link_status(intel_dp); |
| 4461 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 4462 | goto out; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4463 | } |
| 4464 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4465 | /* |
| 4466 | * Clearing NACK and defer counts to get their exact values |
| 4467 | * while reading EDID which are required by Compliance tests |
| 4468 | * 4.2.2.4 and 4.2.2.5 |
| 4469 | */ |
| 4470 | intel_dp->aux.i2c_nack_count = 0; |
| 4471 | intel_dp->aux.i2c_defer_count = 0; |
| 4472 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4473 | intel_dp_set_edid(intel_dp); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4474 | if (is_edp(intel_dp) || intel_connector->detect_edid) |
| 4475 | status = connector_status_connected; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4476 | intel_dp->detect_done = true; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4477 | |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4478 | /* Try to read the source of the interrupt */ |
| 4479 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4480 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4481 | sink_irq_vector != 0) { |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4482 | /* Clear interrupt source */ |
| 4483 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4484 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4485 | sink_irq_vector); |
| 4486 | |
| 4487 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
| 4488 | intel_dp_handle_test_request(intel_dp); |
| 4489 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4490 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4491 | } |
| 4492 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4493 | out: |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4494 | if (status != connector_status_connected && !intel_dp->is_mst) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4495 | intel_dp_unset_edid(intel_dp); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4496 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4497 | intel_display_power_put(to_i915(dev), power_domain); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4498 | return status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | static enum drm_connector_status |
| 4502 | intel_dp_detect(struct drm_connector *connector, bool force) |
| 4503 | { |
| 4504 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4505 | enum drm_connector_status status = connector->status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4506 | |
| 4507 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4508 | connector->base.id, connector->name); |
| 4509 | |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4510 | /* If full detect is not performed yet, do a full detect */ |
| 4511 | if (!intel_dp->detect_done) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4512 | status = intel_dp_long_pulse(intel_dp->attached_connector); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4513 | |
| 4514 | intel_dp->detect_done = false; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4515 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4516 | return status; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4519 | static void |
| 4520 | intel_dp_force(struct drm_connector *connector) |
| 4521 | { |
| 4522 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 4523 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4524 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4525 | enum intel_display_power_domain power_domain; |
| 4526 | |
| 4527 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4528 | connector->base.id, connector->name); |
| 4529 | intel_dp_unset_edid(intel_dp); |
| 4530 | |
| 4531 | if (connector->status != connector_status_connected) |
| 4532 | return; |
| 4533 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4534 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
| 4535 | intel_display_power_get(dev_priv, power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4536 | |
| 4537 | intel_dp_set_edid(intel_dp); |
| 4538 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4539 | intel_display_power_put(dev_priv, power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4540 | |
| 4541 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4542 | intel_encoder->type = INTEL_OUTPUT_DP; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4543 | } |
| 4544 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4545 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 4546 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4547 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4548 | struct edid *edid; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4549 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4550 | edid = intel_connector->detect_edid; |
| 4551 | if (edid) { |
| 4552 | int ret = intel_connector_update_modes(connector, edid); |
| 4553 | if (ret) |
| 4554 | return ret; |
| 4555 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4556 | |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4557 | /* if eDP has no EDID, fall back to fixed mode */ |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4558 | if (is_edp(intel_attached_dp(connector)) && |
| 4559 | intel_connector->panel.fixed_mode) { |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4560 | struct drm_display_mode *mode; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4561 | |
| 4562 | mode = drm_mode_duplicate(connector->dev, |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4563 | intel_connector->panel.fixed_mode); |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4564 | if (mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4565 | drm_mode_probed_add(connector, mode); |
| 4566 | return 1; |
| 4567 | } |
| 4568 | } |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4569 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4570 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4571 | } |
| 4572 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4573 | static bool |
| 4574 | intel_dp_detect_audio(struct drm_connector *connector) |
| 4575 | { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4576 | bool has_audio = false; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4577 | struct edid *edid; |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4578 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4579 | edid = to_intel_connector(connector)->detect_edid; |
| 4580 | if (edid) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4581 | has_audio = drm_detect_monitor_audio(edid); |
Imre Deak | 671dedd | 2014-03-05 16:20:53 +0200 | [diff] [blame] | 4582 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4583 | return has_audio; |
| 4584 | } |
| 4585 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4586 | static int |
| 4587 | intel_dp_set_property(struct drm_connector *connector, |
| 4588 | struct drm_property *property, |
| 4589 | uint64_t val) |
| 4590 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4591 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4592 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4593 | struct intel_encoder *intel_encoder = intel_attached_encoder(connector); |
| 4594 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4595 | int ret; |
| 4596 | |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 4597 | ret = drm_object_property_set_value(&connector->base, property, val); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4598 | if (ret) |
| 4599 | return ret; |
| 4600 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 4601 | if (property == dev_priv->force_audio_property) { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4602 | int i = val; |
| 4603 | bool has_audio; |
| 4604 | |
| 4605 | if (i == intel_dp->force_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4606 | return 0; |
| 4607 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4608 | intel_dp->force_audio = i; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4609 | |
Daniel Vetter | c3e5f67 | 2012-02-23 17:14:47 +0100 | [diff] [blame] | 4610 | if (i == HDMI_AUDIO_AUTO) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4611 | has_audio = intel_dp_detect_audio(connector); |
| 4612 | else |
Daniel Vetter | c3e5f67 | 2012-02-23 17:14:47 +0100 | [diff] [blame] | 4613 | has_audio = (i == HDMI_AUDIO_ON); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4614 | |
| 4615 | if (has_audio == intel_dp->has_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4616 | return 0; |
| 4617 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4618 | intel_dp->has_audio = has_audio; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4619 | goto done; |
| 4620 | } |
| 4621 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4622 | if (property == dev_priv->broadcast_rgb_property) { |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4623 | bool old_auto = intel_dp->color_range_auto; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4624 | bool old_range = intel_dp->limited_color_range; |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4625 | |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4626 | switch (val) { |
| 4627 | case INTEL_BROADCAST_RGB_AUTO: |
| 4628 | intel_dp->color_range_auto = true; |
| 4629 | break; |
| 4630 | case INTEL_BROADCAST_RGB_FULL: |
| 4631 | intel_dp->color_range_auto = false; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4632 | intel_dp->limited_color_range = false; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4633 | break; |
| 4634 | case INTEL_BROADCAST_RGB_LIMITED: |
| 4635 | intel_dp->color_range_auto = false; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4636 | intel_dp->limited_color_range = true; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4637 | break; |
| 4638 | default: |
| 4639 | return -EINVAL; |
| 4640 | } |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4641 | |
| 4642 | if (old_auto == intel_dp->color_range_auto && |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4643 | old_range == intel_dp->limited_color_range) |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4644 | return 0; |
| 4645 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4646 | goto done; |
| 4647 | } |
| 4648 | |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4649 | if (is_edp(intel_dp) && |
| 4650 | property == connector->dev->mode_config.scaling_mode_property) { |
| 4651 | if (val == DRM_MODE_SCALE_NONE) { |
| 4652 | DRM_DEBUG_KMS("no scaling not supported\n"); |
| 4653 | return -EINVAL; |
| 4654 | } |
Ville Syrjälä | 234126c | 2016-04-12 22:14:38 +0300 | [diff] [blame] | 4655 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 4656 | val == DRM_MODE_SCALE_CENTER) { |
| 4657 | DRM_DEBUG_KMS("centering not supported\n"); |
| 4658 | return -EINVAL; |
| 4659 | } |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4660 | |
| 4661 | if (intel_connector->panel.fitting_mode == val) { |
| 4662 | /* the eDP scaling property is not changed */ |
| 4663 | return 0; |
| 4664 | } |
| 4665 | intel_connector->panel.fitting_mode = val; |
| 4666 | |
| 4667 | goto done; |
| 4668 | } |
| 4669 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4670 | return -EINVAL; |
| 4671 | |
| 4672 | done: |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 4673 | if (intel_encoder->base.crtc) |
| 4674 | intel_crtc_restore_mode(intel_encoder->base.crtc); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4675 | |
| 4676 | return 0; |
| 4677 | } |
| 4678 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4679 | static int |
| 4680 | intel_dp_connector_register(struct drm_connector *connector) |
| 4681 | { |
| 4682 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 4683 | int ret; |
| 4684 | |
| 4685 | ret = intel_connector_register(connector); |
| 4686 | if (ret) |
| 4687 | return ret; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4688 | |
| 4689 | i915_debugfs_connector_add(connector); |
| 4690 | |
| 4691 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
| 4692 | intel_dp->aux.name, connector->kdev->kobj.name); |
| 4693 | |
| 4694 | intel_dp->aux.dev = connector->kdev; |
| 4695 | return drm_dp_aux_register(&intel_dp->aux); |
| 4696 | } |
| 4697 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4698 | static void |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4699 | intel_dp_connector_unregister(struct drm_connector *connector) |
| 4700 | { |
| 4701 | drm_dp_aux_unregister(&intel_attached_dp(connector)->aux); |
| 4702 | intel_connector_unregister(connector); |
| 4703 | } |
| 4704 | |
| 4705 | static void |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 4706 | intel_dp_connector_destroy(struct drm_connector *connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4707 | { |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4708 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4709 | |
Chris Wilson | 10e972d | 2014-09-04 21:43:45 +0100 | [diff] [blame] | 4710 | kfree(intel_connector->detect_edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4711 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4712 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 4713 | kfree(intel_connector->edid); |
| 4714 | |
Paulo Zanoni | acd8db10 | 2013-06-12 17:27:23 -0300 | [diff] [blame] | 4715 | /* Can't call is_edp() since the encoder may have been destroyed |
| 4716 | * already. */ |
| 4717 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4718 | intel_panel_fini(&intel_connector->panel); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4719 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4720 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 4721 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 4724 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4725 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4726 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 4727 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4728 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4729 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4730 | if (is_edp(intel_dp)) { |
| 4731 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4732 | /* |
| 4733 | * vdd might still be enabled do to the delayed vdd off. |
| 4734 | * Make sure vdd is actually turned off here. |
| 4735 | */ |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4736 | pps_lock(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 4737 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4738 | pps_unlock(intel_dp); |
| 4739 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 4740 | if (intel_dp->edp_notifier.notifier_call) { |
| 4741 | unregister_reboot_notifier(&intel_dp->edp_notifier); |
| 4742 | intel_dp->edp_notifier.notifier_call = NULL; |
| 4743 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4744 | } |
Chris Wilson | 9968188 | 2016-06-20 09:29:17 +0100 | [diff] [blame] | 4745 | |
| 4746 | intel_dp_aux_fini(intel_dp); |
| 4747 | |
Imre Deak | c8bd0e4 | 2014-12-12 17:57:38 +0200 | [diff] [blame] | 4748 | drm_encoder_cleanup(encoder); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4749 | kfree(intel_dig_port); |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4750 | } |
| 4751 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 4752 | void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4753 | { |
| 4754 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 4755 | |
| 4756 | if (!is_edp(intel_dp)) |
| 4757 | return; |
| 4758 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4759 | /* |
| 4760 | * vdd might still be enabled do to the delayed vdd off. |
| 4761 | * Make sure vdd is actually turned off here. |
| 4762 | */ |
Ville Syrjälä | afa4e53 | 2014-11-25 15:43:48 +0200 | [diff] [blame] | 4763 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4764 | pps_lock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4765 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4766 | pps_unlock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4767 | } |
| 4768 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4769 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
| 4770 | { |
| 4771 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4772 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4773 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4774 | enum intel_display_power_domain power_domain; |
| 4775 | |
| 4776 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 4777 | |
| 4778 | if (!edp_have_panel_vdd(intel_dp)) |
| 4779 | return; |
| 4780 | |
| 4781 | /* |
| 4782 | * The VDD bit needs a power domain reference, so if the bit is |
| 4783 | * already enabled when we boot or resume, grab this reference and |
| 4784 | * schedule a vdd off, so we don't hold on to the reference |
| 4785 | * indefinitely. |
| 4786 | */ |
| 4787 | DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n"); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4788 | power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4789 | intel_display_power_get(dev_priv, power_domain); |
| 4790 | |
| 4791 | edp_panel_vdd_schedule_off(intel_dp); |
| 4792 | } |
| 4793 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 4794 | void intel_dp_encoder_reset(struct drm_encoder *encoder) |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 4795 | { |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 4796 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 4797 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 4798 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 4799 | |
| 4800 | if (!HAS_DDI(dev_priv)) |
| 4801 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4802 | |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 4803 | if (lspcon->active) |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 4804 | lspcon_resume(lspcon); |
| 4805 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4806 | if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP) |
| 4807 | return; |
| 4808 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4809 | pps_lock(intel_dp); |
| 4810 | |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 4811 | /* Reinit the power sequencer, in case BIOS did something with it. */ |
| 4812 | intel_dp_pps_init(encoder->dev, intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4813 | intel_edp_panel_vdd_sanitize(intel_dp); |
| 4814 | |
| 4815 | pps_unlock(intel_dp); |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 4816 | } |
| 4817 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4818 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 4819 | .dpms = drm_atomic_helper_connector_dpms, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4820 | .detect = intel_dp_detect, |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4821 | .force = intel_dp_force, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4822 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4823 | .set_property = intel_dp_set_property, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 4824 | .atomic_get_property = intel_connector_atomic_get_property, |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4825 | .late_register = intel_dp_connector_register, |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4826 | .early_unregister = intel_dp_connector_unregister, |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 4827 | .destroy = intel_dp_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 4828 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Ander Conselvan de Oliveira | 9896972 | 2015-03-20 16:18:06 +0200 | [diff] [blame] | 4829 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4830 | }; |
| 4831 | |
| 4832 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
| 4833 | .get_modes = intel_dp_get_modes, |
| 4834 | .mode_valid = intel_dp_mode_valid, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4835 | }; |
| 4836 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4837 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 4838 | .reset = intel_dp_encoder_reset, |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4839 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4840 | }; |
| 4841 | |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 4842 | enum irqreturn |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 4843 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
| 4844 | { |
| 4845 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 4846 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4847 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4848 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 4849 | enum intel_display_power_domain power_domain; |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 4850 | enum irqreturn ret = IRQ_NONE; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 4851 | |
Takashi Iwai | 2540058 | 2015-11-19 12:09:56 +0100 | [diff] [blame] | 4852 | if (intel_dig_port->base.type != INTEL_OUTPUT_EDP && |
| 4853 | intel_dig_port->base.type != INTEL_OUTPUT_HDMI) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4854 | intel_dig_port->base.type = INTEL_OUTPUT_DP; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 4855 | |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 4856 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
| 4857 | /* |
| 4858 | * vdd off can generate a long pulse on eDP which |
| 4859 | * would require vdd on to handle it, and thus we |
| 4860 | * would end up in an endless cycle of |
| 4861 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." |
| 4862 | */ |
| 4863 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", |
| 4864 | port_name(intel_dig_port->port)); |
Ville Syrjälä | a8b3d52f8 | 2015-02-10 14:11:46 +0200 | [diff] [blame] | 4865 | return IRQ_HANDLED; |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 4866 | } |
| 4867 | |
Ville Syrjälä | 26fbb77 | 2014-08-11 18:37:37 +0300 | [diff] [blame] | 4868 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
| 4869 | port_name(intel_dig_port->port), |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4870 | long_hpd ? "long" : "short"); |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 4871 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 4872 | if (long_hpd) { |
| 4873 | intel_dp->detect_done = false; |
| 4874 | return IRQ_NONE; |
| 4875 | } |
| 4876 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4877 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 4878 | intel_display_power_get(dev_priv, power_domain); |
| 4879 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 4880 | if (intel_dp->is_mst) { |
| 4881 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) { |
| 4882 | /* |
| 4883 | * If we were in MST mode, and device is not |
| 4884 | * there, get out of MST mode |
| 4885 | */ |
| 4886 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4887 | intel_dp->is_mst, intel_dp->mst_mgr.mst_state); |
| 4888 | intel_dp->is_mst = false; |
| 4889 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4890 | intel_dp->is_mst); |
| 4891 | intel_dp->detect_done = false; |
| 4892 | goto put_power; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4893 | } |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 4894 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4895 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 4896 | if (!intel_dp->is_mst) { |
| 4897 | if (!intel_dp_short_pulse(intel_dp)) { |
| 4898 | intel_dp->detect_done = false; |
| 4899 | goto put_power; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4900 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4901 | } |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 4902 | |
| 4903 | ret = IRQ_HANDLED; |
| 4904 | |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 4905 | put_power: |
| 4906 | intel_display_power_put(dev_priv, power_domain); |
| 4907 | |
| 4908 | return ret; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 4909 | } |
| 4910 | |
Rodrigo Vivi | 477ec32 | 2015-08-06 15:51:39 +0800 | [diff] [blame] | 4911 | /* check the VBT to see whether the eDP is on another port */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 4912 | bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port) |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 4913 | { |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 4914 | /* |
| 4915 | * eDP not supported on g4x. so bail out early just |
| 4916 | * for a bit extra safety in case the VBT is bonkers. |
| 4917 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 4918 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 4919 | return false; |
| 4920 | |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 4921 | if (port == PORT_A) |
| 4922 | return true; |
| 4923 | |
Jani Nikula | 951d9ef | 2016-03-16 12:43:31 +0200 | [diff] [blame] | 4924 | return intel_bios_is_port_edp(dev_priv, port); |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 4925 | } |
| 4926 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4927 | void |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4928 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 4929 | { |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4930 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 4931 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 4932 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4933 | intel_attach_broadcast_rgb_property(connector); |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4934 | intel_dp->color_range_auto = true; |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4935 | |
| 4936 | if (is_edp(intel_dp)) { |
| 4937 | drm_mode_create_scaling_mode_property(connector->dev); |
Rob Clark | 6de6d84 | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 4938 | drm_object_attach_property( |
| 4939 | &connector->base, |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4940 | connector->dev->mode_config.scaling_mode_property, |
Yuly Novikov | 8e740cd | 2012-10-26 12:04:01 +0300 | [diff] [blame] | 4941 | DRM_MODE_SCALE_ASPECT); |
| 4942 | intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT; |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4943 | } |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4944 | } |
| 4945 | |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 4946 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
| 4947 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 4948 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 4949 | intel_dp->last_power_on = jiffies; |
| 4950 | intel_dp->last_backlight_off = jiffies; |
| 4951 | } |
| 4952 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4953 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4954 | intel_pps_readout_hw_state(struct drm_i915_private *dev_priv, |
| 4955 | struct intel_dp *intel_dp, struct edp_power_seq *seq) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4956 | { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4957 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 4958 | struct pps_registers regs; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 4959 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 4960 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4961 | |
| 4962 | /* Workaround: Need to write PP_CONTROL with the unlock key as |
| 4963 | * the very first thing. */ |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4964 | pp_ctl = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4965 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 4966 | pp_on = I915_READ(regs.pp_on); |
| 4967 | pp_off = I915_READ(regs.pp_off); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4968 | if (!IS_GEN9_LP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 4969 | I915_WRITE(regs.pp_ctrl, pp_ctl); |
| 4970 | pp_div = I915_READ(regs.pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4971 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4972 | |
| 4973 | /* Pull timing values out of registers */ |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4974 | seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 4975 | PANEL_POWER_UP_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4976 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4977 | seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 4978 | PANEL_LIGHT_ON_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4979 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4980 | seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 4981 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4982 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4983 | seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 4984 | PANEL_POWER_DOWN_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4985 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4986 | if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4987 | u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> |
| 4988 | BXT_POWER_CYCLE_DELAY_SHIFT; |
| 4989 | if (tmp > 0) |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4990 | seq->t11_t12 = (tmp - 1) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4991 | else |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4992 | seq->t11_t12 = 0; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4993 | } else { |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4994 | seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 4995 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 4996 | } |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | static void |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5000 | intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq) |
| 5001 | { |
| 5002 | DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 5003 | state_name, |
| 5004 | seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12); |
| 5005 | } |
| 5006 | |
| 5007 | static void |
| 5008 | intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 5009 | struct intel_dp *intel_dp) |
| 5010 | { |
| 5011 | struct edp_power_seq hw; |
| 5012 | struct edp_power_seq *sw = &intel_dp->pps_delays; |
| 5013 | |
| 5014 | intel_pps_readout_hw_state(dev_priv, intel_dp, &hw); |
| 5015 | |
| 5016 | if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 || |
| 5017 | hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) { |
| 5018 | DRM_ERROR("PPS state mismatch\n"); |
| 5019 | intel_pps_dump_state("sw", sw); |
| 5020 | intel_pps_dump_state("hw", &hw); |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5025 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
| 5026 | struct intel_dp *intel_dp) |
| 5027 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5028 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5029 | struct edp_power_seq cur, vbt, spec, |
| 5030 | *final = &intel_dp->pps_delays; |
| 5031 | |
| 5032 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5033 | |
| 5034 | /* already initialized? */ |
| 5035 | if (final->t11_t12 != 0) |
| 5036 | return; |
| 5037 | |
| 5038 | intel_pps_readout_hw_state(dev_priv, intel_dp, &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5039 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5040 | intel_pps_dump_state("cur", &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5041 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 5042 | vbt = dev_priv->vbt.edp.pps; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5043 | |
| 5044 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of |
| 5045 | * our hw here, which are all in 100usec. */ |
| 5046 | spec.t1_t3 = 210 * 10; |
| 5047 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ |
| 5048 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ |
| 5049 | spec.t10 = 500 * 10; |
| 5050 | /* This one is special and actually in units of 100ms, but zero |
| 5051 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5052 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5053 | * too. */ |
| 5054 | spec.t11_t12 = (510 + 100) * 10; |
| 5055 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5056 | intel_pps_dump_state("vbt", &vbt); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5057 | |
| 5058 | /* Use the max of the register settings and vbt. If both are |
| 5059 | * unset, fall back to the spec limits. */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5060 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5061 | spec.field : \ |
| 5062 | max(cur.field, vbt.field)) |
| 5063 | assign_final(t1_t3); |
| 5064 | assign_final(t8); |
| 5065 | assign_final(t9); |
| 5066 | assign_final(t10); |
| 5067 | assign_final(t11_t12); |
| 5068 | #undef assign_final |
| 5069 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5070 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5071 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 5072 | intel_dp->backlight_on_delay = get_delay(t8); |
| 5073 | intel_dp->backlight_off_delay = get_delay(t9); |
| 5074 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 5075 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 5076 | #undef get_delay |
| 5077 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5078 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 5079 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 5080 | intel_dp->panel_power_cycle_delay); |
| 5081 | |
| 5082 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 5083 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5084 | |
| 5085 | /* |
| 5086 | * We override the HW backlight delays to 1 because we do manual waits |
| 5087 | * on them. For T8, even BSpec recommends doing it. For T9, if we |
| 5088 | * don't do this, we'll end up waiting for the backlight off delay |
| 5089 | * twice: once when we do the manual sleep, and once when we disable |
| 5090 | * the panel and wait for the PP_STATUS bit to become zero. |
| 5091 | */ |
| 5092 | final->t8 = 1; |
| 5093 | final->t9 = 1; |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | static void |
| 5097 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5098 | struct intel_dp *intel_dp) |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5099 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5100 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5101 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 5102 | int div = dev_priv->rawclk_freq / 1000; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5103 | struct pps_registers regs; |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5104 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5105 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5106 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 5107 | lockdep_assert_held(&dev_priv->pps_mutex); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5108 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5109 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5110 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5111 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5112 | (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT); |
| 5113 | pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5114 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5115 | /* Compute the divisor for the pp clock, simply match the Bspec |
| 5116 | * formula. */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5117 | if (IS_GEN9_LP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5118 | pp_div = I915_READ(regs.pp_ctrl); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5119 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; |
| 5120 | pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000) |
| 5121 | << BXT_POWER_CYCLE_DELAY_SHIFT); |
| 5122 | } else { |
| 5123 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 5124 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
| 5125 | << PANEL_POWER_CYCLE_DELAY_SHIFT); |
| 5126 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5127 | |
| 5128 | /* Haswell doesn't have any port selection bits for the panel |
| 5129 | * power sequencer any more. */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5130 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5131 | port_sel = PANEL_PORT_SELECT_VLV(port); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5132 | } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5133 | if (port == PORT_A) |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5134 | port_sel = PANEL_PORT_SELECT_DPA; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5135 | else |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5136 | port_sel = PANEL_PORT_SELECT_DPD; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5137 | } |
| 5138 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5139 | pp_on |= port_sel; |
| 5140 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5141 | I915_WRITE(regs.pp_on, pp_on); |
| 5142 | I915_WRITE(regs.pp_off, pp_off); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5143 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5144 | I915_WRITE(regs.pp_ctrl, pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5145 | else |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5146 | I915_WRITE(regs.pp_div, pp_div); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5147 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5148 | DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n", |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5149 | I915_READ(regs.pp_on), |
| 5150 | I915_READ(regs.pp_off), |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5151 | IS_GEN9_LP(dev_priv) ? |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5152 | (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) : |
| 5153 | I915_READ(regs.pp_div)); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 5154 | } |
| 5155 | |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5156 | static void intel_dp_pps_init(struct drm_device *dev, |
| 5157 | struct intel_dp *intel_dp) |
| 5158 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5159 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5160 | |
| 5161 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5162 | vlv_initial_power_sequencer_setup(intel_dp); |
| 5163 | } else { |
| 5164 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
| 5165 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); |
| 5166 | } |
| 5167 | } |
| 5168 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5169 | /** |
| 5170 | * intel_dp_set_drrs_state - program registers for RR switch to take effect |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5171 | * @dev_priv: i915 device |
Maarten Lankhorst | e896402 | 2016-08-25 11:07:02 +0200 | [diff] [blame] | 5172 | * @crtc_state: a pointer to the active intel_crtc_state |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5173 | * @refresh_rate: RR to be programmed |
| 5174 | * |
| 5175 | * This function gets called when refresh rate (RR) has to be changed from |
| 5176 | * one frequency to another. Switches can be between high and low RR |
| 5177 | * supported by the panel or to any other RR based on media playback (in |
| 5178 | * this case, RR value needs to be passed from user space). |
| 5179 | * |
| 5180 | * The caller of this function needs to take a lock on dev_priv->drrs. |
| 5181 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5182 | static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv, |
| 5183 | struct intel_crtc_state *crtc_state, |
| 5184 | int refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5185 | { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5186 | struct intel_encoder *encoder; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5187 | struct intel_digital_port *dig_port = NULL; |
| 5188 | struct intel_dp *intel_dp = dev_priv->drrs.dp; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5189 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5190 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5191 | |
| 5192 | if (refresh_rate <= 0) { |
| 5193 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); |
| 5194 | return; |
| 5195 | } |
| 5196 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5197 | if (intel_dp == NULL) { |
| 5198 | DRM_DEBUG_KMS("DRRS not supported.\n"); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5199 | return; |
| 5200 | } |
| 5201 | |
Daniel Vetter | 1fcc9d1 | 2014-07-11 10:30:10 -0700 | [diff] [blame] | 5202 | /* |
Rodrigo Vivi | e4d59f6 | 2014-11-20 02:22:08 -0800 | [diff] [blame] | 5203 | * FIXME: This needs proper synchronization with psr state for some |
| 5204 | * platforms that cannot have PSR and DRRS enabled at the same time. |
Daniel Vetter | 1fcc9d1 | 2014-07-11 10:30:10 -0700 | [diff] [blame] | 5205 | */ |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5206 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5207 | dig_port = dp_to_dig_port(intel_dp); |
| 5208 | encoder = &dig_port->base; |
Ander Conselvan de Oliveira | 723f9aa | 2015-03-20 16:18:18 +0200 | [diff] [blame] | 5209 | intel_crtc = to_intel_crtc(encoder->base.crtc); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5210 | |
| 5211 | if (!intel_crtc) { |
| 5212 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); |
| 5213 | return; |
| 5214 | } |
| 5215 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5216 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5217 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
| 5218 | return; |
| 5219 | } |
| 5220 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5221 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
| 5222 | refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5223 | index = DRRS_LOW_RR; |
| 5224 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5225 | if (index == dev_priv->drrs.refresh_rate_type) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5226 | DRM_DEBUG_KMS( |
| 5227 | "DRRS requested for previously set RR...ignoring\n"); |
| 5228 | return; |
| 5229 | } |
| 5230 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5231 | if (!crtc_state->base.active) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5232 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); |
| 5233 | return; |
| 5234 | } |
| 5235 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5236 | if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) { |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5237 | switch (index) { |
| 5238 | case DRRS_HIGH_RR: |
| 5239 | intel_dp_set_m_n(intel_crtc, M1_N1); |
| 5240 | break; |
| 5241 | case DRRS_LOW_RR: |
| 5242 | intel_dp_set_m_n(intel_crtc, M2_N2); |
| 5243 | break; |
| 5244 | case DRRS_MAX_RR: |
| 5245 | default: |
| 5246 | DRM_ERROR("Unsupported refreshrate type\n"); |
| 5247 | } |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5248 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 5249 | i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5250 | u32 val; |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5251 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5252 | val = I915_READ(reg); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5253 | if (index > DRRS_HIGH_RR) { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5254 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5255 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5256 | else |
| 5257 | val |= PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5258 | } else { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5259 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5260 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5261 | else |
| 5262 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5263 | } |
| 5264 | I915_WRITE(reg, val); |
| 5265 | } |
| 5266 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5267 | dev_priv->drrs.refresh_rate_type = index; |
| 5268 | |
| 5269 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); |
| 5270 | } |
| 5271 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5272 | /** |
| 5273 | * intel_edp_drrs_enable - init drrs struct if supported |
| 5274 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5275 | * @crtc_state: A pointer to the active crtc state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5276 | * |
| 5277 | * Initializes frontbuffer_bits and drrs.dp |
| 5278 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5279 | void intel_edp_drrs_enable(struct intel_dp *intel_dp, |
| 5280 | struct intel_crtc_state *crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5281 | { |
| 5282 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5283 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5284 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5285 | if (!crtc_state->has_drrs) { |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5286 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); |
| 5287 | return; |
| 5288 | } |
| 5289 | |
| 5290 | mutex_lock(&dev_priv->drrs.mutex); |
| 5291 | if (WARN_ON(dev_priv->drrs.dp)) { |
| 5292 | DRM_ERROR("DRRS already enabled\n"); |
| 5293 | goto unlock; |
| 5294 | } |
| 5295 | |
| 5296 | dev_priv->drrs.busy_frontbuffer_bits = 0; |
| 5297 | |
| 5298 | dev_priv->drrs.dp = intel_dp; |
| 5299 | |
| 5300 | unlock: |
| 5301 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5302 | } |
| 5303 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5304 | /** |
| 5305 | * intel_edp_drrs_disable - Disable DRRS |
| 5306 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5307 | * @old_crtc_state: Pointer to old crtc_state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5308 | * |
| 5309 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5310 | void intel_edp_drrs_disable(struct intel_dp *intel_dp, |
| 5311 | struct intel_crtc_state *old_crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5312 | { |
| 5313 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5314 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5315 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5316 | if (!old_crtc_state->has_drrs) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5317 | return; |
| 5318 | |
| 5319 | mutex_lock(&dev_priv->drrs.mutex); |
| 5320 | if (!dev_priv->drrs.dp) { |
| 5321 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5322 | return; |
| 5323 | } |
| 5324 | |
| 5325 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5326 | intel_dp_set_drrs_state(dev_priv, old_crtc_state, |
| 5327 | intel_dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5328 | |
| 5329 | dev_priv->drrs.dp = NULL; |
| 5330 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5331 | |
| 5332 | cancel_delayed_work_sync(&dev_priv->drrs.work); |
| 5333 | } |
| 5334 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5335 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
| 5336 | { |
| 5337 | struct drm_i915_private *dev_priv = |
| 5338 | container_of(work, typeof(*dev_priv), drrs.work.work); |
| 5339 | struct intel_dp *intel_dp; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5340 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5341 | mutex_lock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5342 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5343 | intel_dp = dev_priv->drrs.dp; |
| 5344 | |
| 5345 | if (!intel_dp) |
| 5346 | goto unlock; |
| 5347 | |
| 5348 | /* |
| 5349 | * The delayed work can race with an invalidate hence we need to |
| 5350 | * recheck. |
| 5351 | */ |
| 5352 | |
| 5353 | if (dev_priv->drrs.busy_frontbuffer_bits) |
| 5354 | goto unlock; |
| 5355 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5356 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) { |
| 5357 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 5358 | |
| 5359 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5360 | intel_dp->attached_connector->panel.downclock_mode->vrefresh); |
| 5361 | } |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5362 | |
| 5363 | unlock: |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5364 | mutex_unlock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5365 | } |
| 5366 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5367 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5368 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5369 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5370 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5371 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5372 | * This function gets called everytime rendering on the given planes start. |
| 5373 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5374 | * |
| 5375 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5376 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5377 | void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv, |
| 5378 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5379 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5380 | struct drm_crtc *crtc; |
| 5381 | enum pipe pipe; |
| 5382 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5383 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5384 | return; |
| 5385 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5386 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5387 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5388 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5389 | if (!dev_priv->drrs.dp) { |
| 5390 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5391 | return; |
| 5392 | } |
| 5393 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5394 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5395 | pipe = to_intel_crtc(crtc)->pipe; |
| 5396 | |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5397 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 5398 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; |
| 5399 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5400 | /* invalidate means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5401 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5402 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5403 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5404 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5405 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5406 | } |
| 5407 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5408 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5409 | * intel_edp_drrs_flush - Restart Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5410 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5411 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5412 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5413 | * This function gets called every time rendering on the given planes has |
| 5414 | * completed or flip on a crtc is completed. So DRRS should be upclocked |
| 5415 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, |
| 5416 | * if no other planes are dirty. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5417 | * |
| 5418 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5419 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5420 | void intel_edp_drrs_flush(struct drm_i915_private *dev_priv, |
| 5421 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5422 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5423 | struct drm_crtc *crtc; |
| 5424 | enum pipe pipe; |
| 5425 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5426 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5427 | return; |
| 5428 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5429 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5430 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5431 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5432 | if (!dev_priv->drrs.dp) { |
| 5433 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5434 | return; |
| 5435 | } |
| 5436 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5437 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5438 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5439 | |
| 5440 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5441 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 5442 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5443 | /* flush means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5444 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5445 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5446 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5447 | |
| 5448 | /* |
| 5449 | * flush also means no more activity hence schedule downclock, if all |
| 5450 | * other fbs are quiescent too |
| 5451 | */ |
| 5452 | if (!dev_priv->drrs.busy_frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5453 | schedule_delayed_work(&dev_priv->drrs.work, |
| 5454 | msecs_to_jiffies(1000)); |
| 5455 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5456 | } |
| 5457 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5458 | /** |
| 5459 | * DOC: Display Refresh Rate Switching (DRRS) |
| 5460 | * |
| 5461 | * Display Refresh Rate Switching (DRRS) is a power conservation feature |
| 5462 | * which enables swtching between low and high refresh rates, |
| 5463 | * dynamically, based on the usage scenario. This feature is applicable |
| 5464 | * for internal panels. |
| 5465 | * |
| 5466 | * Indication that the panel supports DRRS is given by the panel EDID, which |
| 5467 | * would list multiple refresh rates for one resolution. |
| 5468 | * |
| 5469 | * DRRS is of 2 types - static and seamless. |
| 5470 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset |
| 5471 | * (may appear as a blink on screen) and is used in dock-undock scenario. |
| 5472 | * Seamless DRRS involves changing RR without any visual effect to the user |
| 5473 | * and can be used during normal system usage. This is done by programming |
| 5474 | * certain registers. |
| 5475 | * |
| 5476 | * Support for static/seamless DRRS may be indicated in the VBT based on |
| 5477 | * inputs from the panel spec. |
| 5478 | * |
| 5479 | * DRRS saves power by switching to low RR based on usage scenarios. |
| 5480 | * |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 5481 | * The implementation is based on frontbuffer tracking implementation. When |
| 5482 | * there is a disturbance on the screen triggered by user activity or a periodic |
| 5483 | * system activity, DRRS is disabled (RR is changed to high RR). When there is |
| 5484 | * no movement on screen, after a timeout of 1 second, a switch to low RR is |
| 5485 | * made. |
| 5486 | * |
| 5487 | * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate() |
| 5488 | * and intel_edp_drrs_flush() are called. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5489 | * |
| 5490 | * DRRS can be further extended to support other internal panels and also |
| 5491 | * the scenario of video playback wherein RR is set based on the rate |
| 5492 | * requested by userspace. |
| 5493 | */ |
| 5494 | |
| 5495 | /** |
| 5496 | * intel_dp_drrs_init - Init basic DRRS work and mutex. |
| 5497 | * @intel_connector: eDP connector |
| 5498 | * @fixed_mode: preferred mode of panel |
| 5499 | * |
| 5500 | * This function is called only once at driver load to initialize basic |
| 5501 | * DRRS stuff. |
| 5502 | * |
| 5503 | * Returns: |
| 5504 | * Downclock mode if panel supports it, else return NULL. |
| 5505 | * DRRS support is determined by the presence of downclock mode (apart |
| 5506 | * from VBT setting). |
| 5507 | */ |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5508 | static struct drm_display_mode * |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5509 | intel_dp_drrs_init(struct intel_connector *intel_connector, |
| 5510 | struct drm_display_mode *fixed_mode) |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5511 | { |
| 5512 | struct drm_connector *connector = &intel_connector->base; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5513 | struct drm_device *dev = connector->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5514 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5515 | struct drm_display_mode *downclock_mode = NULL; |
| 5516 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5517 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
| 5518 | mutex_init(&dev_priv->drrs.mutex); |
| 5519 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5520 | if (INTEL_GEN(dev_priv) <= 6) { |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5521 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); |
| 5522 | return NULL; |
| 5523 | } |
| 5524 | |
| 5525 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5526 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5527 | return NULL; |
| 5528 | } |
| 5529 | |
| 5530 | downclock_mode = intel_find_panel_downclock |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame^] | 5531 | (dev_priv, fixed_mode, connector); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5532 | |
| 5533 | if (!downclock_mode) { |
Ramalingam C | a1d2634 | 2015-02-23 17:38:33 +0530 | [diff] [blame] | 5534 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5535 | return NULL; |
| 5536 | } |
| 5537 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5538 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5539 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5540 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5541 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5542 | return downclock_mode; |
| 5543 | } |
| 5544 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5545 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5546 | struct intel_connector *intel_connector) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5547 | { |
| 5548 | struct drm_connector *connector = &intel_connector->base; |
| 5549 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5550 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5551 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5552 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5553 | struct drm_display_mode *fixed_mode = NULL; |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5554 | struct drm_display_mode *downclock_mode = NULL; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5555 | bool has_dpcd; |
| 5556 | struct drm_display_mode *scan; |
| 5557 | struct edid *edid; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5558 | enum pipe pipe = INVALID_PIPE; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5559 | |
| 5560 | if (!is_edp(intel_dp)) |
| 5561 | return true; |
| 5562 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 5563 | /* |
| 5564 | * On IBX/CPT we may get here with LVDS already registered. Since the |
| 5565 | * driver uses the only internal power sequencer available for both |
| 5566 | * eDP and LVDS bail out early in this case to prevent interfering |
| 5567 | * with an already powered-on LVDS power sequencer. |
| 5568 | */ |
| 5569 | if (intel_get_lvds_encoder(dev)) { |
| 5570 | WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))); |
| 5571 | DRM_INFO("LVDS was detected, not registering eDP\n"); |
| 5572 | |
| 5573 | return false; |
| 5574 | } |
| 5575 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5576 | pps_lock(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5577 | |
| 5578 | intel_dp_init_panel_power_timestamps(intel_dp); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5579 | intel_dp_pps_init(dev, intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5580 | intel_edp_panel_vdd_sanitize(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5581 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5582 | pps_unlock(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5583 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5584 | /* Cache DPCD and EDID for edp. */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5585 | has_dpcd = intel_edp_init_dpcd(intel_dp); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5586 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5587 | if (!has_dpcd) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5588 | /* if this fails, presume the device is a ghost */ |
| 5589 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5590 | goto out_vdd_off; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5591 | } |
| 5592 | |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5593 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 5594 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5595 | if (edid) { |
| 5596 | if (drm_add_edid_modes(connector, edid)) { |
| 5597 | drm_mode_connector_update_edid_property(connector, |
| 5598 | edid); |
| 5599 | drm_edid_to_eld(connector, edid); |
| 5600 | } else { |
| 5601 | kfree(edid); |
| 5602 | edid = ERR_PTR(-EINVAL); |
| 5603 | } |
| 5604 | } else { |
| 5605 | edid = ERR_PTR(-ENOENT); |
| 5606 | } |
| 5607 | intel_connector->edid = edid; |
| 5608 | |
| 5609 | /* prefer fixed mode from EDID if available */ |
| 5610 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 5611 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 5612 | fixed_mode = drm_mode_duplicate(dev, scan); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5613 | downclock_mode = intel_dp_drrs_init( |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5614 | intel_connector, fixed_mode); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5615 | break; |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | /* fallback to VBT if available for eDP */ |
| 5620 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { |
| 5621 | fixed_mode = drm_mode_duplicate(dev, |
| 5622 | dev_priv->vbt.lfp_lvds_vbt_mode); |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5623 | if (fixed_mode) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5624 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5625 | connector->display_info.width_mm = fixed_mode->width_mm; |
| 5626 | connector->display_info.height_mm = fixed_mode->height_mm; |
| 5627 | } |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5628 | } |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5629 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5630 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5631 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5632 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
| 5633 | register_reboot_notifier(&intel_dp->edp_notifier); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5634 | |
| 5635 | /* |
| 5636 | * Figure out the current pipe for the initial backlight setup. |
| 5637 | * If the current pipe isn't valid, try the PPS pipe, and if that |
| 5638 | * fails just assume pipe A. |
| 5639 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5640 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5641 | pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP); |
| 5642 | else |
| 5643 | pipe = PORT_TO_PIPE(intel_dp->DP); |
| 5644 | |
| 5645 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5646 | pipe = intel_dp->pps_pipe; |
| 5647 | |
| 5648 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5649 | pipe = PIPE_A; |
| 5650 | |
| 5651 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", |
| 5652 | pipe_name(pipe)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5653 | } |
| 5654 | |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5655 | intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 5656 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5657 | intel_panel_setup_backlight(connector, pipe); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5658 | |
| 5659 | return true; |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5660 | |
| 5661 | out_vdd_off: |
| 5662 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 5663 | /* |
| 5664 | * vdd might still be enabled do to the delayed vdd off. |
| 5665 | * Make sure vdd is actually turned off here. |
| 5666 | */ |
| 5667 | pps_lock(intel_dp); |
| 5668 | edp_panel_vdd_off_sync(intel_dp); |
| 5669 | pps_unlock(intel_dp); |
| 5670 | |
| 5671 | return false; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5672 | } |
| 5673 | |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 5674 | bool |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5675 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
| 5676 | struct intel_connector *intel_connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5677 | { |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5678 | struct drm_connector *connector = &intel_connector->base; |
| 5679 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 5680 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5681 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5682 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 5683 | enum port port = intel_dig_port->port; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5684 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5685 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 5686 | if (WARN(intel_dig_port->max_lanes < 1, |
| 5687 | "Not enough lanes (%d) for DP on port %c\n", |
| 5688 | intel_dig_port->max_lanes, port_name(port))) |
| 5689 | return false; |
| 5690 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 5691 | intel_dp->pps_pipe = INVALID_PIPE; |
| 5692 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5693 | /* intel_dp vfuncs */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5694 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 5695 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5696 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5697 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5698 | else if (HAS_PCH_SPLIT(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5699 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; |
| 5700 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 5701 | intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider; |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5702 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5703 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 5704 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; |
| 5705 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 5706 | intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl; |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 5707 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5708 | if (HAS_DDI(dev_priv)) |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 5709 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; |
| 5710 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 5711 | /* Preserve the current hw state. */ |
| 5712 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 5713 | intel_dp->attached_connector = intel_connector; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 5714 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5715 | if (intel_dp_is_edp(dev_priv, port)) |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 5716 | type = DRM_MODE_CONNECTOR_eDP; |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5717 | else |
| 5718 | type = DRM_MODE_CONNECTOR_DisplayPort; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 5719 | |
Imre Deak | f7d2490 | 2013-05-08 13:14:05 +0300 | [diff] [blame] | 5720 | /* |
| 5721 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but |
| 5722 | * for DP the encoder type can be set by the caller to |
| 5723 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. |
| 5724 | */ |
| 5725 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 5726 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 5727 | |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 5728 | /* eDP only on port B and/or C on vlv/chv */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5729 | if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 5730 | is_edp(intel_dp) && port != PORT_B && port != PORT_C)) |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 5731 | return false; |
| 5732 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 5733 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
| 5734 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", |
| 5735 | port_name(port)); |
| 5736 | |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 5737 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5738 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 5739 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5740 | connector->interlace_allowed = true; |
| 5741 | connector->doublescan_allowed = 0; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 5742 | |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 5743 | intel_dp_aux_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5744 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 5745 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 5746 | edp_panel_vdd_work); |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 5747 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 5748 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5749 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5750 | if (HAS_DDI(dev_priv)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 5751 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 5752 | else |
| 5753 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
| 5754 | |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 5755 | /* Set up the hotplug pin. */ |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 5756 | switch (port) { |
| 5757 | case PORT_A: |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 5758 | intel_encoder->hpd_pin = HPD_PORT_A; |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 5759 | break; |
| 5760 | case PORT_B: |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 5761 | intel_encoder->hpd_pin = HPD_PORT_B; |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 5762 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) |
Sonika Jindal | cf1d588 | 2015-08-10 10:35:36 +0530 | [diff] [blame] | 5763 | intel_encoder->hpd_pin = HPD_PORT_A; |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 5764 | break; |
| 5765 | case PORT_C: |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 5766 | intel_encoder->hpd_pin = HPD_PORT_C; |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 5767 | break; |
| 5768 | case PORT_D: |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 5769 | intel_encoder->hpd_pin = HPD_PORT_D; |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 5770 | break; |
Xiong Zhang | 26951ca | 2015-08-17 15:55:50 +0800 | [diff] [blame] | 5771 | case PORT_E: |
| 5772 | intel_encoder->hpd_pin = HPD_PORT_E; |
| 5773 | break; |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 5774 | default: |
Damien Lespiau | ad1c0b1 | 2013-03-07 15:30:28 +0000 | [diff] [blame] | 5775 | BUG(); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 5776 | } |
| 5777 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5778 | /* init MST on ports that can support it */ |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 5779 | if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) && |
Jani Nikula | 0c9b371 | 2015-05-18 17:10:01 +0300 | [diff] [blame] | 5780 | (port == PORT_B || port == PORT_C || port == PORT_D)) |
| 5781 | intel_dp_mst_encoder_init(intel_dig_port, |
| 5782 | intel_connector->base.base.id); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5783 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5784 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 5785 | intel_dp_aux_fini(intel_dp); |
| 5786 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
| 5787 | goto fail; |
Paulo Zanoni | b2f246a | 2013-06-12 17:27:26 -0300 | [diff] [blame] | 5788 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 5789 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5790 | intel_dp_add_properties(intel_dp, connector); |
| 5791 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5792 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 5793 | * 0xd. Failure to do so will result in spurious interrupts being |
| 5794 | * generated on the port when a cable is not attached. |
| 5795 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5796 | if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5797 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 5798 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 5799 | } |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 5800 | |
| 5801 | return true; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 5802 | |
| 5803 | fail: |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 5804 | drm_connector_cleanup(connector); |
| 5805 | |
| 5806 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5807 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5808 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 5809 | bool intel_dp_init(struct drm_i915_private *dev_priv, |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 5810 | i915_reg_t output_reg, |
| 5811 | enum port port) |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5812 | { |
| 5813 | struct intel_digital_port *intel_dig_port; |
| 5814 | struct intel_encoder *intel_encoder; |
| 5815 | struct drm_encoder *encoder; |
| 5816 | struct intel_connector *intel_connector; |
| 5817 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 5818 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5819 | if (!intel_dig_port) |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 5820 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5821 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 5822 | intel_connector = intel_connector_alloc(); |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 5823 | if (!intel_connector) |
| 5824 | goto err_connector_alloc; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5825 | |
| 5826 | intel_encoder = &intel_dig_port->base; |
| 5827 | encoder = &intel_encoder->base; |
| 5828 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 5829 | if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, |
| 5830 | &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, |
| 5831 | "DP %c", port_name(port))) |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 5832 | goto err_encoder_init; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5833 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 5834 | intel_encoder->compute_config = intel_dp_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 5835 | intel_encoder->disable = intel_disable_dp; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 5836 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 5837 | intel_encoder->get_config = intel_dp_get_config; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 5838 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5839 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 5840 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 5841 | intel_encoder->pre_enable = chv_pre_enable_dp; |
| 5842 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 5843 | intel_encoder->post_disable = chv_post_disable_dp; |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 5844 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 5845 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 5846 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 5847 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
| 5848 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 5849 | intel_encoder->post_disable = vlv_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 5850 | } else { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 5851 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 5852 | intel_encoder->enable = g4x_enable_dp; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5853 | if (INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 5854 | intel_encoder->post_disable = ilk_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 5855 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5856 | |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 5857 | intel_dig_port->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5858 | intel_dig_port->dp.output_reg = output_reg; |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 5859 | intel_dig_port->max_lanes = 4; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5860 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 5861 | intel_encoder->type = INTEL_OUTPUT_DP; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5862 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 882ec38 | 2014-04-28 14:07:43 +0300 | [diff] [blame] | 5863 | if (port == PORT_D) |
| 5864 | intel_encoder->crtc_mask = 1 << 2; |
| 5865 | else |
| 5866 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
| 5867 | } else { |
| 5868 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 5869 | } |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 5870 | intel_encoder->cloneable = 0; |
Pandiyan, Dhinakaran | 03cdc1d | 2016-09-19 18:24:38 -0700 | [diff] [blame] | 5871 | intel_encoder->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5872 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5873 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 5874 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5875 | |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 5876 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
| 5877 | goto err_init_connector; |
| 5878 | |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 5879 | return true; |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 5880 | |
| 5881 | err_init_connector: |
| 5882 | drm_encoder_cleanup(encoder); |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 5883 | err_encoder_init: |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 5884 | kfree(intel_connector); |
| 5885 | err_connector_alloc: |
| 5886 | kfree(intel_dig_port); |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 5887 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5888 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5889 | |
| 5890 | void intel_dp_mst_suspend(struct drm_device *dev) |
| 5891 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5892 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5893 | int i; |
| 5894 | |
| 5895 | /* disable MST */ |
| 5896 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 5897 | struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i]; |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 5898 | |
| 5899 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5900 | continue; |
| 5901 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 5902 | if (intel_dig_port->dp.is_mst) |
| 5903 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5904 | } |
| 5905 | } |
| 5906 | |
| 5907 | void intel_dp_mst_resume(struct drm_device *dev) |
| 5908 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5909 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5910 | int i; |
| 5911 | |
| 5912 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 5913 | struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i]; |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 5914 | int ret; |
| 5915 | |
| 5916 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5917 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5918 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 5919 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); |
| 5920 | if (ret) |
| 5921 | intel_dp_check_mst_status(&intel_dig_port->dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5922 | } |
| 5923 | } |