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> |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 31 | #include <linux/types.h> |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 32 | #include <linux/notifier.h> |
| 33 | #include <linux/reboot.h> |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 34 | #include <asm/byteorder.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 36 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drm_crtc.h> |
| 38 | #include <drm/drm_crtc_helper.h> |
| 39 | #include <drm/drm_edid.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 40 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 41 | #include <drm/i915_drm.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 42 | #include "i915_drv.h" |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 43 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 44 | #define DP_LINK_CHECK_TIMEOUT (10 * 1000) |
| 45 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 46 | /* Compliance test status bits */ |
| 47 | #define INTEL_DP_RESOLUTION_SHIFT_MASK 0 |
| 48 | #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 49 | #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 50 | #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 51 | |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 52 | struct dp_link_dpll { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 53 | int clock; |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 54 | struct dpll dpll; |
| 55 | }; |
| 56 | |
| 57 | static const struct dp_link_dpll gen4_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 58 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 59 | { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 60 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 61 | { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } } |
| 62 | }; |
| 63 | |
| 64 | static const struct dp_link_dpll pch_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 65 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 66 | { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 67 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 68 | { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } } |
| 69 | }; |
| 70 | |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 71 | static const struct dp_link_dpll vlv_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 72 | { 162000, |
Chon Ming Lee | 58f6e63 | 2013-09-25 15:47:51 +0800 | [diff] [blame] | 73 | { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 74 | { 270000, |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 75 | { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } } |
| 76 | }; |
| 77 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 78 | /* |
| 79 | * CHV supports eDP 1.4 that have more link rates. |
| 80 | * Below only provides the fixed rate but exclude variable rate. |
| 81 | */ |
| 82 | static const struct dp_link_dpll chv_dpll[] = { |
| 83 | /* |
| 84 | * CHV requires to program fractional division for m2. |
| 85 | * m2 is stored in fixed point format using formula below |
| 86 | * (m2_int << 22) | m2_fraction |
| 87 | */ |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 88 | { 162000, /* m2_int = 32, m2_fraction = 1677722 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 89 | { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 90 | { 270000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 91 | { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 92 | { 540000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 93 | { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } } |
| 94 | }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 95 | |
Sonika Jindal | 64987fc | 2015-05-26 17:50:13 +0530 | [diff] [blame] | 96 | static const int bxt_rates[] = { 162000, 216000, 243000, 270000, |
| 97 | 324000, 432000, 540000 }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 98 | static const int skl_rates[] = { 162000, 216000, 270000, |
Ville Syrjälä | f4896f1 | 2015-03-12 17:10:27 +0200 | [diff] [blame] | 99 | 324000, 432000, 540000 }; |
| 100 | static const int default_rates[] = { 162000, 270000, 540000 }; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 101 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 102 | /** |
| 103 | * is_edp - is the given port attached to an eDP panel (either CPU or PCH) |
| 104 | * @intel_dp: DP struct |
| 105 | * |
| 106 | * If a CPU or PCH DP output is attached to an eDP panel, this function |
| 107 | * will return true, and false otherwise. |
| 108 | */ |
| 109 | static bool is_edp(struct intel_dp *intel_dp) |
| 110 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 111 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 112 | |
| 113 | return intel_dig_port->base.type == INTEL_OUTPUT_EDP; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 116 | 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] | 117 | { |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 118 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 119 | |
| 120 | return intel_dig_port->base.base.dev; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 123 | static struct intel_dp *intel_attached_dp(struct drm_connector *connector) |
| 124 | { |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 125 | return enc_to_intel_dp(&intel_attached_encoder(connector)->base); |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 128 | static void intel_dp_link_down(struct intel_dp *intel_dp); |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 129 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 130 | 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] | 131 | 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] | 132 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 133 | enum pipe pipe); |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 134 | static void intel_dp_unset_edid(struct intel_dp *intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 135 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 136 | static int |
| 137 | intel_dp_max_link_bw(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 138 | { |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 139 | int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 140 | |
| 141 | switch (max_link_bw) { |
| 142 | case DP_LINK_BW_1_62: |
| 143 | case DP_LINK_BW_2_7: |
Ville Syrjälä | 1db10e2 | 2015-03-12 17:10:32 +0200 | [diff] [blame] | 144 | case DP_LINK_BW_5_4: |
Imre Deak | d4eead5 | 2013-07-09 17:05:26 +0300 | [diff] [blame] | 145 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 146 | default: |
Imre Deak | d4eead5 | 2013-07-09 17:05:26 +0300 | [diff] [blame] | 147 | WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n", |
| 148 | max_link_bw); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 149 | max_link_bw = DP_LINK_BW_1_62; |
| 150 | break; |
| 151 | } |
| 152 | return max_link_bw; |
| 153 | } |
| 154 | |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 155 | static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp) |
| 156 | { |
| 157 | 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] | 158 | u8 source_max, sink_max; |
| 159 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 160 | source_max = intel_dig_port->max_lanes; |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 161 | sink_max = intel_dp->max_sink_lane_count; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 162 | |
| 163 | return min(source_max, sink_max); |
| 164 | } |
| 165 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 166 | int |
Keith Packard | c898261 | 2012-01-25 08:16:25 -0800 | [diff] [blame] | 167 | intel_dp_link_required(int pixel_clock, int bpp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 168 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 169 | /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */ |
| 170 | return DIV_ROUND_UP(pixel_clock * bpp, 8); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 173 | int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 174 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 175 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 176 | /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the |
| 177 | * link rate that is generally expressed in Gbps. Since, 8 bits of data |
| 178 | * is transmitted every LS_Clk per lane, there is no need to account for |
| 179 | * the channel encoding that is done in the PHY layer here. |
| 180 | */ |
| 181 | |
| 182 | return max_link_clock * max_lanes; |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 183 | } |
| 184 | |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 185 | static int |
| 186 | intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp) |
| 187 | { |
| 188 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 189 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 190 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 191 | int max_dotclk = dev_priv->max_dotclk_freq; |
| 192 | int ds_max_dotclk; |
| 193 | |
| 194 | int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 195 | |
| 196 | if (type != DP_DS_PORT_TYPE_VGA) |
| 197 | return max_dotclk; |
| 198 | |
| 199 | ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd, |
| 200 | intel_dp->downstream_ports); |
| 201 | |
| 202 | if (ds_max_dotclk != 0) |
| 203 | max_dotclk = min(max_dotclk, ds_max_dotclk); |
| 204 | |
| 205 | return max_dotclk; |
| 206 | } |
| 207 | |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 208 | static int |
| 209 | intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates) |
| 210 | { |
| 211 | if (intel_dp->num_sink_rates) { |
| 212 | *sink_rates = intel_dp->sink_rates; |
| 213 | return intel_dp->num_sink_rates; |
| 214 | } |
| 215 | |
| 216 | *sink_rates = default_rates; |
| 217 | |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 218 | return (intel_dp->max_sink_link_bw >> 3) + 1; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int |
| 222 | intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates) |
| 223 | { |
| 224 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 225 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 226 | int size; |
| 227 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 228 | if (IS_GEN9_LP(dev_priv)) { |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 229 | *source_rates = bxt_rates; |
| 230 | size = ARRAY_SIZE(bxt_rates); |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 231 | } else if (IS_GEN9_BC(dev_priv)) { |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 232 | *source_rates = skl_rates; |
| 233 | size = ARRAY_SIZE(skl_rates); |
| 234 | } else { |
| 235 | *source_rates = default_rates; |
| 236 | size = ARRAY_SIZE(default_rates); |
| 237 | } |
| 238 | |
| 239 | /* This depends on the fact that 5.4 is last value in the array */ |
| 240 | if (!intel_dp_source_supports_hbr2(intel_dp)) |
| 241 | size--; |
| 242 | |
| 243 | return size; |
| 244 | } |
| 245 | |
| 246 | static int intersect_rates(const int *source_rates, int source_len, |
| 247 | const int *sink_rates, int sink_len, |
| 248 | int *common_rates) |
| 249 | { |
| 250 | int i = 0, j = 0, k = 0; |
| 251 | |
| 252 | while (i < source_len && j < sink_len) { |
| 253 | if (source_rates[i] == sink_rates[j]) { |
| 254 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
| 255 | return k; |
| 256 | common_rates[k] = source_rates[i]; |
| 257 | ++k; |
| 258 | ++i; |
| 259 | ++j; |
| 260 | } else if (source_rates[i] < sink_rates[j]) { |
| 261 | ++i; |
| 262 | } else { |
| 263 | ++j; |
| 264 | } |
| 265 | } |
| 266 | return k; |
| 267 | } |
| 268 | |
| 269 | static int intel_dp_common_rates(struct intel_dp *intel_dp, |
| 270 | int *common_rates) |
| 271 | { |
| 272 | const int *source_rates, *sink_rates; |
| 273 | int source_len, sink_len; |
| 274 | |
| 275 | sink_len = intel_dp_sink_rates(intel_dp, &sink_rates); |
| 276 | source_len = intel_dp_source_rates(intel_dp, &source_rates); |
| 277 | |
| 278 | return intersect_rates(source_rates, source_len, |
| 279 | sink_rates, sink_len, |
| 280 | common_rates); |
| 281 | } |
| 282 | |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 283 | static int intel_dp_link_rate_index(struct intel_dp *intel_dp, |
| 284 | int *common_rates, int link_rate) |
| 285 | { |
| 286 | int common_len; |
| 287 | int index; |
| 288 | |
| 289 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
| 290 | for (index = 0; index < common_len; index++) { |
| 291 | if (link_rate == common_rates[common_len - index - 1]) |
| 292 | return common_len - index - 1; |
| 293 | } |
| 294 | |
| 295 | return -1; |
| 296 | } |
| 297 | |
| 298 | int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, |
| 299 | int link_rate, uint8_t lane_count) |
| 300 | { |
| 301 | int common_rates[DP_MAX_SUPPORTED_RATES]; |
| 302 | int link_rate_index; |
| 303 | |
| 304 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 305 | common_rates, |
| 306 | link_rate); |
| 307 | if (link_rate_index > 0) { |
| 308 | intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]); |
| 309 | intel_dp->max_sink_lane_count = lane_count; |
| 310 | } else if (lane_count > 1) { |
| 311 | intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp); |
| 312 | intel_dp->max_sink_lane_count = lane_count >> 1; |
| 313 | } else { |
| 314 | DRM_ERROR("Link Training Unsuccessful\n"); |
| 315 | return -1; |
| 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 321 | static enum drm_mode_status |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 322 | intel_dp_mode_valid(struct drm_connector *connector, |
| 323 | struct drm_display_mode *mode) |
| 324 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 325 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 326 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 327 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 328 | int target_clock = mode->clock; |
| 329 | int max_rate, mode_rate, max_lanes, max_link_clock; |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 330 | int max_dotclk; |
| 331 | |
| 332 | max_dotclk = intel_dp_downstream_max_dotclock(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 333 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 334 | if (is_edp(intel_dp) && fixed_mode) { |
| 335 | if (mode->hdisplay > fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 336 | return MODE_PANEL; |
| 337 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 338 | if (mode->vdisplay > fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 339 | return MODE_PANEL; |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 340 | |
| 341 | target_clock = fixed_mode->clock; |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 344 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 345 | max_lanes = intel_dp_max_lane_count(intel_dp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 346 | |
| 347 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); |
| 348 | mode_rate = intel_dp_link_required(target_clock, 18); |
| 349 | |
Mika Kahola | 799487f | 2016-02-02 15:16:38 +0200 | [diff] [blame] | 350 | if (mode_rate > max_rate || target_clock > max_dotclk) |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 351 | return MODE_CLOCK_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 352 | |
| 353 | if (mode->clock < 10000) |
| 354 | return MODE_CLOCK_LOW; |
| 355 | |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 356 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 357 | return MODE_H_ILLEGAL; |
| 358 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 359 | return MODE_OK; |
| 360 | } |
| 361 | |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 362 | 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] | 363 | { |
| 364 | int i; |
| 365 | uint32_t v = 0; |
| 366 | |
| 367 | if (src_bytes > 4) |
| 368 | src_bytes = 4; |
| 369 | for (i = 0; i < src_bytes; i++) |
| 370 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 371 | return v; |
| 372 | } |
| 373 | |
Damien Lespiau | c2af70e | 2015-02-10 19:32:23 +0000 | [diff] [blame] | 374 | 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] | 375 | { |
| 376 | int i; |
| 377 | if (dst_bytes > 4) |
| 378 | dst_bytes = 4; |
| 379 | for (i = 0; i < dst_bytes; i++) |
| 380 | dst[i] = src >> ((3-i) * 8); |
| 381 | } |
| 382 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 383 | static void |
| 384 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 385 | struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 386 | static void |
| 387 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 388 | struct intel_dp *intel_dp, |
| 389 | bool force_disable_vdd); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 390 | static void |
| 391 | 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] | 392 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 393 | static void pps_lock(struct intel_dp *intel_dp) |
| 394 | { |
| 395 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 396 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 397 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 398 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 399 | enum intel_display_power_domain power_domain; |
| 400 | |
| 401 | /* |
| 402 | * See vlv_power_sequencer_reset() why we need |
| 403 | * a power domain reference here. |
| 404 | */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 405 | power_domain = intel_display_port_aux_power_domain(encoder); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 406 | intel_display_power_get(dev_priv, power_domain); |
| 407 | |
| 408 | mutex_lock(&dev_priv->pps_mutex); |
| 409 | } |
| 410 | |
| 411 | static void pps_unlock(struct intel_dp *intel_dp) |
| 412 | { |
| 413 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 414 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 415 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 416 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 417 | enum intel_display_power_domain power_domain; |
| 418 | |
| 419 | mutex_unlock(&dev_priv->pps_mutex); |
| 420 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 421 | power_domain = intel_display_port_aux_power_domain(encoder); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 422 | intel_display_power_put(dev_priv, power_domain); |
| 423 | } |
| 424 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 425 | static void |
| 426 | vlv_power_sequencer_kick(struct intel_dp *intel_dp) |
| 427 | { |
| 428 | 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] | 429 | 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] | 430 | enum pipe pipe = intel_dp->pps_pipe; |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 431 | bool pll_enabled, release_cl_override = false; |
| 432 | enum dpio_phy phy = DPIO_PHY(pipe); |
| 433 | enum dpio_channel ch = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 434 | uint32_t DP; |
| 435 | |
| 436 | if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN, |
| 437 | "skipping pipe %c power seqeuncer kick due to port %c being active\n", |
| 438 | pipe_name(pipe), port_name(intel_dig_port->port))) |
| 439 | return; |
| 440 | |
| 441 | DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n", |
| 442 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 443 | |
| 444 | /* Preserve the BIOS-computed detected bit. This is |
| 445 | * supposed to be read-only. |
| 446 | */ |
| 447 | DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
| 448 | DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
| 449 | DP |= DP_PORT_WIDTH(1); |
| 450 | DP |= DP_LINK_TRAIN_PAT_1; |
| 451 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 452 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 453 | DP |= DP_PIPE_SELECT_CHV(pipe); |
| 454 | else if (pipe == PIPE_B) |
| 455 | DP |= DP_PIPEB_SELECT; |
| 456 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 457 | pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE; |
| 458 | |
| 459 | /* |
| 460 | * The DPLL for the pipe must be enabled for this to work. |
| 461 | * So enable temporarily it if it's not already enabled. |
| 462 | */ |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 463 | if (!pll_enabled) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 464 | release_cl_override = IS_CHERRYVIEW(dev_priv) && |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 465 | !chv_phy_powergate_ch(dev_priv, phy, ch, true); |
| 466 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 467 | if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ? |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 468 | &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) { |
| 469 | DRM_ERROR("Failed to force on pll for pipe %c!\n", |
| 470 | pipe_name(pipe)); |
| 471 | return; |
| 472 | } |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 473 | } |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 474 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 475 | /* |
| 476 | * Similar magic as in intel_dp_enable_port(). |
| 477 | * We _must_ do this port enable + disable trick |
| 478 | * to make this power seqeuencer lock onto the port. |
| 479 | * Otherwise even VDD force bit won't work. |
| 480 | */ |
| 481 | I915_WRITE(intel_dp->output_reg, DP); |
| 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); |
| 486 | |
| 487 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
| 488 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 489 | |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 490 | if (!pll_enabled) { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 491 | vlv_force_pll_off(dev_priv, pipe); |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 492 | |
| 493 | if (release_cl_override) |
| 494 | chv_phy_powergate_ch(dev_priv, phy, ch, false); |
| 495 | } |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 496 | } |
| 497 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 498 | static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv) |
| 499 | { |
| 500 | struct intel_encoder *encoder; |
| 501 | unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); |
| 502 | |
| 503 | /* |
| 504 | * We don't have power sequencer currently. |
| 505 | * Pick one that's not used by other ports. |
| 506 | */ |
| 507 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 508 | struct intel_dp *intel_dp; |
| 509 | |
| 510 | if (encoder->type != INTEL_OUTPUT_DP && |
| 511 | encoder->type != INTEL_OUTPUT_EDP) |
| 512 | continue; |
| 513 | |
| 514 | intel_dp = enc_to_intel_dp(&encoder->base); |
| 515 | |
| 516 | if (encoder->type == INTEL_OUTPUT_EDP) { |
| 517 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 518 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 519 | |
| 520 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 521 | pipes &= ~(1 << intel_dp->pps_pipe); |
| 522 | } else { |
| 523 | WARN_ON(intel_dp->pps_pipe != INVALID_PIPE); |
| 524 | |
| 525 | if (intel_dp->active_pipe != INVALID_PIPE) |
| 526 | pipes &= ~(1 << intel_dp->active_pipe); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | if (pipes == 0) |
| 531 | return INVALID_PIPE; |
| 532 | |
| 533 | return ffs(pipes) - 1; |
| 534 | } |
| 535 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 536 | static enum pipe |
| 537 | vlv_power_sequencer_pipe(struct intel_dp *intel_dp) |
| 538 | { |
| 539 | 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] | 540 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 541 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 542 | enum pipe pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 543 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 544 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 545 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 546 | /* We should never land here with regular DP ports */ |
| 547 | WARN_ON(!is_edp(intel_dp)); |
| 548 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 549 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 550 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 551 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 552 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 553 | return intel_dp->pps_pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 554 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 555 | pipe = vlv_find_free_pps(dev_priv); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 556 | |
| 557 | /* |
| 558 | * Didn't find one. This should not happen since there |
| 559 | * are two power sequencers and up to two eDP ports. |
| 560 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 561 | if (WARN_ON(pipe == INVALID_PIPE)) |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 562 | pipe = PIPE_A; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 563 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 564 | vlv_steal_power_sequencer(dev, pipe); |
| 565 | intel_dp->pps_pipe = pipe; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 566 | |
| 567 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", |
| 568 | pipe_name(intel_dp->pps_pipe), |
| 569 | port_name(intel_dig_port->port)); |
| 570 | |
| 571 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 572 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 573 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 574 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 575 | /* |
| 576 | * Even vdd force doesn't work until we've made |
| 577 | * the power sequencer lock in on the port. |
| 578 | */ |
| 579 | vlv_power_sequencer_kick(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 580 | |
| 581 | return intel_dp->pps_pipe; |
| 582 | } |
| 583 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 584 | static int |
| 585 | bxt_power_sequencer_idx(struct intel_dp *intel_dp) |
| 586 | { |
| 587 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 588 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 589 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 590 | |
| 591 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 592 | |
| 593 | /* We should never land here with regular DP ports */ |
| 594 | WARN_ON(!is_edp(intel_dp)); |
| 595 | |
| 596 | /* |
| 597 | * TODO: BXT has 2 PPS instances. The correct port->PPS instance |
| 598 | * mapping needs to be retrieved from VBT, for now just hard-code to |
| 599 | * use instance #0 always. |
| 600 | */ |
| 601 | if (!intel_dp->pps_reset) |
| 602 | return 0; |
| 603 | |
| 604 | intel_dp->pps_reset = false; |
| 605 | |
| 606 | /* |
| 607 | * Only the HW needs to be reprogrammed, the SW state is fixed and |
| 608 | * has been setup during connector init. |
| 609 | */ |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 610 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 615 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
| 616 | enum pipe pipe); |
| 617 | |
| 618 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, |
| 619 | enum pipe pipe) |
| 620 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 621 | return I915_READ(PP_STATUS(pipe)) & PP_ON; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, |
| 625 | enum pipe pipe) |
| 626 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 627 | return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, |
| 631 | enum pipe pipe) |
| 632 | { |
| 633 | return true; |
| 634 | } |
| 635 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 636 | static enum pipe |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 637 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
| 638 | enum port port, |
| 639 | vlv_pipe_check pipe_check) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 640 | { |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 641 | enum pipe pipe; |
| 642 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 643 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 644 | u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) & |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 645 | PANEL_PORT_SELECT_MASK; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 646 | |
| 647 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) |
| 648 | continue; |
| 649 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 650 | if (!pipe_check(dev_priv, pipe)) |
| 651 | continue; |
| 652 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 653 | return pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 654 | } |
| 655 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 656 | return INVALID_PIPE; |
| 657 | } |
| 658 | |
| 659 | static void |
| 660 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) |
| 661 | { |
| 662 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 663 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 664 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 665 | enum port port = intel_dig_port->port; |
| 666 | |
| 667 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 668 | |
| 669 | /* try to find a pipe with this port selected */ |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 670 | /* first pick one where the panel is on */ |
| 671 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 672 | vlv_pipe_has_pp_on); |
| 673 | /* didn't find one? pick one where vdd is on */ |
| 674 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 675 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 676 | vlv_pipe_has_vdd_on); |
| 677 | /* didn't find one? pick one with just the correct port */ |
| 678 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 679 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 680 | vlv_pipe_any); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 681 | |
| 682 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ |
| 683 | if (intel_dp->pps_pipe == INVALID_PIPE) { |
| 684 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", |
| 685 | port_name(port)); |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
| 690 | port_name(port), pipe_name(intel_dp->pps_pipe)); |
| 691 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 692 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 693 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 694 | } |
| 695 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 696 | void intel_power_sequencer_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 697 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 698 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 699 | struct intel_encoder *encoder; |
| 700 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 701 | 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] | 702 | !IS_GEN9_LP(dev_priv))) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 703 | return; |
| 704 | |
| 705 | /* |
| 706 | * We can't grab pps_mutex here due to deadlock with power_domain |
| 707 | * mutex when power_domain functions are called while holding pps_mutex. |
| 708 | * That also means that in order to use pps_pipe the code needs to |
| 709 | * hold both a power domain reference and pps_mutex, and the power domain |
| 710 | * reference get/put must be done while _not_ holding pps_mutex. |
| 711 | * pps_{lock,unlock}() do these steps in the correct order, so one |
| 712 | * should use them always. |
| 713 | */ |
| 714 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 715 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 716 | struct intel_dp *intel_dp; |
| 717 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 718 | if (encoder->type != INTEL_OUTPUT_DP && |
| 719 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 720 | continue; |
| 721 | |
| 722 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 723 | |
| 724 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 725 | |
| 726 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 727 | continue; |
| 728 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 729 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 730 | intel_dp->pps_reset = true; |
| 731 | else |
| 732 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 733 | } |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 734 | } |
| 735 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 736 | struct pps_registers { |
| 737 | i915_reg_t pp_ctrl; |
| 738 | i915_reg_t pp_stat; |
| 739 | i915_reg_t pp_on; |
| 740 | i915_reg_t pp_off; |
| 741 | i915_reg_t pp_div; |
| 742 | }; |
| 743 | |
| 744 | static void intel_pps_get_registers(struct drm_i915_private *dev_priv, |
| 745 | struct intel_dp *intel_dp, |
| 746 | struct pps_registers *regs) |
| 747 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 748 | int pps_idx = 0; |
| 749 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 750 | memset(regs, 0, sizeof(*regs)); |
| 751 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 752 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 753 | pps_idx = bxt_power_sequencer_idx(intel_dp); |
| 754 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 755 | pps_idx = vlv_power_sequencer_pipe(intel_dp); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 756 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 757 | regs->pp_ctrl = PP_CONTROL(pps_idx); |
| 758 | regs->pp_stat = PP_STATUS(pps_idx); |
| 759 | regs->pp_on = PP_ON_DELAYS(pps_idx); |
| 760 | regs->pp_off = PP_OFF_DELAYS(pps_idx); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 761 | if (!IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 762 | regs->pp_div = PP_DIVISOR(pps_idx); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 763 | } |
| 764 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 765 | static i915_reg_t |
| 766 | _pp_ctrl_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 767 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 768 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 769 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 770 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 771 | ®s); |
| 772 | |
| 773 | return regs.pp_ctrl; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 774 | } |
| 775 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 776 | static i915_reg_t |
| 777 | _pp_stat_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 778 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 779 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 780 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 781 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 782 | ®s); |
| 783 | |
| 784 | return regs.pp_stat; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 785 | } |
| 786 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 787 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
| 788 | This function only applicable when panel PM state is not to be tracked */ |
| 789 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, |
| 790 | void *unused) |
| 791 | { |
| 792 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), |
| 793 | edp_notifier); |
| 794 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 795 | struct drm_i915_private *dev_priv = to_i915(dev); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 796 | |
| 797 | if (!is_edp(intel_dp) || code != SYS_RESTART) |
| 798 | return 0; |
| 799 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 800 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 801 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 802 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 803 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 804 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 805 | u32 pp_div; |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 806 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 807 | pp_ctrl_reg = PP_CONTROL(pipe); |
| 808 | pp_div_reg = PP_DIVISOR(pipe); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 809 | pp_div = I915_READ(pp_div_reg); |
| 810 | pp_div &= PP_REFERENCE_DIVIDER_MASK; |
| 811 | |
| 812 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ |
| 813 | I915_WRITE(pp_div_reg, pp_div | 0x1F); |
| 814 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 815 | msleep(intel_dp->panel_power_cycle_delay); |
| 816 | } |
| 817 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 818 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 819 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 820 | return 0; |
| 821 | } |
| 822 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 823 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 824 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 825 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 826 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 827 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 828 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 829 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 830 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 831 | intel_dp->pps_pipe == INVALID_PIPE) |
| 832 | return false; |
| 833 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 834 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 837 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 838 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 839 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 840 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 841 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 842 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 843 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 844 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 845 | intel_dp->pps_pipe == INVALID_PIPE) |
| 846 | return false; |
| 847 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 848 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 851 | static void |
| 852 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 853 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 854 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 855 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 856 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 857 | if (!is_edp(intel_dp)) |
| 858 | return; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 859 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 860 | 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] | 861 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 862 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 863 | I915_READ(_pp_stat_reg(intel_dp)), |
| 864 | I915_READ(_pp_ctrl_reg(intel_dp))); |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 868 | static uint32_t |
| 869 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) |
| 870 | { |
| 871 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 872 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 873 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 874 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 875 | uint32_t status; |
| 876 | bool done; |
| 877 | |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 878 | #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] | 879 | if (has_aux_irq) |
Paulo Zanoni | b18ac46 | 2013-02-18 19:00:24 -0300 | [diff] [blame] | 880 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
Imre Deak | 3598706 | 2013-05-21 20:03:20 +0300 | [diff] [blame] | 881 | msecs_to_jiffies_timeout(10)); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 882 | else |
Imre Deak | 713a6b66 | 2016-06-28 13:37:33 +0300 | [diff] [blame] | 883 | done = wait_for(C, 10) == 0; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 884 | if (!done) |
| 885 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", |
| 886 | has_aux_irq); |
| 887 | #undef C |
| 888 | |
| 889 | return status; |
| 890 | } |
| 891 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 892 | 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] | 893 | { |
| 894 | 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] | 895 | 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] | 896 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 897 | if (index) |
| 898 | return 0; |
| 899 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 900 | /* |
| 901 | * 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] | 902 | * 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] | 903 | */ |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 904 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 908 | { |
| 909 | 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] | 910 | 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] | 911 | |
| 912 | if (index) |
| 913 | return 0; |
| 914 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 915 | /* |
| 916 | * The clock divider is based off the cdclk or PCH rawclk, and would |
| 917 | * like to run at 2MHz. So, take the cdclk or PCH rawclk value and |
| 918 | * divide by 2000 and use that |
| 919 | */ |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 920 | if (intel_dig_port->port == PORT_A) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 921 | return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 922 | else |
| 923 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | 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] | 927 | { |
| 928 | 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] | 929 | 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] | 930 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 931 | 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] | 932 | /* Workaround for non-ULT HSW */ |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 933 | switch (index) { |
| 934 | case 0: return 63; |
| 935 | case 1: return 72; |
| 936 | default: return 0; |
| 937 | } |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 938 | } |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 939 | |
| 940 | return ilk_get_aux_clock_divider(intel_dp, index); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 941 | } |
| 942 | |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 943 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 944 | { |
| 945 | /* |
| 946 | * SKL doesn't need us to program the AUX clock divider (Hardware will |
| 947 | * derive the clock from CDCLK automatically). We still implement the |
| 948 | * get_aux_clock_divider vfunc to plug-in into the existing code. |
| 949 | */ |
| 950 | return index ? 0 : 1; |
| 951 | } |
| 952 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 953 | static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 954 | bool has_aux_irq, |
| 955 | int send_bytes, |
| 956 | uint32_t aux_clock_divider) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 957 | { |
| 958 | 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] | 959 | struct drm_i915_private *dev_priv = |
| 960 | to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 961 | uint32_t precharge, timeout; |
| 962 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 963 | if (IS_GEN6(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 964 | precharge = 3; |
| 965 | else |
| 966 | precharge = 5; |
| 967 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 968 | if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 969 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
| 970 | else |
| 971 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; |
| 972 | |
| 973 | return DP_AUX_CH_CTL_SEND_BUSY | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 974 | DP_AUX_CH_CTL_DONE | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 975 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 976 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 977 | timeout | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 978 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 979 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 980 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 981 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 984 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 985 | bool has_aux_irq, |
| 986 | int send_bytes, |
| 987 | uint32_t unused) |
| 988 | { |
| 989 | return DP_AUX_CH_CTL_SEND_BUSY | |
| 990 | DP_AUX_CH_CTL_DONE | |
| 991 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
| 992 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 993 | DP_AUX_CH_CTL_TIME_OUT_1600us | |
| 994 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
| 995 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 996 | DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 997 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); |
| 998 | } |
| 999 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1000 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1001 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
Daniel Vetter | bd9f74a | 2014-10-02 09:45:35 +0200 | [diff] [blame] | 1002 | const uint8_t *send, int send_bytes, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1003 | uint8_t *recv, int recv_size) |
| 1004 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1005 | 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] | 1006 | struct drm_i915_private *dev_priv = |
| 1007 | to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1008 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1009 | uint32_t aux_clock_divider; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1010 | int i, ret, recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1011 | uint32_t status; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1012 | int try, clock = 0; |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 1013 | bool has_aux_irq = HAS_AUX_IRQ(dev_priv); |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1014 | bool vdd; |
| 1015 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1016 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1017 | |
Ville Syrjälä | 72c3500 | 2014-08-18 22:16:00 +0300 | [diff] [blame] | 1018 | /* |
| 1019 | * We will be called with VDD already enabled for dpcd/edid/oui reads. |
| 1020 | * In such cases we want to leave VDD enabled and it's up to upper layers |
| 1021 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off |
| 1022 | * ourselves. |
| 1023 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 1024 | vdd = edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1025 | |
| 1026 | /* dp aux is extremely sensitive to irq latency, hence request the |
| 1027 | * lowest possible wakeup latency and so prevent the cpu from going into |
| 1028 | * deep sleep states. |
| 1029 | */ |
| 1030 | pm_qos_update_request(&dev_priv->pm_qos, 0); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1031 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 1032 | intel_dp_check_edp(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1033 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1034 | /* Try to wait for any previous AUX channel activity */ |
| 1035 | for (try = 0; try < 3; try++) { |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 1036 | status = I915_READ_NOTRACE(ch_ctl); |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1037 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 1038 | break; |
| 1039 | msleep(1); |
| 1040 | } |
| 1041 | |
| 1042 | if (try == 3) { |
Mika Kuoppala | 02196c7 | 2015-08-06 16:48:58 +0300 | [diff] [blame] | 1043 | static u32 last_status = -1; |
| 1044 | const u32 status = I915_READ(ch_ctl); |
| 1045 | |
| 1046 | if (status != last_status) { |
| 1047 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 1048 | status); |
| 1049 | last_status = status; |
| 1050 | } |
| 1051 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1052 | ret = -EBUSY; |
| 1053 | goto out; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1056 | /* Only 5 data registers! */ |
| 1057 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { |
| 1058 | ret = -E2BIG; |
| 1059 | goto out; |
| 1060 | } |
| 1061 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 1062 | 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] | 1063 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
| 1064 | has_aux_irq, |
| 1065 | send_bytes, |
| 1066 | aux_clock_divider); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1067 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1068 | /* Must try at least 3 times according to DP spec */ |
| 1069 | for (try = 0; try < 5; try++) { |
| 1070 | /* Load the send data into the aux channel data registers */ |
| 1071 | for (i = 0; i < send_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1072 | I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2], |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1073 | intel_dp_pack_aux(send + i, |
| 1074 | send_bytes - i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1075 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1076 | /* Send the command and wait for it to complete */ |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1077 | I915_WRITE(ch_ctl, send_ctl); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1078 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1079 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1080 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1081 | /* Clear done status and any errors */ |
| 1082 | I915_WRITE(ch_ctl, |
| 1083 | status | |
| 1084 | DP_AUX_CH_CTL_DONE | |
| 1085 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1086 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Adam Jackson | d7e96fe | 2011-07-26 15:39:46 -0400 | [diff] [blame] | 1087 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1088 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1089 | continue; |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1090 | |
| 1091 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 |
| 1092 | * 400us delay required for errors and timeouts |
| 1093 | * Timeout errors from the HW already meet this |
| 1094 | * requirement so skip to next iteration |
| 1095 | */ |
| 1096 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
| 1097 | usleep_range(400, 500); |
| 1098 | continue; |
| 1099 | } |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1100 | if (status & DP_AUX_CH_CTL_DONE) |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1101 | goto done; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1102 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1105 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1106 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1107 | ret = -EBUSY; |
| 1108 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1111 | done: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1112 | /* Check for timeout or receive error. |
| 1113 | * Timeouts occur when the sink is not connected |
| 1114 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1115 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1116 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1117 | ret = -EIO; |
| 1118 | goto out; |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1119 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1120 | |
| 1121 | /* Timeouts occur when the device isn't connected, so they're |
| 1122 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1123 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Chris Wilson | a5570fe | 2017-02-23 11:51:02 +0000 | [diff] [blame] | 1124 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1125 | ret = -ETIMEDOUT; |
| 1126 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /* Unload any bytes sent back from the other side */ |
| 1130 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 1131 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1132 | |
| 1133 | /* |
| 1134 | * By BSpec: "Message sizes of 0 or >20 are not allowed." |
| 1135 | * We have no idea of what happened so we return -EBUSY so |
| 1136 | * drm layer takes care for the necessary retries. |
| 1137 | */ |
| 1138 | if (recv_bytes == 0 || recv_bytes > 20) { |
| 1139 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", |
| 1140 | recv_bytes); |
| 1141 | /* |
| 1142 | * FIXME: This patch was created on top of a series that |
| 1143 | * organize the retries at drm level. There EBUSY should |
| 1144 | * also take care for 1ms wait before retrying. |
| 1145 | * That aux retries re-org is still needed and after that is |
| 1146 | * merged we remove this sleep from here. |
| 1147 | */ |
| 1148 | usleep_range(1000, 1500); |
| 1149 | ret = -EBUSY; |
| 1150 | goto out; |
| 1151 | } |
| 1152 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1153 | if (recv_bytes > recv_size) |
| 1154 | recv_bytes = recv_size; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1155 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1156 | for (i = 0; i < recv_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1157 | 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] | 1158 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1159 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1160 | ret = recv_bytes; |
| 1161 | out: |
| 1162 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); |
| 1163 | |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1164 | if (vdd) |
| 1165 | edp_panel_vdd_off(intel_dp, false); |
| 1166 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1167 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1168 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1169 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1172 | #define BARE_ADDRESS_SIZE 3 |
| 1173 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1174 | static ssize_t |
| 1175 | 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] | 1176 | { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1177 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
| 1178 | uint8_t txbuf[20], rxbuf[20]; |
| 1179 | size_t txsize, rxsize; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1180 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1181 | |
Ville Syrjälä | d2d9cbb | 2015-03-19 11:44:06 +0200 | [diff] [blame] | 1182 | txbuf[0] = (msg->request << 4) | |
| 1183 | ((msg->address >> 16) & 0xf); |
| 1184 | txbuf[1] = (msg->address >> 8) & 0xff; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1185 | txbuf[2] = msg->address & 0xff; |
| 1186 | txbuf[3] = msg->size - 1; |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1187 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1188 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
| 1189 | case DP_AUX_NATIVE_WRITE: |
| 1190 | case DP_AUX_I2C_WRITE: |
Ville Syrjälä | c1e74122 | 2015-08-27 17:23:27 +0300 | [diff] [blame] | 1191 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1192 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1193 | rxsize = 2; /* 0 or 1 data bytes */ |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1194 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1195 | if (WARN_ON(txsize > 20)) |
| 1196 | return -E2BIG; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1197 | |
Ville Syrjälä | dd78809 | 2016-07-28 17:55:04 +0300 | [diff] [blame] | 1198 | WARN_ON(!msg->buffer != !msg->size); |
| 1199 | |
Imre Deak | d81a67c | 2016-01-29 14:52:26 +0200 | [diff] [blame] | 1200 | if (msg->buffer) |
| 1201 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1202 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1203 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1204 | if (ret > 0) { |
| 1205 | msg->reply = rxbuf[0] >> 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1206 | |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1207 | if (ret > 1) { |
| 1208 | /* Number of bytes written in a short write. */ |
| 1209 | ret = clamp_t(int, rxbuf[1], 0, msg->size); |
| 1210 | } else { |
| 1211 | /* Return payload size. */ |
| 1212 | ret = msg->size; |
| 1213 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1214 | } |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1215 | break; |
| 1216 | |
| 1217 | case DP_AUX_NATIVE_READ: |
| 1218 | case DP_AUX_I2C_READ: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1219 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1220 | rxsize = msg->size + 1; |
| 1221 | |
| 1222 | if (WARN_ON(rxsize > 20)) |
| 1223 | return -E2BIG; |
| 1224 | |
| 1225 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1226 | if (ret > 0) { |
| 1227 | msg->reply = rxbuf[0] >> 4; |
| 1228 | /* |
| 1229 | * Assume happy day, and copy the data. The caller is |
| 1230 | * expected to check msg->reply before touching it. |
| 1231 | * |
| 1232 | * Return payload size. |
| 1233 | */ |
| 1234 | ret--; |
| 1235 | memcpy(msg->buffer, rxbuf + 1, ret); |
| 1236 | } |
| 1237 | break; |
| 1238 | |
| 1239 | default: |
| 1240 | ret = -EINVAL; |
| 1241 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1242 | } |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1243 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1244 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1247 | static enum port intel_aux_port(struct drm_i915_private *dev_priv, |
| 1248 | enum port port) |
| 1249 | { |
| 1250 | const struct ddi_vbt_port_info *info = |
| 1251 | &dev_priv->vbt.ddi_port_info[port]; |
| 1252 | enum port aux_port; |
| 1253 | |
| 1254 | if (!info->alternate_aux_channel) { |
| 1255 | DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n", |
| 1256 | port_name(port), port_name(port)); |
| 1257 | return port; |
| 1258 | } |
| 1259 | |
| 1260 | switch (info->alternate_aux_channel) { |
| 1261 | case DP_AUX_A: |
| 1262 | aux_port = PORT_A; |
| 1263 | break; |
| 1264 | case DP_AUX_B: |
| 1265 | aux_port = PORT_B; |
| 1266 | break; |
| 1267 | case DP_AUX_C: |
| 1268 | aux_port = PORT_C; |
| 1269 | break; |
| 1270 | case DP_AUX_D: |
| 1271 | aux_port = PORT_D; |
| 1272 | break; |
| 1273 | default: |
| 1274 | MISSING_CASE(info->alternate_aux_channel); |
| 1275 | aux_port = PORT_A; |
| 1276 | break; |
| 1277 | } |
| 1278 | |
| 1279 | DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n", |
| 1280 | port_name(aux_port), port_name(port)); |
| 1281 | |
| 1282 | return aux_port; |
| 1283 | } |
| 1284 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1285 | 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] | 1286 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1287 | { |
| 1288 | switch (port) { |
| 1289 | case PORT_B: |
| 1290 | case PORT_C: |
| 1291 | case PORT_D: |
| 1292 | return DP_AUX_CH_CTL(port); |
| 1293 | default: |
| 1294 | MISSING_CASE(port); |
| 1295 | return DP_AUX_CH_CTL(PORT_B); |
| 1296 | } |
| 1297 | } |
| 1298 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1299 | 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] | 1300 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1301 | { |
| 1302 | switch (port) { |
| 1303 | case PORT_B: |
| 1304 | case PORT_C: |
| 1305 | case PORT_D: |
| 1306 | return DP_AUX_CH_DATA(port, index); |
| 1307 | default: |
| 1308 | MISSING_CASE(port); |
| 1309 | return DP_AUX_CH_DATA(PORT_B, index); |
| 1310 | } |
| 1311 | } |
| 1312 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1313 | 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] | 1314 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1315 | { |
| 1316 | switch (port) { |
| 1317 | case PORT_A: |
| 1318 | return DP_AUX_CH_CTL(port); |
| 1319 | case PORT_B: |
| 1320 | case PORT_C: |
| 1321 | case PORT_D: |
| 1322 | return PCH_DP_AUX_CH_CTL(port); |
| 1323 | default: |
| 1324 | MISSING_CASE(port); |
| 1325 | return DP_AUX_CH_CTL(PORT_A); |
| 1326 | } |
| 1327 | } |
| 1328 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1329 | 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] | 1330 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1331 | { |
| 1332 | switch (port) { |
| 1333 | case PORT_A: |
| 1334 | return DP_AUX_CH_DATA(port, index); |
| 1335 | case PORT_B: |
| 1336 | case PORT_C: |
| 1337 | case PORT_D: |
| 1338 | return PCH_DP_AUX_CH_DATA(port, index); |
| 1339 | default: |
| 1340 | MISSING_CASE(port); |
| 1341 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1342 | } |
| 1343 | } |
| 1344 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1345 | 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] | 1346 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1347 | { |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1348 | switch (port) { |
| 1349 | case PORT_A: |
| 1350 | case PORT_B: |
| 1351 | case PORT_C: |
| 1352 | case PORT_D: |
| 1353 | return DP_AUX_CH_CTL(port); |
| 1354 | default: |
| 1355 | MISSING_CASE(port); |
| 1356 | return DP_AUX_CH_CTL(PORT_A); |
| 1357 | } |
| 1358 | } |
| 1359 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1360 | 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] | 1361 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1362 | { |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1363 | switch (port) { |
| 1364 | case PORT_A: |
| 1365 | case PORT_B: |
| 1366 | case PORT_C: |
| 1367 | case PORT_D: |
| 1368 | return DP_AUX_CH_DATA(port, index); |
| 1369 | default: |
| 1370 | MISSING_CASE(port); |
| 1371 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1372 | } |
| 1373 | } |
| 1374 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1375 | 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] | 1376 | enum port port) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1377 | { |
| 1378 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1379 | return skl_aux_ctl_reg(dev_priv, port); |
| 1380 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1381 | return ilk_aux_ctl_reg(dev_priv, port); |
| 1382 | else |
| 1383 | return g4x_aux_ctl_reg(dev_priv, port); |
| 1384 | } |
| 1385 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1386 | 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] | 1387 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1388 | { |
| 1389 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1390 | return skl_aux_data_reg(dev_priv, port, index); |
| 1391 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1392 | return ilk_aux_data_reg(dev_priv, port, index); |
| 1393 | else |
| 1394 | return g4x_aux_data_reg(dev_priv, port, index); |
| 1395 | } |
| 1396 | |
| 1397 | static void intel_aux_reg_init(struct intel_dp *intel_dp) |
| 1398 | { |
| 1399 | 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] | 1400 | enum port port = intel_aux_port(dev_priv, |
| 1401 | dp_to_dig_port(intel_dp)->port); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1402 | int i; |
| 1403 | |
| 1404 | intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); |
| 1405 | for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++) |
| 1406 | intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i); |
| 1407 | } |
| 1408 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1409 | static void |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1410 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
| 1411 | { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1412 | kfree(intel_dp->aux.name); |
| 1413 | } |
| 1414 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1415 | static void |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 1416 | intel_dp_aux_init(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1417 | { |
Jani Nikula | 33ad662 | 2014-03-14 16:51:16 +0200 | [diff] [blame] | 1418 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 1419 | enum port port = intel_dig_port->port; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1420 | |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1421 | intel_aux_reg_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1422 | drm_dp_aux_init(&intel_dp->aux); |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 1423 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1424 | /* Failure to allocate our preferred name is not critical */ |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1425 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port)); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1426 | intel_dp->aux.transfer = intel_dp_aux_transfer; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1429 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1430 | { |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1431 | 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] | 1432 | 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] | 1433 | |
Navare, Manasi D | 577c543 | 2016-09-27 16:36:53 -0700 | [diff] [blame] | 1434 | if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) || |
| 1435 | IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9)) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1436 | return true; |
| 1437 | else |
| 1438 | return false; |
| 1439 | } |
| 1440 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 1441 | static void |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1442 | intel_dp_set_clock(struct intel_encoder *encoder, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1443 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1444 | { |
| 1445 | struct drm_device *dev = encoder->base.dev; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1446 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1447 | const struct dp_link_dpll *divisor = NULL; |
| 1448 | int i, count = 0; |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1449 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 1450 | if (IS_G4X(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1451 | divisor = gen4_dpll; |
| 1452 | count = ARRAY_SIZE(gen4_dpll); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1453 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1454 | divisor = pch_dpll; |
| 1455 | count = ARRAY_SIZE(pch_dpll); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1456 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1457 | divisor = chv_dpll; |
| 1458 | count = ARRAY_SIZE(chv_dpll); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 1459 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 1460 | divisor = vlv_dpll; |
| 1461 | count = ARRAY_SIZE(vlv_dpll); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1462 | } |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1463 | |
| 1464 | if (divisor && count) { |
| 1465 | for (i = 0; i < count; i++) { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1466 | if (pipe_config->port_clock == divisor[i].clock) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1467 | pipe_config->dpll = divisor[i].dpll; |
| 1468 | pipe_config->clock_set = true; |
| 1469 | break; |
| 1470 | } |
| 1471 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1475 | static void snprintf_int_array(char *str, size_t len, |
| 1476 | const int *array, int nelem) |
| 1477 | { |
| 1478 | int i; |
| 1479 | |
| 1480 | str[0] = '\0'; |
| 1481 | |
| 1482 | for (i = 0; i < nelem; i++) { |
Jani Nikula | b2f505b | 2015-05-18 16:01:45 +0300 | [diff] [blame] | 1483 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1484 | if (r >= len) |
| 1485 | return; |
| 1486 | str += r; |
| 1487 | len -= r; |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | static void intel_dp_print_rates(struct intel_dp *intel_dp) |
| 1492 | { |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1493 | const int *source_rates, *sink_rates; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1494 | int source_len, sink_len, common_len; |
| 1495 | int common_rates[DP_MAX_SUPPORTED_RATES]; |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1496 | char str[128]; /* FIXME: too big for stack? */ |
| 1497 | |
| 1498 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 1499 | return; |
| 1500 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1501 | source_len = intel_dp_source_rates(intel_dp, &source_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1502 | snprintf_int_array(str, sizeof(str), source_rates, source_len); |
| 1503 | DRM_DEBUG_KMS("source rates: %s\n", str); |
| 1504 | |
| 1505 | sink_len = intel_dp_sink_rates(intel_dp, &sink_rates); |
| 1506 | snprintf_int_array(str, sizeof(str), sink_rates, sink_len); |
| 1507 | DRM_DEBUG_KMS("sink rates: %s\n", str); |
| 1508 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1509 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
| 1510 | snprintf_int_array(str, sizeof(str), common_rates, common_len); |
| 1511 | DRM_DEBUG_KMS("common rates: %s\n", str); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
Imre Deak | 489375c | 2016-10-24 19:33:31 +0300 | [diff] [blame] | 1514 | bool |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1515 | __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] | 1516 | { |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1517 | u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI : |
| 1518 | DP_SINK_OUI; |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1519 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1520 | return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) == |
| 1521 | sizeof(*desc); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1522 | } |
| 1523 | |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 1524 | bool intel_dp_read_desc(struct intel_dp *intel_dp) |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1525 | { |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1526 | struct intel_dp_desc *desc = &intel_dp->desc; |
| 1527 | bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & |
| 1528 | DP_OUI_SUPPORT; |
| 1529 | int dev_id_len; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1530 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1531 | if (!__intel_dp_read_desc(intel_dp, desc)) |
| 1532 | return false; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1533 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1534 | dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id)); |
| 1535 | DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n", |
| 1536 | drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink", |
| 1537 | (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)", |
| 1538 | dev_id_len, desc->device_id, |
| 1539 | desc->hw_rev >> 4, desc->hw_rev & 0xf, |
| 1540 | desc->sw_major_rev, desc->sw_minor_rev); |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1541 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1542 | return true; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1543 | } |
| 1544 | |
Ville Syrjälä | f4896f1 | 2015-03-12 17:10:27 +0200 | [diff] [blame] | 1545 | static int rate_to_index(int find, const int *rates) |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1546 | { |
| 1547 | int i = 0; |
| 1548 | |
| 1549 | for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i) |
| 1550 | if (find == rates[i]) |
| 1551 | break; |
| 1552 | |
| 1553 | return i; |
| 1554 | } |
| 1555 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1556 | int |
| 1557 | intel_dp_max_link_rate(struct intel_dp *intel_dp) |
| 1558 | { |
| 1559 | int rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 1560 | int len; |
| 1561 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1562 | len = intel_dp_common_rates(intel_dp, rates); |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1563 | if (WARN_ON(len <= 0)) |
| 1564 | return 162000; |
| 1565 | |
Ville Syrjälä | 1354f73 | 2016-07-28 17:50:45 +0300 | [diff] [blame] | 1566 | return rates[len - 1]; |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1567 | } |
| 1568 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1569 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
| 1570 | { |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1571 | return rate_to_index(rate, intel_dp->sink_rates); |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 1574 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
| 1575 | uint8_t *link_bw, uint8_t *rate_select) |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1576 | { |
| 1577 | if (intel_dp->num_sink_rates) { |
| 1578 | *link_bw = 0; |
| 1579 | *rate_select = |
| 1580 | intel_dp_rate_select(intel_dp, port_clock); |
| 1581 | } else { |
| 1582 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); |
| 1583 | *rate_select = 0; |
| 1584 | } |
| 1585 | } |
| 1586 | |
Jani Nikula | f580bea | 2016-09-15 16:28:52 +0300 | [diff] [blame] | 1587 | static int intel_dp_compute_bpp(struct intel_dp *intel_dp, |
| 1588 | struct intel_crtc_state *pipe_config) |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1589 | { |
| 1590 | int bpp, bpc; |
| 1591 | |
| 1592 | bpp = pipe_config->pipe_bpp; |
| 1593 | bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports); |
| 1594 | |
| 1595 | if (bpc > 0) |
| 1596 | bpp = min(bpp, 3*bpc); |
| 1597 | |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 1598 | /* For DP Compliance we override the computed bpp for the pipe */ |
| 1599 | if (intel_dp->compliance.test_data.bpc != 0) { |
| 1600 | pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc; |
| 1601 | pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3; |
| 1602 | DRM_DEBUG_KMS("Setting pipe_bpp to %d\n", |
| 1603 | pipe_config->pipe_bpp); |
| 1604 | } |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1605 | return bpp; |
| 1606 | } |
| 1607 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1608 | bool |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1609 | intel_dp_compute_config(struct intel_encoder *encoder, |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 1610 | struct intel_crtc_state *pipe_config, |
| 1611 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1612 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1613 | 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] | 1614 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1615 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1616 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ander Conselvan de Oliveira | 84556d5 | 2015-03-20 16:18:10 +0200 | [diff] [blame] | 1617 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1618 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1619 | int lane_count, clock; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1620 | int min_lane_count = 1; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 1621 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
Todd Previte | 06ea66b | 2014-01-20 10:19:39 -0700 | [diff] [blame] | 1622 | /* Conveniently, the link BW constants become indices with a shift...*/ |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1623 | int min_clock = 0; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1624 | int max_clock; |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1625 | int link_rate_index; |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1626 | int bpp, mode_rate; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1627 | int link_avail, link_clock; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1628 | int common_rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 1629 | int common_len; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1630 | uint8_t link_bw, rate_select; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1631 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1632 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1633 | |
| 1634 | /* No common link rates between source and sink */ |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1635 | WARN_ON(common_len <= 0); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1636 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1637 | max_clock = common_len - 1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1638 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1639 | 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] | 1640 | pipe_config->has_pch_encoder = true; |
| 1641 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1642 | pipe_config->has_drrs = false; |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 1643 | pipe_config->has_audio = intel_dp->has_audio && port != PORT_A; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1644 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1645 | if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
| 1646 | intel_fixed_panel_mode(intel_connector->panel.fixed_mode, |
| 1647 | adjusted_mode); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1648 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1649 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1650 | int ret; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 1651 | ret = skl_update_scaler_crtc(pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1652 | if (ret) |
| 1653 | return ret; |
| 1654 | } |
| 1655 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 1656 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1657 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
| 1658 | intel_connector->panel.fitting_mode); |
| 1659 | else |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 1660 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
| 1661 | intel_connector->panel.fitting_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 1662 | } |
| 1663 | |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 1664 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 1665 | return false; |
| 1666 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1667 | /* Use values requested by Compliance Test Request */ |
| 1668 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 1669 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 1670 | common_rates, |
| 1671 | intel_dp->compliance.test_link_rate); |
| 1672 | if (link_rate_index >= 0) |
| 1673 | min_clock = max_clock = link_rate_index; |
| 1674 | min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count; |
| 1675 | } |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1676 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1677 | "max bw %d pixel clock %iKHz\n", |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1678 | max_lane_count, common_rates[max_clock], |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1679 | adjusted_mode->crtc_clock); |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1680 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1681 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
| 1682 | * bpc in between. */ |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1683 | bpp = intel_dp_compute_bpp(intel_dp, pipe_config); |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1684 | if (is_edp(intel_dp)) { |
Thulasimani,Sivakumar | 22ce562 | 2015-07-31 11:05:27 +0530 | [diff] [blame] | 1685 | |
| 1686 | /* Get bpp from vbt only for panels that dont have bpp in edid */ |
| 1687 | if (intel_connector->base.display_info.bpc == 0 && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1688 | (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) { |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1689 | 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] | 1690 | dev_priv->vbt.edp.bpp); |
| 1691 | bpp = dev_priv->vbt.edp.bpp; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1692 | } |
| 1693 | |
Jani Nikula | 344c5bb | 2014-09-09 11:25:13 +0300 | [diff] [blame] | 1694 | /* |
| 1695 | * Use the maximum clock and number of lanes the eDP panel |
| 1696 | * advertizes being capable of. The panels are generally |
| 1697 | * designed to support only a single clock and lane |
| 1698 | * configuration, and typically these values correspond to the |
| 1699 | * native resolution of the panel. |
| 1700 | */ |
| 1701 | min_lane_count = max_lane_count; |
| 1702 | min_clock = max_clock; |
Imre Deak | 7984211 | 2013-07-18 17:44:13 +0300 | [diff] [blame] | 1703 | } |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1704 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1705 | for (; bpp >= 6*3; bpp -= 2*3) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1706 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
| 1707 | bpp); |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1708 | |
Dave Airlie | c693099 | 2014-07-14 11:04:39 +1000 | [diff] [blame] | 1709 | for (clock = min_clock; clock <= max_clock; clock++) { |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1710 | for (lane_count = min_lane_count; |
| 1711 | lane_count <= max_lane_count; |
| 1712 | lane_count <<= 1) { |
| 1713 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1714 | link_clock = common_rates[clock]; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1715 | link_avail = intel_dp_max_data_rate(link_clock, |
| 1716 | lane_count); |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 1717 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1718 | if (mode_rate <= link_avail) { |
| 1719 | goto found; |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | return false; |
| 1726 | |
| 1727 | found: |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1728 | if (intel_dp->color_range_auto) { |
| 1729 | /* |
| 1730 | * See: |
| 1731 | * CEA-861-E - 5.1 Default Encoding Parameters |
| 1732 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry |
| 1733 | */ |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1734 | pipe_config->limited_color_range = |
Ville Syrjälä | c8127cf0 | 2017-01-11 16:18:35 +0200 | [diff] [blame] | 1735 | bpp != 18 && |
| 1736 | drm_default_rgb_quant_range(adjusted_mode) == |
| 1737 | HDMI_QUANTIZATION_RANGE_LIMITED; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1738 | } else { |
| 1739 | pipe_config->limited_color_range = |
| 1740 | intel_dp->limited_color_range; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1741 | } |
| 1742 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1743 | pipe_config->lane_count = lane_count; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1744 | |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1745 | pipe_config->pipe_bpp = bpp; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1746 | pipe_config->port_clock = common_rates[clock]; |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1747 | |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1748 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
| 1749 | &link_bw, &rate_select); |
| 1750 | |
| 1751 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", |
| 1752 | link_bw, rate_select, pipe_config->lane_count, |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1753 | pipe_config->port_clock, bpp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1754 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
| 1755 | mode_rate, link_avail); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1756 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1757 | intel_link_compute_m_n(bpp, lane_count, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1758 | adjusted_mode->crtc_clock, |
| 1759 | pipe_config->port_clock, |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1760 | &pipe_config->dp_m_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1761 | |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1762 | if (intel_connector->panel.downclock_mode != NULL && |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 1763 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1764 | pipe_config->has_drrs = true; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1765 | intel_link_compute_m_n(bpp, lane_count, |
| 1766 | intel_connector->panel.downclock_mode->clock, |
| 1767 | pipe_config->port_clock, |
| 1768 | &pipe_config->dp_m2_n2); |
| 1769 | } |
| 1770 | |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1771 | /* |
| 1772 | * DPLL0 VCO may need to be adjusted to get the correct |
| 1773 | * clock for eDP. This will affect cdclk as well. |
| 1774 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 1775 | if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) { |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1776 | int vco; |
| 1777 | |
| 1778 | switch (pipe_config->port_clock / 2) { |
| 1779 | case 108000: |
| 1780 | case 216000: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1781 | vco = 8640000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1782 | break; |
| 1783 | default: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1784 | vco = 8100000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1785 | break; |
| 1786 | } |
| 1787 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 1788 | to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1789 | } |
| 1790 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1791 | if (!HAS_DDI(dev_priv)) |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1792 | intel_dp_set_clock(encoder, pipe_config); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1793 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1794 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1797 | 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] | 1798 | int link_rate, uint8_t lane_count, |
| 1799 | bool link_mst) |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1800 | { |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1801 | intel_dp->link_rate = link_rate; |
| 1802 | intel_dp->lane_count = lane_count; |
| 1803 | intel_dp->link_mst = link_mst; |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1804 | } |
| 1805 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1806 | static void intel_dp_prepare(struct intel_encoder *encoder, |
| 1807 | struct intel_crtc_state *pipe_config) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1808 | { |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1809 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1810 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1811 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1812 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1813 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1814 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1815 | |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1816 | intel_dp_set_link_params(intel_dp, pipe_config->port_clock, |
| 1817 | pipe_config->lane_count, |
| 1818 | intel_crtc_has_type(pipe_config, |
| 1819 | INTEL_OUTPUT_DP_MST)); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1820 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1821 | /* |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1822 | * There are four kinds of DP registers: |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1823 | * |
| 1824 | * IBX PCH |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1825 | * SNB CPU |
| 1826 | * IVB CPU |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1827 | * CPT PCH |
| 1828 | * |
| 1829 | * IBX PCH and CPU are the same for almost everything, |
| 1830 | * except that the CPU DP PLL is configured in this |
| 1831 | * register |
| 1832 | * |
| 1833 | * CPT PCH is quite different, having many bits moved |
| 1834 | * to the TRANS_DP_CTL register instead. That |
| 1835 | * configuration happens (oddly) in ironlake_pch_enable |
| 1836 | */ |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 1837 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1838 | /* Preserve the BIOS-computed detected bit. This is |
| 1839 | * supposed to be read-only. |
| 1840 | */ |
| 1841 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1842 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1843 | /* Handle DP bits in common between all three register formats */ |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1844 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1845 | intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1846 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1847 | /* Split out the IBX/CPU vs CPT settings */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1848 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1849 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1850 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1851 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1852 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1853 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1854 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
| 1855 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1856 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1857 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1858 | |
Daniel Vetter | 7c62a16 | 2013-06-01 17:16:20 +0200 | [diff] [blame] | 1859 | intel_dp->DP |= crtc->pipe << 29; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1860 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1861 | u32 trans_dp; |
| 1862 | |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1863 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1864 | |
| 1865 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 1866 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 1867 | trans_dp |= TRANS_DP_ENH_FRAMING; |
| 1868 | else |
| 1869 | trans_dp &= ~TRANS_DP_ENH_FRAMING; |
| 1870 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1871 | } else { |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 1872 | if (IS_G4X(dev_priv) && pipe_config->limited_color_range) |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1873 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1874 | |
| 1875 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1876 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1877 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1878 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1879 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
| 1880 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1881 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1882 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1883 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1884 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1885 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1886 | else if (crtc->pipe == PIPE_B) |
| 1887 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1888 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1891 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
| 1892 | #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] | 1893 | |
Paulo Zanoni | 1a5ef5b | 2013-12-19 14:29:43 -0200 | [diff] [blame] | 1894 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
| 1895 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1896 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1897 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
| 1898 | #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] | 1899 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1900 | static void intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 1901 | struct intel_dp *intel_dp); |
| 1902 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1903 | static void wait_panel_status(struct intel_dp *intel_dp, |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1904 | u32 mask, |
| 1905 | u32 value) |
| 1906 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 1907 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1908 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1909 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1910 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1911 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1912 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1913 | intel_pps_verify_state(dev_priv, intel_dp); |
| 1914 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1915 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 1916 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1917 | |
| 1918 | DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1919 | mask, value, |
| 1920 | I915_READ(pp_stat_reg), |
| 1921 | I915_READ(pp_ctrl_reg)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1922 | |
Chris Wilson | 9036ff0 | 2016-06-30 15:33:09 +0100 | [diff] [blame] | 1923 | if (intel_wait_for_register(dev_priv, |
| 1924 | pp_stat_reg, mask, value, |
| 1925 | 5000)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1926 | DRM_ERROR("Panel status timeout: status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1927 | I915_READ(pp_stat_reg), |
| 1928 | I915_READ(pp_ctrl_reg)); |
Chris Wilson | 54c136d | 2013-12-02 09:57:16 +0000 | [diff] [blame] | 1929 | |
| 1930 | DRM_DEBUG_KMS("Wait complete\n"); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1933 | static void wait_panel_on(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1934 | { |
| 1935 | DRM_DEBUG_KMS("Wait for panel power on\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1936 | wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1939 | static void wait_panel_off(struct intel_dp *intel_dp) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1940 | { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1941 | DRM_DEBUG_KMS("Wait for panel power off time\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1942 | wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1943 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1944 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1945 | static void wait_panel_power_cycle(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1946 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1947 | ktime_t panel_power_on_time; |
| 1948 | s64 panel_power_off_duration; |
| 1949 | |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1950 | DRM_DEBUG_KMS("Wait for panel power cycle\n"); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1951 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1952 | /* take the difference of currrent time and panel power off time |
| 1953 | * and then make panel wait for t11_t12 if needed. */ |
| 1954 | panel_power_on_time = ktime_get_boottime(); |
| 1955 | panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time); |
| 1956 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1957 | /* When we disable the VDD override bit last we have to do the manual |
| 1958 | * wait. */ |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1959 | if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay) |
| 1960 | wait_remaining_ms_from_jiffies(jiffies, |
| 1961 | intel_dp->panel_power_cycle_delay - panel_power_off_duration); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1962 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1963 | wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1964 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1965 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1966 | static void wait_backlight_on(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1967 | { |
| 1968 | wait_remaining_ms_from_jiffies(intel_dp->last_power_on, |
| 1969 | intel_dp->backlight_on_delay); |
| 1970 | } |
| 1971 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1972 | static void edp_wait_backlight_off(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1973 | { |
| 1974 | wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off, |
| 1975 | intel_dp->backlight_off_delay); |
| 1976 | } |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1977 | |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 1978 | /* Read the current pp_control value, unlocking the register if it |
| 1979 | * is locked |
| 1980 | */ |
| 1981 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1982 | static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 1983 | { |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1984 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1985 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1986 | u32 control; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1987 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1988 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1989 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1990 | control = I915_READ(_pp_ctrl_reg(intel_dp)); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 1991 | if (WARN_ON(!HAS_DDI(dev_priv) && |
| 1992 | (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 1993 | control &= ~PANEL_UNLOCK_MASK; |
| 1994 | control |= PANEL_UNLOCK_REGS; |
| 1995 | } |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 1996 | return control; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 1999 | /* |
| 2000 | * Must be paired with edp_panel_vdd_off(). |
| 2001 | * Must hold pps_mutex around the whole on/off sequence. |
| 2002 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2003 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 2004 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2005 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2006 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2007 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2008 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2009 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2010 | enum intel_display_power_domain power_domain; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2011 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2012 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2013 | bool need_to_disable = !intel_dp->want_panel_vdd; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2014 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2015 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2016 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2017 | if (!is_edp(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2018 | return false; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2019 | |
Egbert Eich | 2c623c1 | 2014-11-25 12:54:57 +0100 | [diff] [blame] | 2020 | cancel_delayed_work(&intel_dp->panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2021 | intel_dp->want_panel_vdd = true; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2022 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2023 | if (edp_have_panel_vdd(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2024 | return need_to_disable; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2025 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 2026 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2027 | intel_display_power_get(dev_priv, power_domain); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2028 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2029 | DRM_DEBUG_KMS("Turning eDP port %c VDD on\n", |
| 2030 | port_name(intel_dig_port->port)); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2031 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2032 | if (!edp_have_panel_power(intel_dp)) |
| 2033 | wait_panel_power_cycle(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2034 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2035 | pp = ironlake_get_pp_control(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2036 | pp |= EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2037 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2038 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 2039 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2040 | |
| 2041 | I915_WRITE(pp_ctrl_reg, pp); |
| 2042 | POSTING_READ(pp_ctrl_reg); |
| 2043 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2044 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2045 | /* |
| 2046 | * If the panel wasn't on, delay before accessing aux channel |
| 2047 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2048 | if (!edp_have_panel_power(intel_dp)) { |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2049 | DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n", |
| 2050 | port_name(intel_dig_port->port)); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2051 | msleep(intel_dp->panel_power_up_delay); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2052 | } |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2053 | |
| 2054 | return need_to_disable; |
| 2055 | } |
| 2056 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2057 | /* |
| 2058 | * Must be paired with intel_edp_panel_vdd_off() or |
| 2059 | * intel_edp_panel_off(). |
| 2060 | * Nested calls to these functions are not allowed since |
| 2061 | * we drop the lock. Caller must use some higher level |
| 2062 | * locking to prevent nested calls from other threads. |
| 2063 | */ |
Daniel Vetter | b80d6c7 | 2014-03-19 15:54:37 +0100 | [diff] [blame] | 2064 | void intel_edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2065 | { |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2066 | bool vdd; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2067 | |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2068 | if (!is_edp(intel_dp)) |
| 2069 | return; |
| 2070 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2071 | pps_lock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2072 | vdd = edp_panel_vdd_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2073 | pps_unlock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2074 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2075 | 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] | 2076 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2077 | } |
| 2078 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2079 | static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2080 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2081 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2082 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2083 | struct intel_digital_port *intel_dig_port = |
| 2084 | dp_to_dig_port(intel_dp); |
| 2085 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 2086 | enum intel_display_power_domain power_domain; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2087 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2088 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2089 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2090 | lockdep_assert_held(&dev_priv->pps_mutex); |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 2091 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2092 | WARN_ON(intel_dp->want_panel_vdd); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2093 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2094 | if (!edp_have_panel_vdd(intel_dp)) |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2095 | return; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2096 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2097 | DRM_DEBUG_KMS("Turning eDP port %c VDD off\n", |
| 2098 | port_name(intel_dig_port->port)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2099 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2100 | pp = ironlake_get_pp_control(intel_dp); |
| 2101 | pp &= ~EDP_FORCE_VDD; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2102 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2103 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
| 2104 | pp_stat_reg = _pp_stat_reg(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2105 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2106 | I915_WRITE(pp_ctrl_reg, pp); |
| 2107 | POSTING_READ(pp_ctrl_reg); |
Paulo Zanoni | 90791a5 | 2013-12-06 17:32:42 -0200 | [diff] [blame] | 2108 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2109 | /* Make sure sequencer is idle before allowing subsequent activity */ |
| 2110 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2111 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2112 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2113 | if ((pp & PANEL_POWER_ON) == 0) |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2114 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2115 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 2116 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2117 | intel_display_power_put(dev_priv, power_domain); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2120 | static void edp_panel_vdd_work(struct work_struct *__work) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2121 | { |
| 2122 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), |
| 2123 | struct intel_dp, panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2124 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2125 | pps_lock(intel_dp); |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2126 | if (!intel_dp->want_panel_vdd) |
| 2127 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2128 | pps_unlock(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2131 | static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) |
| 2132 | { |
| 2133 | unsigned long delay; |
| 2134 | |
| 2135 | /* |
| 2136 | * Queue the timer to fire a long time from now (relative to the power |
| 2137 | * down delay) to keep the panel power up across a sequence of |
| 2138 | * operations. |
| 2139 | */ |
| 2140 | delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5); |
| 2141 | schedule_delayed_work(&intel_dp->panel_vdd_work, delay); |
| 2142 | } |
| 2143 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2144 | /* |
| 2145 | * Must be paired with edp_panel_vdd_on(). |
| 2146 | * Must hold pps_mutex around the whole on/off sequence. |
| 2147 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2148 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2149 | 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] | 2150 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2151 | 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] | 2152 | |
| 2153 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2154 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2155 | if (!is_edp(intel_dp)) |
| 2156 | return; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2157 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2158 | 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] | 2159 | port_name(dp_to_dig_port(intel_dp)->port)); |
Keith Packard | f2e8b18 | 2011-11-01 20:01:35 -0700 | [diff] [blame] | 2160 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2161 | intel_dp->want_panel_vdd = false; |
| 2162 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2163 | if (sync) |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2164 | edp_panel_vdd_off_sync(intel_dp); |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2165 | else |
| 2166 | edp_panel_vdd_schedule_off(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2167 | } |
| 2168 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2169 | static void edp_panel_on(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2170 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2171 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2172 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2173 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2174 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2175 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2176 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2177 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2178 | if (!is_edp(intel_dp)) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2179 | return; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2180 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2181 | DRM_DEBUG_KMS("Turn eDP port %c panel power on\n", |
| 2182 | port_name(dp_to_dig_port(intel_dp)->port)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2183 | |
Ville Syrjälä | e7a89ac | 2014-10-16 21:30:07 +0300 | [diff] [blame] | 2184 | if (WARN(edp_have_panel_power(intel_dp), |
| 2185 | "eDP port %c panel power already on\n", |
| 2186 | port_name(dp_to_dig_port(intel_dp)->port))) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2187 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2188 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2189 | wait_panel_power_cycle(intel_dp); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2190 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2191 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2192 | pp = ironlake_get_pp_control(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2193 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2194 | /* ILK workaround: disable reset around power sequence */ |
| 2195 | pp &= ~PANEL_POWER_RESET; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2196 | I915_WRITE(pp_ctrl_reg, pp); |
| 2197 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2198 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2199 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2200 | pp |= PANEL_POWER_ON; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2201 | if (!IS_GEN5(dev_priv)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2202 | pp |= PANEL_POWER_RESET; |
| 2203 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2204 | I915_WRITE(pp_ctrl_reg, pp); |
| 2205 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2206 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2207 | wait_panel_on(intel_dp); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2208 | intel_dp->last_power_on = jiffies; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2209 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2210 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2211 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2212 | I915_WRITE(pp_ctrl_reg, pp); |
| 2213 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2214 | } |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2215 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2216 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2217 | void intel_edp_panel_on(struct intel_dp *intel_dp) |
| 2218 | { |
| 2219 | if (!is_edp(intel_dp)) |
| 2220 | return; |
| 2221 | |
| 2222 | pps_lock(intel_dp); |
| 2223 | edp_panel_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2224 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2227 | |
| 2228 | static void edp_panel_off(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2229 | { |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2230 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2231 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2232 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2233 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2234 | enum intel_display_power_domain power_domain; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [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; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2237 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2238 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2239 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2240 | if (!is_edp(intel_dp)) |
| 2241 | return; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2242 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2243 | DRM_DEBUG_KMS("Turn eDP port %c panel power off\n", |
| 2244 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2245 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2246 | WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n", |
| 2247 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2248 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2249 | pp = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 35a3855 | 2012-08-12 22:17:14 +0200 | [diff] [blame] | 2250 | /* We need to switch off panel power _and_ force vdd, for otherwise some |
| 2251 | * panels get very unhappy and cease to work. */ |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2252 | pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | |
Patrik Jakobsson | b306415 | 2014-03-04 00:42:44 +0100 | [diff] [blame] | 2253 | EDP_BLC_ENABLE); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2254 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2255 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2256 | |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2257 | intel_dp->want_panel_vdd = false; |
| 2258 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2259 | I915_WRITE(pp_ctrl_reg, pp); |
| 2260 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2261 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2262 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2263 | wait_panel_off(intel_dp); |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2264 | |
| 2265 | /* We got a reference when we enabled the VDD. */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 2266 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2267 | intel_display_power_put(dev_priv, power_domain); |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2268 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2269 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2270 | void intel_edp_panel_off(struct intel_dp *intel_dp) |
| 2271 | { |
| 2272 | if (!is_edp(intel_dp)) |
| 2273 | return; |
| 2274 | |
| 2275 | pps_lock(intel_dp); |
| 2276 | edp_panel_off(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2277 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2280 | /* Enable backlight in the panel power control. */ |
| 2281 | static void _intel_edp_backlight_on(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2282 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2283 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2284 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2285 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2286 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2287 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2288 | |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 2289 | /* |
| 2290 | * If we enable the backlight right away following a panel power |
| 2291 | * on, we may see slight flicker as the panel syncs with the eDP |
| 2292 | * link. So delay a bit to make sure the image is solid before |
| 2293 | * allowing it to appear. |
| 2294 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2295 | wait_backlight_on(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2296 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2297 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2298 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2299 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2300 | pp |= EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2301 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2302 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2303 | |
| 2304 | I915_WRITE(pp_ctrl_reg, pp); |
| 2305 | POSTING_READ(pp_ctrl_reg); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2306 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2307 | pps_unlock(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2308 | } |
| 2309 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2310 | /* Enable backlight PWM and backlight PP control. */ |
| 2311 | void intel_edp_backlight_on(struct intel_dp *intel_dp) |
| 2312 | { |
| 2313 | if (!is_edp(intel_dp)) |
| 2314 | return; |
| 2315 | |
| 2316 | DRM_DEBUG_KMS("\n"); |
| 2317 | |
| 2318 | intel_panel_enable_backlight(intel_dp->attached_connector); |
| 2319 | _intel_edp_backlight_on(intel_dp); |
| 2320 | } |
| 2321 | |
| 2322 | /* Disable backlight in the panel power control. */ |
| 2323 | static void _intel_edp_backlight_off(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2324 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2325 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2326 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2327 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2328 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2329 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2330 | if (!is_edp(intel_dp)) |
| 2331 | return; |
| 2332 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2333 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2334 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2335 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2336 | pp &= ~EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2337 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2338 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2339 | |
| 2340 | I915_WRITE(pp_ctrl_reg, pp); |
| 2341 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2342 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2343 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2344 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2345 | intel_dp->last_backlight_off = jiffies; |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2346 | edp_wait_backlight_off(intel_dp); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2347 | } |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2348 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2349 | /* Disable backlight PP control and backlight PWM. */ |
| 2350 | void intel_edp_backlight_off(struct intel_dp *intel_dp) |
| 2351 | { |
| 2352 | if (!is_edp(intel_dp)) |
| 2353 | return; |
| 2354 | |
| 2355 | DRM_DEBUG_KMS("\n"); |
| 2356 | |
| 2357 | _intel_edp_backlight_off(intel_dp); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2358 | intel_panel_disable_backlight(intel_dp->attached_connector); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2359 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2360 | |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2361 | /* |
| 2362 | * Hook for controlling the panel power control backlight through the bl_power |
| 2363 | * sysfs attribute. Take care to handle multiple calls. |
| 2364 | */ |
| 2365 | static void intel_edp_backlight_power(struct intel_connector *connector, |
| 2366 | bool enable) |
| 2367 | { |
| 2368 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2369 | bool is_enabled; |
| 2370 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2371 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2372 | is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2373 | pps_unlock(intel_dp); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2374 | |
| 2375 | if (is_enabled == enable) |
| 2376 | return; |
| 2377 | |
Jani Nikula | 23ba937 | 2014-08-27 14:08:43 +0300 | [diff] [blame] | 2378 | DRM_DEBUG_KMS("panel power control backlight %s\n", |
| 2379 | enable ? "enable" : "disable"); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2380 | |
| 2381 | if (enable) |
| 2382 | _intel_edp_backlight_on(intel_dp); |
| 2383 | else |
| 2384 | _intel_edp_backlight_off(intel_dp); |
| 2385 | } |
| 2386 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2387 | static void assert_dp_port(struct intel_dp *intel_dp, bool state) |
| 2388 | { |
| 2389 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 2390 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 2391 | bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN; |
| 2392 | |
| 2393 | I915_STATE_WARN(cur_state != state, |
| 2394 | "DP port %c state assertion failure (expected %s, current %s)\n", |
| 2395 | port_name(dig_port->port), |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2396 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2397 | } |
| 2398 | #define assert_dp_port_disabled(d) assert_dp_port((d), false) |
| 2399 | |
| 2400 | static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state) |
| 2401 | { |
| 2402 | bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE; |
| 2403 | |
| 2404 | I915_STATE_WARN(cur_state != state, |
| 2405 | "eDP PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2406 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2407 | } |
| 2408 | #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) |
| 2409 | #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) |
| 2410 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2411 | static void ironlake_edp_pll_on(struct intel_dp *intel_dp, |
| 2412 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2413 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2414 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2415 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2416 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2417 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2418 | assert_dp_port_disabled(intel_dp); |
| 2419 | assert_edp_pll_disabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2420 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2421 | DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n", |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2422 | pipe_config->port_clock); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2423 | |
| 2424 | intel_dp->DP &= ~DP_PLL_FREQ_MASK; |
| 2425 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2426 | if (pipe_config->port_clock == 162000) |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2427 | intel_dp->DP |= DP_PLL_FREQ_162MHZ; |
| 2428 | else |
| 2429 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
| 2430 | |
| 2431 | I915_WRITE(DP_A, intel_dp->DP); |
| 2432 | POSTING_READ(DP_A); |
| 2433 | udelay(500); |
| 2434 | |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2435 | /* |
| 2436 | * [DevILK] Work around required when enabling DP PLL |
| 2437 | * while a pipe is enabled going to FDI: |
| 2438 | * 1. Wait for the start of vertical blank on the enabled pipe going to FDI |
| 2439 | * 2. Program DP PLL enable |
| 2440 | */ |
| 2441 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 2442 | intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe); |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2443 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2444 | intel_dp->DP |= DP_PLL_ENABLE; |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2445 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2446 | I915_WRITE(DP_A, intel_dp->DP); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 2447 | POSTING_READ(DP_A); |
| 2448 | udelay(200); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2451 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2452 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2453 | 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] | 2454 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
| 2455 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2456 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2457 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2458 | assert_dp_port_disabled(intel_dp); |
| 2459 | assert_edp_pll_enabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2460 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2461 | DRM_DEBUG_KMS("disabling eDP PLL\n"); |
| 2462 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2463 | intel_dp->DP &= ~DP_PLL_ENABLE; |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2464 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2465 | I915_WRITE(DP_A, intel_dp->DP); |
Chris Wilson | 1af5fa1 | 2010-09-08 21:07:28 +0100 | [diff] [blame] | 2466 | POSTING_READ(DP_A); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2467 | udelay(200); |
| 2468 | } |
| 2469 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2470 | /* If the sink supports it, try to set the power state appropriately */ |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2471 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2472 | { |
| 2473 | int ret, i; |
| 2474 | |
| 2475 | /* Should have a valid DPCD by this point */ |
| 2476 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 2477 | return; |
| 2478 | |
| 2479 | if (mode != DRM_MODE_DPMS_ON) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2480 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2481 | DP_SET_POWER_D3); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2482 | } else { |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2483 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
| 2484 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2485 | /* |
| 2486 | * When turning on, we need to retry for 1ms to give the sink |
| 2487 | * time to wake up. |
| 2488 | */ |
| 2489 | for (i = 0; i < 3; i++) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2490 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2491 | DP_SET_POWER_D0); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2492 | if (ret == 1) |
| 2493 | break; |
| 2494 | msleep(1); |
| 2495 | } |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2496 | |
| 2497 | if (ret == 1 && lspcon->active) |
| 2498 | lspcon_wait_pcon_mode(lspcon); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2499 | } |
Jani Nikula | f9cac72 | 2014-09-02 16:33:52 +0300 | [diff] [blame] | 2500 | |
| 2501 | if (ret != 1) |
| 2502 | DRM_DEBUG_KMS("failed to %s sink power state\n", |
| 2503 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2506 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
| 2507 | enum pipe *pipe) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2508 | { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2509 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 2510 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2511 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2512 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2513 | enum intel_display_power_domain power_domain; |
| 2514 | u32 tmp; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2515 | bool ret; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2516 | |
| 2517 | power_domain = intel_display_port_power_domain(encoder); |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2518 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2519 | return false; |
| 2520 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2521 | ret = false; |
| 2522 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2523 | tmp = I915_READ(intel_dp->output_reg); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2524 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2525 | if (!(tmp & DP_PORT_EN)) |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2526 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2527 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2528 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2529 | *pipe = PORT_TO_PIPE_CPT(tmp); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2530 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2531 | enum pipe p; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2532 | |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2533 | for_each_pipe(dev_priv, p) { |
| 2534 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); |
| 2535 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { |
| 2536 | *pipe = p; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2537 | ret = true; |
| 2538 | |
| 2539 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2540 | } |
| 2541 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2542 | |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2543 | 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] | 2544 | i915_mmio_reg_offset(intel_dp->output_reg)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2545 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2546 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); |
| 2547 | } else { |
| 2548 | *pipe = PORT_TO_PIPE(tmp); |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2549 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2550 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2551 | ret = true; |
| 2552 | |
| 2553 | out: |
| 2554 | intel_display_power_put(dev_priv, power_domain); |
| 2555 | |
| 2556 | return ret; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2557 | } |
| 2558 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2559 | static void intel_dp_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2560 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2561 | { |
| 2562 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2563 | u32 tmp, flags = 0; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2564 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2565 | struct drm_i915_private *dev_priv = to_i915(dev); |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2566 | enum port port = dp_to_dig_port(intel_dp)->port; |
| 2567 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2568 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2569 | tmp = I915_READ(intel_dp->output_reg); |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 2570 | |
| 2571 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2572 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2573 | if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2574 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 2575 | |
| 2576 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2577 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2578 | else |
| 2579 | flags |= DRM_MODE_FLAG_NHSYNC; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2580 | |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2581 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2582 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2583 | else |
| 2584 | flags |= DRM_MODE_FLAG_NVSYNC; |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2585 | } else { |
| 2586 | if (tmp & DP_SYNC_HS_HIGH) |
| 2587 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2588 | else |
| 2589 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2590 | |
| 2591 | if (tmp & DP_SYNC_VS_HIGH) |
| 2592 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2593 | else |
| 2594 | flags |= DRM_MODE_FLAG_NVSYNC; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2595 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2596 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2597 | pipe_config->base.adjusted_mode.flags |= flags; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2598 | |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 2599 | if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235) |
Ville Syrjälä | 8c875fc | 2014-09-12 15:46:29 +0300 | [diff] [blame] | 2600 | pipe_config->limited_color_range = true; |
| 2601 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2602 | pipe_config->lane_count = |
| 2603 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; |
| 2604 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2605 | intel_dp_get_m_n(crtc, pipe_config); |
| 2606 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2607 | if (port == PORT_A) { |
Ville Syrjälä | b377e0d | 2015-10-29 21:25:59 +0200 | [diff] [blame] | 2608 | 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] | 2609 | pipe_config->port_clock = 162000; |
| 2610 | else |
| 2611 | pipe_config->port_clock = 270000; |
| 2612 | } |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2613 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 2614 | pipe_config->base.adjusted_mode.crtc_clock = |
| 2615 | intel_dotclock_calculate(pipe_config->port_clock, |
| 2616 | &pipe_config->dp_m_n); |
Daniel Vetter | 7f16e5c | 2013-11-04 16:28:47 +0100 | [diff] [blame] | 2617 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2618 | if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp && |
| 2619 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2620 | /* |
| 2621 | * This is a big fat ugly hack. |
| 2622 | * |
| 2623 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2624 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2625 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2626 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2627 | * max, not what it tells us to use. |
| 2628 | * |
| 2629 | * Note: This will still be broken if the eDP panel is not lit |
| 2630 | * up by the BIOS, and thus we can't get the mode at module |
| 2631 | * load. |
| 2632 | */ |
| 2633 | 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] | 2634 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2635 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2636 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2639 | static void intel_disable_dp(struct intel_encoder *encoder, |
| 2640 | struct intel_crtc_state *old_crtc_state, |
| 2641 | struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2642 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2643 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2644 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2645 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2646 | if (old_crtc_state->has_audio) |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2647 | intel_audio_codec_disable(encoder); |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2648 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2649 | if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv)) |
Rodrigo Vivi | b32c6f4 | 2014-11-20 03:44:37 -0800 | [diff] [blame] | 2650 | intel_psr_disable(intel_dp); |
| 2651 | |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2652 | /* Make sure the panel is off before trying to change the mode. But also |
| 2653 | * ensure that we have vdd while we switch off the panel. */ |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2654 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2655 | intel_edp_backlight_off(intel_dp); |
Jani Nikula | fdbc3b1 | 2013-11-12 17:10:13 +0200 | [diff] [blame] | 2656 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2657 | intel_edp_panel_off(intel_dp); |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2658 | |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2659 | /* disable the port before the pipe on g4x */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2660 | if (INTEL_GEN(dev_priv) < 5) |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2661 | intel_dp_link_down(intel_dp); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2664 | static void ilk_post_disable_dp(struct intel_encoder *encoder, |
| 2665 | struct intel_crtc_state *old_crtc_state, |
| 2666 | struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2667 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2668 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | 982a386 | 2013-05-23 19:39:40 +0300 | [diff] [blame] | 2669 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2670 | |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2671 | intel_dp_link_down(intel_dp); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2672 | |
| 2673 | /* Only ilk+ has port A */ |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2674 | if (port == PORT_A) |
| 2675 | ironlake_edp_pll_off(intel_dp); |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2676 | } |
| 2677 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2678 | static void vlv_post_disable_dp(struct intel_encoder *encoder, |
| 2679 | struct intel_crtc_state *old_crtc_state, |
| 2680 | struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2681 | { |
| 2682 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2683 | |
| 2684 | intel_dp_link_down(intel_dp); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2685 | } |
| 2686 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2687 | static void chv_post_disable_dp(struct intel_encoder *encoder, |
| 2688 | struct intel_crtc_state *old_crtc_state, |
| 2689 | struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2690 | { |
| 2691 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2692 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2693 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2694 | |
| 2695 | intel_dp_link_down(intel_dp); |
| 2696 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2697 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2698 | |
Ville Syrjälä | a8f327f | 2015-07-09 20:14:11 +0300 | [diff] [blame] | 2699 | /* Assert data lane reset */ |
| 2700 | chv_data_lane_soft_reset(encoder, true); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2701 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2702 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2703 | } |
| 2704 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2705 | static void |
| 2706 | _intel_dp_set_link_train(struct intel_dp *intel_dp, |
| 2707 | uint32_t *DP, |
| 2708 | uint8_t dp_train_pat) |
| 2709 | { |
| 2710 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2711 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2712 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2713 | enum port port = intel_dig_port->port; |
| 2714 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2715 | if (dp_train_pat & DP_TRAINING_PATTERN_MASK) |
| 2716 | DRM_DEBUG_KMS("Using DP training pattern TPS%d\n", |
| 2717 | dp_train_pat & DP_TRAINING_PATTERN_MASK); |
| 2718 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 2719 | if (HAS_DDI(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2720 | uint32_t temp = I915_READ(DP_TP_CTL(port)); |
| 2721 | |
| 2722 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) |
| 2723 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2724 | else |
| 2725 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2726 | |
| 2727 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 2728 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2729 | case DP_TRAINING_PATTERN_DISABLE: |
| 2730 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; |
| 2731 | |
| 2732 | break; |
| 2733 | case DP_TRAINING_PATTERN_1: |
| 2734 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2735 | break; |
| 2736 | case DP_TRAINING_PATTERN_2: |
| 2737 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; |
| 2738 | break; |
| 2739 | case DP_TRAINING_PATTERN_3: |
| 2740 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; |
| 2741 | break; |
| 2742 | } |
| 2743 | I915_WRITE(DP_TP_CTL(port), temp); |
| 2744 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2745 | } else if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2746 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2747 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 2748 | |
| 2749 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2750 | case DP_TRAINING_PATTERN_DISABLE: |
| 2751 | *DP |= DP_LINK_TRAIN_OFF_CPT; |
| 2752 | break; |
| 2753 | case DP_TRAINING_PATTERN_1: |
| 2754 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; |
| 2755 | break; |
| 2756 | case DP_TRAINING_PATTERN_2: |
| 2757 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2758 | break; |
| 2759 | case DP_TRAINING_PATTERN_3: |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2760 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2761 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2762 | break; |
| 2763 | } |
| 2764 | |
| 2765 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2766 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2767 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 2768 | else |
| 2769 | *DP &= ~DP_LINK_TRAIN_MASK; |
| 2770 | |
| 2771 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2772 | case DP_TRAINING_PATTERN_DISABLE: |
| 2773 | *DP |= DP_LINK_TRAIN_OFF; |
| 2774 | break; |
| 2775 | case DP_TRAINING_PATTERN_1: |
| 2776 | *DP |= DP_LINK_TRAIN_PAT_1; |
| 2777 | break; |
| 2778 | case DP_TRAINING_PATTERN_2: |
| 2779 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2780 | break; |
| 2781 | case DP_TRAINING_PATTERN_3: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2782 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2783 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; |
| 2784 | } else { |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2785 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2786 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2787 | } |
| 2788 | break; |
| 2789 | } |
| 2790 | } |
| 2791 | } |
| 2792 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2793 | static void intel_dp_enable_port(struct intel_dp *intel_dp, |
| 2794 | struct intel_crtc_state *old_crtc_state) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2795 | { |
| 2796 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2797 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2798 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2799 | /* enable with pattern 1 (as per spec) */ |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2800 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2801 | 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] | 2802 | |
| 2803 | /* |
| 2804 | * Magic for VLV/CHV. We _must_ first set up the register |
| 2805 | * without actually enabling the port, and then do another |
| 2806 | * write to enable the port. Otherwise link training will |
| 2807 | * fail when the power sequencer is freshly used for this port. |
| 2808 | */ |
| 2809 | intel_dp->DP |= DP_PORT_EN; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2810 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2811 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2812 | |
| 2813 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 2814 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2815 | } |
| 2816 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2817 | static void intel_enable_dp(struct intel_encoder *encoder, |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2818 | struct intel_crtc_state *pipe_config, |
| 2819 | struct drm_connector_state *conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2820 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2821 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2822 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2823 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2824 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2825 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2826 | enum pipe pipe = crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2827 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 2828 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
| 2829 | return; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2830 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2831 | pps_lock(intel_dp); |
| 2832 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2833 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2834 | vlv_init_panel_power_sequencer(intel_dp); |
| 2835 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2836 | intel_dp_enable_port(intel_dp, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2837 | |
| 2838 | edp_panel_vdd_on(intel_dp); |
| 2839 | edp_panel_on(intel_dp); |
| 2840 | edp_panel_vdd_off(intel_dp, true); |
| 2841 | |
| 2842 | pps_unlock(intel_dp); |
| 2843 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2844 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2845 | unsigned int lane_mask = 0x0; |
| 2846 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2847 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2848 | lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2849 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 2850 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
| 2851 | lane_mask); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2852 | } |
Ville Syrjälä | 61234fa | 2014-10-16 21:27:34 +0300 | [diff] [blame] | 2853 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2854 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 2855 | intel_dp_start_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2856 | intel_dp_stop_link_train(intel_dp); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2857 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2858 | if (pipe_config->has_audio) { |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2859 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2860 | pipe_name(pipe)); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2861 | intel_audio_codec_enable(encoder, pipe_config, conn_state); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2862 | } |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2863 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2864 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2865 | static void g4x_enable_dp(struct intel_encoder *encoder, |
| 2866 | struct intel_crtc_state *pipe_config, |
| 2867 | struct drm_connector_state *conn_state) |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 2868 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2869 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2870 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2871 | intel_enable_dp(encoder, pipe_config, conn_state); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2872 | intel_edp_backlight_on(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2873 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2874 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2875 | static void vlv_enable_dp(struct intel_encoder *encoder, |
| 2876 | struct intel_crtc_state *pipe_config, |
| 2877 | struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2878 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2879 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2880 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2881 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | b32c6f4 | 2014-11-20 03:44:37 -0800 | [diff] [blame] | 2882 | intel_psr_enable(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2885 | static void g4x_pre_enable_dp(struct intel_encoder *encoder, |
| 2886 | struct intel_crtc_state *pipe_config, |
| 2887 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2888 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2889 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2890 | enum port port = dp_to_dig_port(intel_dp)->port; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2891 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2892 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 2893 | |
Daniel Vetter | d41f1ef | 2014-04-24 23:54:53 +0200 | [diff] [blame] | 2894 | /* Only ilk+ has port A */ |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2895 | if (port == PORT_A) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2896 | ironlake_edp_pll_on(intel_dp, pipe_config); |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2897 | } |
| 2898 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2899 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
| 2900 | { |
| 2901 | 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] | 2902 | 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] | 2903 | enum pipe pipe = intel_dp->pps_pipe; |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 2904 | i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2905 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2906 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 2907 | |
Ville Syrjälä | d158694 | 2017-02-08 19:52:54 +0200 | [diff] [blame] | 2908 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 2909 | return; |
| 2910 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2911 | edp_panel_vdd_off_sync(intel_dp); |
| 2912 | |
| 2913 | /* |
| 2914 | * VLV seems to get confused when multiple power seqeuencers |
| 2915 | * have the same port selected (even if only one has power/vdd |
| 2916 | * enabled). The failure manifests as vlv_wait_port_ready() failing |
| 2917 | * CHV on the other hand doesn't seem to mind having the same port |
| 2918 | * selected in multiple power seqeuencers, but let's clear the |
| 2919 | * port select always when logically disconnecting a power sequencer |
| 2920 | * from a port. |
| 2921 | */ |
| 2922 | DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n", |
| 2923 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 2924 | I915_WRITE(pp_on_reg, 0); |
| 2925 | POSTING_READ(pp_on_reg); |
| 2926 | |
| 2927 | intel_dp->pps_pipe = INVALID_PIPE; |
| 2928 | } |
| 2929 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2930 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 2931 | enum pipe pipe) |
| 2932 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2933 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2934 | struct intel_encoder *encoder; |
| 2935 | |
| 2936 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2937 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 2938 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2939 | struct intel_dp *intel_dp; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2940 | enum port port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2941 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2942 | if (encoder->type != INTEL_OUTPUT_DP && |
| 2943 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2944 | continue; |
| 2945 | |
| 2946 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2947 | port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2948 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2949 | WARN(intel_dp->active_pipe == pipe, |
| 2950 | "stealing pipe %c power sequencer from active (e)DP port %c\n", |
| 2951 | pipe_name(pipe), port_name(port)); |
| 2952 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2953 | if (intel_dp->pps_pipe != pipe) |
| 2954 | continue; |
| 2955 | |
| 2956 | 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] | 2957 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2958 | |
| 2959 | /* make sure vdd is off before we steal it */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2960 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp) |
| 2965 | { |
| 2966 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2967 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 2968 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2969 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2970 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2971 | |
| 2972 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2973 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2974 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2975 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2976 | if (intel_dp->pps_pipe != INVALID_PIPE && |
| 2977 | intel_dp->pps_pipe != crtc->pipe) { |
| 2978 | /* |
| 2979 | * If another power sequencer was being used on this |
| 2980 | * port previously make sure to turn off vdd there while |
| 2981 | * we still have control of it. |
| 2982 | */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2983 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2984 | } |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2985 | |
| 2986 | /* |
| 2987 | * We may be stealing the power |
| 2988 | * sequencer from another port. |
| 2989 | */ |
| 2990 | vlv_steal_power_sequencer(dev, crtc->pipe); |
| 2991 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2992 | intel_dp->active_pipe = crtc->pipe; |
| 2993 | |
| 2994 | if (!is_edp(intel_dp)) |
| 2995 | return; |
| 2996 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2997 | /* now it's all ours */ |
| 2998 | intel_dp->pps_pipe = crtc->pipe; |
| 2999 | |
| 3000 | DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n", |
| 3001 | pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port)); |
| 3002 | |
| 3003 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 3004 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 3005 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3006 | } |
| 3007 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3008 | static void vlv_pre_enable_dp(struct intel_encoder *encoder, |
| 3009 | struct intel_crtc_state *pipe_config, |
| 3010 | struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3011 | { |
Ander Conselvan de Oliveira | 5f68c27 | 2016-04-27 15:44:24 +0300 | [diff] [blame] | 3012 | vlv_phy_pre_encoder_enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3013 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3014 | intel_enable_dp(encoder, pipe_config, conn_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3017 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder, |
| 3018 | struct intel_crtc_state *pipe_config, |
| 3019 | struct drm_connector_state *conn_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3020 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3021 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 3022 | |
Ander Conselvan de Oliveira | 6da2e61 | 2016-04-27 15:44:23 +0300 | [diff] [blame] | 3023 | vlv_phy_pre_pll_enable(encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3026 | static void chv_pre_enable_dp(struct intel_encoder *encoder, |
| 3027 | struct intel_crtc_state *pipe_config, |
| 3028 | struct drm_connector_state *conn_state) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3029 | { |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3030 | chv_phy_pre_encoder_enable(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3031 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3032 | intel_enable_dp(encoder, pipe_config, conn_state); |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 3033 | |
| 3034 | /* Second common lane will stay alive on its own now */ |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3035 | chv_phy_release_cl2_override(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3036 | } |
| 3037 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3038 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder, |
| 3039 | struct intel_crtc_state *pipe_config, |
| 3040 | struct drm_connector_state *conn_state) |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3041 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3042 | intel_dp_prepare(encoder, pipe_config); |
Ville Syrjälä | 625695f | 2014-06-28 02:04:02 +0300 | [diff] [blame] | 3043 | |
Ander Conselvan de Oliveira | 419b1b7 | 2016-04-27 15:44:19 +0300 | [diff] [blame] | 3044 | chv_phy_pre_pll_enable(encoder); |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3045 | } |
| 3046 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3047 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder, |
| 3048 | struct intel_crtc_state *pipe_config, |
| 3049 | struct drm_connector_state *conn_state) |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3050 | { |
Ander Conselvan de Oliveira | 204970b | 2016-04-27 15:44:21 +0300 | [diff] [blame] | 3051 | chv_phy_post_pll_disable(encoder); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3052 | } |
| 3053 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3054 | /* |
| 3055 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 3056 | * link status information |
| 3057 | */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3058 | bool |
Keith Packard | 93f62da | 2011-11-01 19:45:03 -0700 | [diff] [blame] | 3059 | 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] | 3060 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3061 | return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status, |
| 3062 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3065 | static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp) |
| 3066 | { |
| 3067 | uint8_t psr_caps = 0; |
| 3068 | |
| 3069 | drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps); |
| 3070 | return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED; |
| 3071 | } |
| 3072 | |
| 3073 | static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) |
| 3074 | { |
| 3075 | uint8_t dprx = 0; |
| 3076 | |
| 3077 | drm_dp_dpcd_readb(&intel_dp->aux, |
| 3078 | DP_DPRX_FEATURE_ENUMERATION_LIST, |
| 3079 | &dprx); |
| 3080 | return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED; |
| 3081 | } |
| 3082 | |
Chris Wilson | a76f73d | 2017-01-14 10:51:13 +0000 | [diff] [blame] | 3083 | static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp) |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3084 | { |
| 3085 | uint8_t alpm_caps = 0; |
| 3086 | |
| 3087 | drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps); |
| 3088 | return alpm_caps & DP_ALPM_CAP; |
| 3089 | } |
| 3090 | |
Paulo Zanoni | 1100244 | 2014-06-13 18:45:41 -0300 | [diff] [blame] | 3091 | /* These are source-specific values. */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3092 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3093 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3094 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3095 | 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] | 3096 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3097 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 3098 | if (IS_GEN9_LP(dev_priv)) |
Vandana Kannan | 9314726 | 2014-11-18 15:45:29 +0530 | [diff] [blame] | 3099 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3100 | else if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | ffe5111 | 2017-02-23 19:49:01 +0200 | [diff] [blame^] | 3101 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3102 | return intel_ddi_dp_voltage_max(encoder); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3103 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3104 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3105 | else if (IS_GEN7(dev_priv) && port == PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3106 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3107 | else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3108 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3109 | else |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3110 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3111 | } |
| 3112 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3113 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3114 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
| 3115 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3116 | 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] | 3117 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3118 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3119 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3120 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 3121 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3122 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3123 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3124 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3125 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3126 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3127 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
| 3128 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3129 | default: |
| 3130 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
| 3131 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3132 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3133 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3134 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3135 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3136 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3137 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3138 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3139 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3140 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3141 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3142 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3143 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3144 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3145 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3146 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3147 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3148 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3149 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3150 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3151 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3152 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3153 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3154 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3155 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3156 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3157 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3158 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3159 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3160 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3161 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3162 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3163 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3164 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3165 | } |
| 3166 | } else { |
| 3167 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3168 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3169 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3170 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3171 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3172 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3173 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3174 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3175 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3176 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3177 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3181 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3182 | { |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3183 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3184 | unsigned long demph_reg_value, preemph_reg_value, |
| 3185 | uniqtranscale_reg_value; |
| 3186 | uint8_t train_set = intel_dp->train_set[0]; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3187 | |
| 3188 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3189 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3190 | preemph_reg_value = 0x0004000; |
| 3191 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3192 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3193 | demph_reg_value = 0x2B405555; |
| 3194 | uniqtranscale_reg_value = 0x552AB83A; |
| 3195 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3196 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3197 | demph_reg_value = 0x2B404040; |
| 3198 | uniqtranscale_reg_value = 0x5548B83A; |
| 3199 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3200 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3201 | demph_reg_value = 0x2B245555; |
| 3202 | uniqtranscale_reg_value = 0x5560B83A; |
| 3203 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3204 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3205 | demph_reg_value = 0x2B405555; |
| 3206 | uniqtranscale_reg_value = 0x5598DA3A; |
| 3207 | break; |
| 3208 | default: |
| 3209 | return 0; |
| 3210 | } |
| 3211 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3212 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3213 | preemph_reg_value = 0x0002000; |
| 3214 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3215 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3216 | demph_reg_value = 0x2B404040; |
| 3217 | uniqtranscale_reg_value = 0x5552B83A; |
| 3218 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3219 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3220 | demph_reg_value = 0x2B404848; |
| 3221 | uniqtranscale_reg_value = 0x5580B83A; |
| 3222 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3223 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3224 | demph_reg_value = 0x2B404040; |
| 3225 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3226 | break; |
| 3227 | default: |
| 3228 | return 0; |
| 3229 | } |
| 3230 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3231 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3232 | preemph_reg_value = 0x0000000; |
| 3233 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3234 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3235 | demph_reg_value = 0x2B305555; |
| 3236 | uniqtranscale_reg_value = 0x5570B83A; |
| 3237 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3238 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3239 | demph_reg_value = 0x2B2B4040; |
| 3240 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3241 | break; |
| 3242 | default: |
| 3243 | return 0; |
| 3244 | } |
| 3245 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3246 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3247 | preemph_reg_value = 0x0006000; |
| 3248 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3249 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3250 | demph_reg_value = 0x1B405555; |
| 3251 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3252 | break; |
| 3253 | default: |
| 3254 | return 0; |
| 3255 | } |
| 3256 | break; |
| 3257 | default: |
| 3258 | return 0; |
| 3259 | } |
| 3260 | |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3261 | vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value, |
| 3262 | uniqtranscale_reg_value, 0); |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3263 | |
| 3264 | return 0; |
| 3265 | } |
| 3266 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3267 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3268 | { |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3269 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3270 | u32 deemph_reg_value, margin_reg_value; |
| 3271 | bool uniq_trans_scale = false; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3272 | uint8_t train_set = intel_dp->train_set[0]; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3273 | |
| 3274 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3275 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3276 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3277 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3278 | deemph_reg_value = 128; |
| 3279 | margin_reg_value = 52; |
| 3280 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3281 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3282 | deemph_reg_value = 128; |
| 3283 | margin_reg_value = 77; |
| 3284 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3285 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3286 | deemph_reg_value = 128; |
| 3287 | margin_reg_value = 102; |
| 3288 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3289 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3290 | deemph_reg_value = 128; |
| 3291 | margin_reg_value = 154; |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3292 | uniq_trans_scale = true; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3293 | break; |
| 3294 | default: |
| 3295 | return 0; |
| 3296 | } |
| 3297 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3298 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3299 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3300 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3301 | deemph_reg_value = 85; |
| 3302 | margin_reg_value = 78; |
| 3303 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3304 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3305 | deemph_reg_value = 85; |
| 3306 | margin_reg_value = 116; |
| 3307 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3308 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3309 | deemph_reg_value = 85; |
| 3310 | margin_reg_value = 154; |
| 3311 | break; |
| 3312 | default: |
| 3313 | return 0; |
| 3314 | } |
| 3315 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3316 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3317 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3318 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3319 | deemph_reg_value = 64; |
| 3320 | margin_reg_value = 104; |
| 3321 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3322 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3323 | deemph_reg_value = 64; |
| 3324 | margin_reg_value = 154; |
| 3325 | break; |
| 3326 | default: |
| 3327 | return 0; |
| 3328 | } |
| 3329 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3330 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3331 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3332 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3333 | deemph_reg_value = 43; |
| 3334 | margin_reg_value = 154; |
| 3335 | break; |
| 3336 | default: |
| 3337 | return 0; |
| 3338 | } |
| 3339 | break; |
| 3340 | default: |
| 3341 | return 0; |
| 3342 | } |
| 3343 | |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3344 | chv_set_phy_signal_level(encoder, deemph_reg_value, |
| 3345 | margin_reg_value, uniq_trans_scale); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3346 | |
| 3347 | return 0; |
| 3348 | } |
| 3349 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3350 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3351 | gen4_signal_levels(uint8_t train_set) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3352 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3353 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3354 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3355 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3356 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3357 | default: |
| 3358 | signal_levels |= DP_VOLTAGE_0_4; |
| 3359 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3360 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3361 | signal_levels |= DP_VOLTAGE_0_6; |
| 3362 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3363 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3364 | signal_levels |= DP_VOLTAGE_0_8; |
| 3365 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3366 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3367 | signal_levels |= DP_VOLTAGE_1_2; |
| 3368 | break; |
| 3369 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3370 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3371 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3372 | default: |
| 3373 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 3374 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3375 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3376 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 3377 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3378 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3379 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 3380 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3381 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3382 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 3383 | break; |
| 3384 | } |
| 3385 | return signal_levels; |
| 3386 | } |
| 3387 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3388 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 3389 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3390 | gen6_edp_signal_levels(uint8_t train_set) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3391 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3392 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3393 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3394 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3395 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3396 | 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] | 3397 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3398 | 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] | 3399 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3400 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 3401 | 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] | 3402 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3403 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 3404 | 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] | 3405 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3406 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3407 | 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] | 3408 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3409 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3410 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3411 | "0x%x\n", signal_levels); |
| 3412 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3416 | /* Gen7's DP voltage swing and pre-emphasis control */ |
| 3417 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3418 | gen7_edp_signal_levels(uint8_t train_set) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3419 | { |
| 3420 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3421 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3422 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3423 | 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] | 3424 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3425 | 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] | 3426 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3427 | 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] | 3428 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
| 3429 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3430 | 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] | 3431 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3432 | 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] | 3433 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
| 3434 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3435 | 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] | 3436 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3437 | 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] | 3438 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
| 3439 | |
| 3440 | default: |
| 3441 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3442 | "0x%x\n", signal_levels); |
| 3443 | return EDP_LINK_TRAIN_500MV_0DB_IVB; |
| 3444 | } |
| 3445 | } |
| 3446 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3447 | void |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3448 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3449 | { |
| 3450 | 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] | 3451 | enum port port = intel_dig_port->port; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3452 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3453 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3454 | uint32_t signal_levels, mask = 0; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3455 | uint8_t train_set = intel_dp->train_set[0]; |
| 3456 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3457 | if (HAS_DDI(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3458 | signal_levels = ddi_signal_levels(intel_dp); |
| 3459 | |
Michel Thierry | 254e093 | 2017-01-09 16:51:35 +0200 | [diff] [blame] | 3460 | if (IS_GEN9_LP(dev_priv)) |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3461 | signal_levels = 0; |
| 3462 | else |
| 3463 | mask = DDI_BUF_EMP_MASK; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3464 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3465 | signal_levels = chv_signal_levels(intel_dp); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 3466 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3467 | signal_levels = vlv_signal_levels(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3468 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3469 | signal_levels = gen7_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3470 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3471 | } else if (IS_GEN6(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3472 | signal_levels = gen6_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3473 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
| 3474 | } else { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3475 | signal_levels = gen4_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3476 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
| 3477 | } |
| 3478 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 3479 | if (mask) |
| 3480 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); |
| 3481 | |
| 3482 | DRM_DEBUG_KMS("Using vswing level %d\n", |
| 3483 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); |
| 3484 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", |
| 3485 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> |
| 3486 | DP_TRAIN_PRE_EMPHASIS_SHIFT); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3487 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3488 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3489 | |
| 3490 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 3491 | POSTING_READ(intel_dp->output_reg); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3492 | } |
| 3493 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3494 | void |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3495 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
| 3496 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3497 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 3498 | 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] | 3499 | struct drm_i915_private *dev_priv = |
| 3500 | to_i915(intel_dig_port->base.base.dev); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3501 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3502 | _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] | 3503 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3504 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3505 | POSTING_READ(intel_dp->output_reg); |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3506 | } |
| 3507 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3508 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3509 | { |
| 3510 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3511 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3512 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3513 | enum port port = intel_dig_port->port; |
| 3514 | uint32_t val; |
| 3515 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3516 | if (!HAS_DDI(dev_priv)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3517 | return; |
| 3518 | |
| 3519 | val = I915_READ(DP_TP_CTL(port)); |
| 3520 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 3521 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; |
| 3522 | I915_WRITE(DP_TP_CTL(port), val); |
| 3523 | |
| 3524 | /* |
| 3525 | * On PORT_A we can have only eDP in SST mode. There the only reason |
| 3526 | * we need to set idle transmission mode is to work around a HW issue |
| 3527 | * where we enable the pipe while not in idle link-training mode. |
| 3528 | * In this case there is requirement to wait for a minimum number of |
| 3529 | * idle patterns to be sent. |
| 3530 | */ |
| 3531 | if (port == PORT_A) |
| 3532 | return; |
| 3533 | |
Chris Wilson | a767017 | 2016-06-30 15:33:10 +0100 | [diff] [blame] | 3534 | if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port), |
| 3535 | DP_TP_STATUS_IDLE_DONE, |
| 3536 | DP_TP_STATUS_IDLE_DONE, |
| 3537 | 1)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3538 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); |
| 3539 | } |
| 3540 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3541 | static void |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3542 | intel_dp_link_down(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3543 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3544 | 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] | 3545 | 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] | 3546 | enum port port = intel_dig_port->port; |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3547 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3548 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3549 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3550 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3551 | if (WARN_ON(HAS_DDI(dev_priv))) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 3552 | return; |
| 3553 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 3554 | 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] | 3555 | return; |
| 3556 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3557 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3558 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3559 | if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3560 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3561 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3562 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3563 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3564 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | aad3d14 | 2014-06-28 02:04:25 +0300 | [diff] [blame] | 3565 | DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 3566 | else |
| 3567 | DP &= ~DP_LINK_TRAIN_MASK; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3568 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3569 | } |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3570 | I915_WRITE(intel_dp->output_reg, DP); |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 3571 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3572 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3573 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
| 3574 | I915_WRITE(intel_dp->output_reg, DP); |
| 3575 | POSTING_READ(intel_dp->output_reg); |
| 3576 | |
| 3577 | /* |
| 3578 | * HW workaround for IBX, we need to move the port |
| 3579 | * to transcoder A after disabling it to allow the |
| 3580 | * matching HDMI port to be enabled on transcoder A. |
| 3581 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3582 | 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] | 3583 | /* |
| 3584 | * We get CPU/PCH FIFO underruns on the other pipe when |
| 3585 | * doing the workaround. Sweep them under the rug. |
| 3586 | */ |
| 3587 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3588 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3589 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3590 | /* always enable with pattern 1 (as per spec) */ |
| 3591 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); |
| 3592 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; |
| 3593 | I915_WRITE(intel_dp->output_reg, DP); |
| 3594 | POSTING_READ(intel_dp->output_reg); |
| 3595 | |
| 3596 | DP &= ~DP_PORT_EN; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3597 | I915_WRITE(intel_dp->output_reg, DP); |
Daniel Vetter | 0ca0968 | 2014-11-24 16:54:11 +0100 | [diff] [blame] | 3598 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3599 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3600 | intel_wait_for_vblank_if_active(dev_priv, PIPE_A); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3601 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
| 3602 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3603 | } |
| 3604 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 3605 | msleep(intel_dp->panel_power_down_delay); |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 3606 | |
| 3607 | intel_dp->DP = DP; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3608 | |
| 3609 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 3610 | pps_lock(intel_dp); |
| 3611 | intel_dp->active_pipe = INVALID_PIPE; |
| 3612 | pps_unlock(intel_dp); |
| 3613 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3614 | } |
| 3615 | |
Imre Deak | 24e807e | 2016-10-24 19:33:28 +0300 | [diff] [blame] | 3616 | bool |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3617 | intel_dp_read_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3618 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3619 | if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, |
| 3620 | sizeof(intel_dp->dpcd)) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3621 | return false; /* aux transfer failed */ |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3622 | |
Andy Shevchenko | a8e9815 | 2014-09-01 14:12:01 +0300 | [diff] [blame] | 3623 | 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] | 3624 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3625 | return intel_dp->dpcd[DP_DPCD_REV] != 0; |
| 3626 | } |
| 3627 | |
| 3628 | static bool |
| 3629 | intel_edp_init_dpcd(struct intel_dp *intel_dp) |
| 3630 | { |
| 3631 | struct drm_i915_private *dev_priv = |
| 3632 | to_i915(dp_to_dig_port(intel_dp)->base.base.dev); |
| 3633 | |
| 3634 | /* this function is meant to be called only once */ |
| 3635 | WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0); |
| 3636 | |
| 3637 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3638 | return false; |
| 3639 | |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 3640 | intel_dp_read_desc(intel_dp); |
| 3641 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3642 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 3643 | dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
| 3644 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 3645 | |
| 3646 | /* Check if the panel supports PSR */ |
| 3647 | drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT, |
| 3648 | intel_dp->psr_dpcd, |
| 3649 | sizeof(intel_dp->psr_dpcd)); |
| 3650 | if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) { |
| 3651 | dev_priv->psr.sink_support = true; |
| 3652 | DRM_DEBUG_KMS("Detected EDP PSR Panel.\n"); |
| 3653 | } |
| 3654 | |
| 3655 | if (INTEL_GEN(dev_priv) >= 9 && |
| 3656 | (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) { |
| 3657 | uint8_t frame_sync_cap; |
| 3658 | |
| 3659 | dev_priv->psr.sink_support = true; |
| 3660 | drm_dp_dpcd_read(&intel_dp->aux, |
| 3661 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP, |
| 3662 | &frame_sync_cap, 1); |
| 3663 | dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false; |
| 3664 | /* PSR2 needs frame sync as well */ |
| 3665 | dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync; |
| 3666 | DRM_DEBUG_KMS("PSR2 %s on sink", |
| 3667 | dev_priv->psr.psr2_support ? "supported" : "not supported"); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3668 | |
| 3669 | if (dev_priv->psr.psr2_support) { |
| 3670 | dev_priv->psr.y_cord_support = |
| 3671 | intel_dp_get_y_cord_status(intel_dp); |
| 3672 | dev_priv->psr.colorimetry_support = |
| 3673 | intel_dp_get_colorimetry_status(intel_dp); |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3674 | dev_priv->psr.alpm = |
| 3675 | intel_dp_get_alpm_status(intel_dp); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3676 | } |
| 3677 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | /* Read the eDP Display control capabilities registers */ |
| 3681 | if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) && |
| 3682 | drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, |
Dan Carpenter | f7170e2 | 2016-10-13 11:55:08 +0300 | [diff] [blame] | 3683 | intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == |
| 3684 | sizeof(intel_dp->edp_dpcd)) |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3685 | DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd), |
| 3686 | intel_dp->edp_dpcd); |
| 3687 | |
| 3688 | /* Intermediate frequency support */ |
| 3689 | if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */ |
| 3690 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
| 3691 | int i; |
| 3692 | |
| 3693 | drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES, |
| 3694 | sink_rates, sizeof(sink_rates)); |
| 3695 | |
| 3696 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
| 3697 | int val = le16_to_cpu(sink_rates[i]); |
| 3698 | |
| 3699 | if (val == 0) |
| 3700 | break; |
| 3701 | |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 3702 | /* Value read multiplied by 200kHz gives the per-lane |
| 3703 | * link rate in kHz. The source rates are, however, |
| 3704 | * stored in terms of LS_Clk kHz. The full conversion |
| 3705 | * back to symbols is |
| 3706 | * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) |
| 3707 | */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3708 | intel_dp->sink_rates[i] = (val * 200) / 10; |
| 3709 | } |
| 3710 | intel_dp->num_sink_rates = i; |
| 3711 | } |
| 3712 | |
| 3713 | return true; |
| 3714 | } |
| 3715 | |
| 3716 | |
| 3717 | static bool |
| 3718 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
| 3719 | { |
| 3720 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3721 | return false; |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3722 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3723 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT, |
| 3724 | &intel_dp->sink_count, 1) < 0) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3725 | return false; |
| 3726 | |
| 3727 | /* |
| 3728 | * Sink count can change between short pulse hpd hence |
| 3729 | * a member variable in intel_dp will track any changes |
| 3730 | * between short pulse interrupts. |
| 3731 | */ |
| 3732 | intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count); |
| 3733 | |
| 3734 | /* |
| 3735 | * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that |
| 3736 | * a dongle is present but no display. Unless we require to know |
| 3737 | * if a dongle is present or not, we don't need to update |
| 3738 | * downstream port information. So, an early return here saves |
| 3739 | * time from performing other operations which are not required. |
| 3740 | */ |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 3741 | if (!is_edp(intel_dp) && !intel_dp->sink_count) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3742 | return false; |
| 3743 | |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 3744 | if (!drm_dp_is_branch(intel_dp->dpcd)) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3745 | return true; /* native DP sink */ |
| 3746 | |
| 3747 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) |
| 3748 | return true; /* no per-port downstream info */ |
| 3749 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3750 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
| 3751 | intel_dp->downstream_ports, |
| 3752 | DP_MAX_DOWNSTREAM_PORTS) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3753 | return false; /* downstream port status fetch failed */ |
| 3754 | |
| 3755 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3758 | static bool |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3759 | intel_dp_can_mst(struct intel_dp *intel_dp) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3760 | { |
| 3761 | u8 buf[1]; |
| 3762 | |
Nathan Schulte | 7cc9613 | 2016-03-15 10:14:05 -0500 | [diff] [blame] | 3763 | if (!i915.enable_dp_mst) |
| 3764 | return false; |
| 3765 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3766 | if (!intel_dp->can_mst) |
| 3767 | return false; |
| 3768 | |
| 3769 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) |
| 3770 | return false; |
| 3771 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3772 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1) |
| 3773 | return false; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3774 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3775 | return buf[0] & DP_MST_CAP; |
| 3776 | } |
| 3777 | |
| 3778 | static void |
| 3779 | intel_dp_configure_mst(struct intel_dp *intel_dp) |
| 3780 | { |
| 3781 | if (!i915.enable_dp_mst) |
| 3782 | return; |
| 3783 | |
| 3784 | if (!intel_dp->can_mst) |
| 3785 | return; |
| 3786 | |
| 3787 | intel_dp->is_mst = intel_dp_can_mst(intel_dp); |
| 3788 | |
| 3789 | if (intel_dp->is_mst) |
| 3790 | DRM_DEBUG_KMS("Sink is MST capable\n"); |
| 3791 | else |
| 3792 | DRM_DEBUG_KMS("Sink is not MST capable\n"); |
| 3793 | |
| 3794 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 3795 | intel_dp->is_mst); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3796 | } |
| 3797 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3798 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp) |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3799 | { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3800 | 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] | 3801 | 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] | 3802 | 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] | 3803 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3804 | int ret = 0; |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3805 | int count = 0; |
| 3806 | int attempts = 10; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3807 | |
| 3808 | 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] | 3809 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3810 | ret = -EIO; |
| 3811 | goto out; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3812 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3813 | |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3814 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3815 | buf & ~DP_TEST_SINK_START) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3816 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3817 | ret = -EIO; |
| 3818 | goto out; |
| 3819 | } |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3820 | |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3821 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3822 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3823 | |
| 3824 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3825 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3826 | ret = -EIO; |
| 3827 | goto out; |
| 3828 | } |
| 3829 | count = buf & DP_TEST_COUNT_MASK; |
| 3830 | } while (--attempts && count); |
| 3831 | |
| 3832 | if (attempts == 0) { |
Rodrigo Vivi | dc5a903 | 2016-01-29 14:44:59 -0800 | [diff] [blame] | 3833 | 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] | 3834 | ret = -ETIMEDOUT; |
| 3835 | } |
| 3836 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3837 | out: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3838 | hsw_enable_ips(intel_crtc); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3839 | return ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp) |
| 3843 | { |
| 3844 | 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] | 3845 | 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] | 3846 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3847 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3848 | int ret; |
| 3849 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3850 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0) |
| 3851 | return -EIO; |
| 3852 | |
| 3853 | if (!(buf & DP_TEST_CRC_SUPPORTED)) |
| 3854 | return -ENOTTY; |
| 3855 | |
| 3856 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) |
| 3857 | return -EIO; |
| 3858 | |
Rodrigo Vivi | 6d8175d | 2015-11-05 10:50:22 -0800 | [diff] [blame] | 3859 | if (buf & DP_TEST_SINK_START) { |
| 3860 | ret = intel_dp_sink_crc_stop(intel_dp); |
| 3861 | if (ret) |
| 3862 | return ret; |
| 3863 | } |
| 3864 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3865 | hsw_disable_ips(intel_crtc); |
| 3866 | |
| 3867 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
| 3868 | buf | DP_TEST_SINK_START) < 0) { |
| 3869 | hsw_enable_ips(intel_crtc); |
| 3870 | return -EIO; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3871 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3872 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3873 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3874 | return 0; |
| 3875 | } |
| 3876 | |
| 3877 | int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc) |
| 3878 | { |
| 3879 | 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] | 3880 | 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] | 3881 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3882 | u8 buf; |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3883 | int count, ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3884 | int attempts = 6; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3885 | |
| 3886 | ret = intel_dp_sink_crc_start(intel_dp); |
| 3887 | if (ret) |
| 3888 | return ret; |
| 3889 | |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3890 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3891 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3892 | |
Rodrigo Vivi | 1dda5f9 | 2014-10-01 07:32:37 -0700 | [diff] [blame] | 3893 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3894 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3895 | ret = -EIO; |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3896 | goto stop; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3897 | } |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3898 | count = buf & DP_TEST_COUNT_MASK; |
Rodrigo Vivi | aabc95d | 2015-07-23 16:35:50 -0700 | [diff] [blame] | 3899 | |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3900 | } while (--attempts && count == 0); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3901 | |
| 3902 | if (attempts == 0) { |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3903 | DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n"); |
| 3904 | ret = -ETIMEDOUT; |
| 3905 | goto stop; |
| 3906 | } |
| 3907 | |
| 3908 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) { |
| 3909 | ret = -EIO; |
| 3910 | goto stop; |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3911 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3912 | |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3913 | stop: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3914 | intel_dp_sink_crc_stop(intel_dp); |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3915 | return ret; |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3916 | } |
| 3917 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3918 | static bool |
| 3919 | intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3920 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3921 | return drm_dp_dpcd_read(&intel_dp->aux, |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 3922 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 3923 | sink_irq_vector, 1) == 1; |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3926 | static bool |
| 3927 | intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3928 | { |
| 3929 | int ret; |
| 3930 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3931 | ret = drm_dp_dpcd_read(&intel_dp->aux, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3932 | DP_SINK_COUNT_ESI, |
| 3933 | sink_irq_vector, 14); |
| 3934 | if (ret != 14) |
| 3935 | return false; |
| 3936 | |
| 3937 | return true; |
| 3938 | } |
| 3939 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3940 | 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] | 3941 | { |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 3942 | int status = 0; |
| 3943 | int min_lane_count = 1; |
| 3944 | int common_rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 3945 | int link_rate_index, test_link_rate; |
| 3946 | uint8_t test_lane_count, test_link_bw; |
| 3947 | /* (DP CTS 1.2) |
| 3948 | * 4.3.1.11 |
| 3949 | */ |
| 3950 | /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */ |
| 3951 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT, |
| 3952 | &test_lane_count); |
| 3953 | |
| 3954 | if (status <= 0) { |
| 3955 | DRM_DEBUG_KMS("Lane count read failed\n"); |
| 3956 | return DP_TEST_NAK; |
| 3957 | } |
| 3958 | test_lane_count &= DP_MAX_LANE_COUNT_MASK; |
| 3959 | /* Validate the requested lane count */ |
| 3960 | if (test_lane_count < min_lane_count || |
| 3961 | test_lane_count > intel_dp->max_sink_lane_count) |
| 3962 | return DP_TEST_NAK; |
| 3963 | |
| 3964 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE, |
| 3965 | &test_link_bw); |
| 3966 | if (status <= 0) { |
| 3967 | DRM_DEBUG_KMS("Link Rate read failed\n"); |
| 3968 | return DP_TEST_NAK; |
| 3969 | } |
| 3970 | /* Validate the requested link rate */ |
| 3971 | test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw); |
| 3972 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 3973 | common_rates, |
| 3974 | test_link_rate); |
| 3975 | if (link_rate_index < 0) |
| 3976 | return DP_TEST_NAK; |
| 3977 | |
| 3978 | intel_dp->compliance.test_lane_count = test_lane_count; |
| 3979 | intel_dp->compliance.test_link_rate = test_link_rate; |
| 3980 | |
| 3981 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp) |
| 3985 | { |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 3986 | uint8_t test_pattern; |
| 3987 | uint16_t test_misc; |
| 3988 | __be16 h_width, v_height; |
| 3989 | int status = 0; |
| 3990 | |
| 3991 | /* Read the TEST_PATTERN (DP CTS 3.1.5) */ |
| 3992 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN, |
| 3993 | &test_pattern, 1); |
| 3994 | if (status <= 0) { |
| 3995 | DRM_DEBUG_KMS("Test pattern read failed\n"); |
| 3996 | return DP_TEST_NAK; |
| 3997 | } |
| 3998 | if (test_pattern != DP_COLOR_RAMP) |
| 3999 | return DP_TEST_NAK; |
| 4000 | |
| 4001 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI, |
| 4002 | &h_width, 2); |
| 4003 | if (status <= 0) { |
| 4004 | DRM_DEBUG_KMS("H Width read failed\n"); |
| 4005 | return DP_TEST_NAK; |
| 4006 | } |
| 4007 | |
| 4008 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI, |
| 4009 | &v_height, 2); |
| 4010 | if (status <= 0) { |
| 4011 | DRM_DEBUG_KMS("V Height read failed\n"); |
| 4012 | return DP_TEST_NAK; |
| 4013 | } |
| 4014 | |
| 4015 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0, |
| 4016 | &test_misc, 1); |
| 4017 | if (status <= 0) { |
| 4018 | DRM_DEBUG_KMS("TEST MISC read failed\n"); |
| 4019 | return DP_TEST_NAK; |
| 4020 | } |
| 4021 | if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB) |
| 4022 | return DP_TEST_NAK; |
| 4023 | if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA) |
| 4024 | return DP_TEST_NAK; |
| 4025 | switch (test_misc & DP_TEST_BIT_DEPTH_MASK) { |
| 4026 | case DP_TEST_BIT_DEPTH_6: |
| 4027 | intel_dp->compliance.test_data.bpc = 6; |
| 4028 | break; |
| 4029 | case DP_TEST_BIT_DEPTH_8: |
| 4030 | intel_dp->compliance.test_data.bpc = 8; |
| 4031 | break; |
| 4032 | default: |
| 4033 | return DP_TEST_NAK; |
| 4034 | } |
| 4035 | |
| 4036 | intel_dp->compliance.test_data.video_pattern = test_pattern; |
| 4037 | intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width); |
| 4038 | intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height); |
| 4039 | /* Set test active flag here so userspace doesn't interrupt things */ |
| 4040 | intel_dp->compliance.test_active = 1; |
| 4041 | |
| 4042 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp) |
| 4046 | { |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4047 | uint8_t test_result = DP_TEST_ACK; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4048 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4049 | struct drm_connector *connector = &intel_connector->base; |
| 4050 | |
| 4051 | if (intel_connector->detect_edid == NULL || |
Daniel Vetter | ac6f2e2 | 2015-05-08 16:15:41 +0200 | [diff] [blame] | 4052 | connector->edid_corrupt || |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4053 | intel_dp->aux.i2c_defer_count > 6) { |
| 4054 | /* Check EDID read for NACKs, DEFERs and corruption |
| 4055 | * (DP CTS 1.2 Core r1.1) |
| 4056 | * 4.2.2.4 : Failed EDID read, I2C_NAK |
| 4057 | * 4.2.2.5 : Failed EDID read, I2C_DEFER |
| 4058 | * 4.2.2.6 : EDID corruption detected |
| 4059 | * Use failsafe mode for all cases |
| 4060 | */ |
| 4061 | if (intel_dp->aux.i2c_nack_count > 0 || |
| 4062 | intel_dp->aux.i2c_defer_count > 0) |
| 4063 | DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n", |
| 4064 | intel_dp->aux.i2c_nack_count, |
| 4065 | intel_dp->aux.i2c_defer_count); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4066 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4067 | } else { |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 4068 | struct edid *block = intel_connector->detect_edid; |
| 4069 | |
| 4070 | /* We have to write the checksum |
| 4071 | * of the last block read |
| 4072 | */ |
| 4073 | block += intel_connector->detect_edid->extensions; |
| 4074 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4075 | if (!drm_dp_dpcd_write(&intel_dp->aux, |
| 4076 | DP_TEST_EDID_CHECKSUM, |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 4077 | &block->checksum, |
Dan Carpenter | 5a1cc65 | 2015-05-12 21:07:37 +0300 | [diff] [blame] | 4078 | 1)) |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4079 | DRM_DEBUG_KMS("Failed to write EDID checksum\n"); |
| 4080 | |
| 4081 | test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE; |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4082 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | /* Set test active flag here so userspace doesn't interrupt things */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4086 | intel_dp->compliance.test_active = 1; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4087 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4088 | return test_result; |
| 4089 | } |
| 4090 | |
| 4091 | static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp) |
| 4092 | { |
| 4093 | uint8_t test_result = DP_TEST_NAK; |
| 4094 | return test_result; |
| 4095 | } |
| 4096 | |
| 4097 | static void intel_dp_handle_test_request(struct intel_dp *intel_dp) |
| 4098 | { |
| 4099 | uint8_t response = DP_TEST_NAK; |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4100 | uint8_t request = 0; |
| 4101 | int status; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4102 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4103 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4104 | if (status <= 0) { |
| 4105 | DRM_DEBUG_KMS("Could not read test request from sink\n"); |
| 4106 | goto update_status; |
| 4107 | } |
| 4108 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4109 | switch (request) { |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4110 | case DP_TEST_LINK_TRAINING: |
| 4111 | DRM_DEBUG_KMS("LINK_TRAINING test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4112 | response = intel_dp_autotest_link_training(intel_dp); |
| 4113 | break; |
| 4114 | case DP_TEST_LINK_VIDEO_PATTERN: |
| 4115 | DRM_DEBUG_KMS("TEST_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4116 | response = intel_dp_autotest_video_pattern(intel_dp); |
| 4117 | break; |
| 4118 | case DP_TEST_LINK_EDID_READ: |
| 4119 | DRM_DEBUG_KMS("EDID test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4120 | response = intel_dp_autotest_edid(intel_dp); |
| 4121 | break; |
| 4122 | case DP_TEST_LINK_PHY_TEST_PATTERN: |
| 4123 | DRM_DEBUG_KMS("PHY_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4124 | response = intel_dp_autotest_phy_pattern(intel_dp); |
| 4125 | break; |
| 4126 | default: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4127 | DRM_DEBUG_KMS("Invalid test request '%02x'\n", request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| 4130 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4131 | if (response & DP_TEST_ACK) |
| 4132 | intel_dp->compliance.test_type = request; |
| 4133 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4134 | update_status: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4135 | status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4136 | if (status <= 0) |
| 4137 | DRM_DEBUG_KMS("Could not write test response to sink\n"); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4138 | } |
| 4139 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4140 | static int |
| 4141 | intel_dp_check_mst_status(struct intel_dp *intel_dp) |
| 4142 | { |
| 4143 | bool bret; |
| 4144 | |
| 4145 | if (intel_dp->is_mst) { |
| 4146 | u8 esi[16] = { 0 }; |
| 4147 | int ret = 0; |
| 4148 | int retry; |
| 4149 | bool handled; |
| 4150 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4151 | go_again: |
| 4152 | if (bret == true) { |
| 4153 | |
| 4154 | /* check link status - esi[10] = 0x200c */ |
Ville Syrjälä | 19e0b4c | 2016-08-05 19:05:42 +0300 | [diff] [blame] | 4155 | if (intel_dp->active_mst_links && |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 4156 | !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4157 | DRM_DEBUG_KMS("channel EQ not ok, retraining\n"); |
| 4158 | intel_dp_start_link_train(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4159 | intel_dp_stop_link_train(intel_dp); |
| 4160 | } |
| 4161 | |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4162 | DRM_DEBUG_KMS("got esi %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4163 | ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); |
| 4164 | |
| 4165 | if (handled) { |
| 4166 | for (retry = 0; retry < 3; retry++) { |
| 4167 | int wret; |
| 4168 | wret = drm_dp_dpcd_write(&intel_dp->aux, |
| 4169 | DP_SINK_COUNT_ESI+1, |
| 4170 | &esi[1], 3); |
| 4171 | if (wret == 3) { |
| 4172 | break; |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4177 | if (bret == true) { |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4178 | DRM_DEBUG_KMS("got esi2 %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4179 | goto go_again; |
| 4180 | } |
| 4181 | } else |
| 4182 | ret = 0; |
| 4183 | |
| 4184 | return ret; |
| 4185 | } else { |
| 4186 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4187 | DRM_DEBUG_KMS("failed to get ESI - device may have failed\n"); |
| 4188 | intel_dp->is_mst = false; |
| 4189 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); |
| 4190 | /* send a hotplug event */ |
| 4191 | drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev); |
| 4192 | } |
| 4193 | } |
| 4194 | return -EINVAL; |
| 4195 | } |
| 4196 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4197 | static void |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4198 | intel_dp_retrain_link(struct intel_dp *intel_dp) |
| 4199 | { |
| 4200 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 4201 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4202 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 4203 | |
| 4204 | /* Suppress underruns caused by re-training */ |
| 4205 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
| 4206 | if (crtc->config->has_pch_encoder) |
| 4207 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4208 | intel_crtc_pch_transcoder(crtc), false); |
| 4209 | |
| 4210 | intel_dp_start_link_train(intel_dp); |
| 4211 | intel_dp_stop_link_train(intel_dp); |
| 4212 | |
| 4213 | /* Keep underrun reporting disabled until things are stable */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4214 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4215 | |
| 4216 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 4217 | if (crtc->config->has_pch_encoder) |
| 4218 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4219 | intel_crtc_pch_transcoder(crtc), true); |
| 4220 | } |
| 4221 | |
| 4222 | static void |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4223 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
| 4224 | { |
| 4225 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
| 4226 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
| 4227 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 4228 | |
| 4229 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 4230 | |
| 4231 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
| 4232 | DRM_ERROR("Failed to get link status\n"); |
| 4233 | return; |
| 4234 | } |
| 4235 | |
| 4236 | if (!intel_encoder->base.crtc) |
| 4237 | return; |
| 4238 | |
| 4239 | if (!to_intel_crtc(intel_encoder->base.crtc)->active) |
| 4240 | return; |
| 4241 | |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4242 | /* FIXME: we need to synchronize this sort of stuff with hardware |
Daniel Vetter | 2dd85ae | 2016-12-13 20:54:14 +0100 | [diff] [blame] | 4243 | * readout. Currently fast link training doesn't work on boot-up. */ |
| 4244 | if (!intel_dp->lane_count) |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4245 | return; |
| 4246 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4247 | /* Retrain if Channel EQ or CR not ok */ |
| 4248 | if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) { |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4249 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
| 4250 | intel_encoder->base.name); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4251 | |
| 4252 | intel_dp_retrain_link(intel_dp); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4253 | } |
| 4254 | } |
| 4255 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4256 | /* |
| 4257 | * According to DP spec |
| 4258 | * 5.1.2: |
| 4259 | * 1. Read DPCD |
| 4260 | * 2. Configure link according to Receiver Capabilities |
| 4261 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 4262 | * 4. Check link status on receipt of hot-plug interrupt |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4263 | * |
| 4264 | * intel_dp_short_pulse - handles short pulse interrupts |
| 4265 | * when full detection is not required. |
| 4266 | * Returns %true if short pulse is handled and full detection |
| 4267 | * is NOT required and %false otherwise. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4268 | */ |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4269 | static bool |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4270 | intel_dp_short_pulse(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4271 | { |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4272 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4273 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4274 | u8 sink_irq_vector = 0; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4275 | u8 old_sink_count = intel_dp->sink_count; |
| 4276 | bool ret; |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4277 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4278 | /* |
| 4279 | * Clearing compliance test variables to allow capturing |
| 4280 | * of values for next automated test request. |
| 4281 | */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4282 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4283 | |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4284 | /* |
| 4285 | * Now read the DPCD to see if it's actually running |
| 4286 | * If the current value of sink count doesn't match with |
| 4287 | * the value that was stored earlier or dpcd read failed |
| 4288 | * we need to do full detection |
| 4289 | */ |
| 4290 | ret = intel_dp_get_dpcd(intel_dp); |
| 4291 | |
| 4292 | if ((old_sink_count != intel_dp->sink_count) || !ret) { |
| 4293 | /* No need to proceed if we are going to do full detect */ |
| 4294 | return false; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 4295 | } |
| 4296 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4297 | /* Try to read the source of the interrupt */ |
| 4298 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4299 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4300 | sink_irq_vector != 0) { |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4301 | /* Clear interrupt source */ |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4302 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4303 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4304 | sink_irq_vector); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4305 | |
| 4306 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4307 | intel_dp_handle_test_request(intel_dp); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4308 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4309 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4310 | } |
| 4311 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4312 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4313 | intel_dp_check_link_status(intel_dp); |
| 4314 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4315 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 4316 | DRM_DEBUG_KMS("Link Training Compliance Test requested\n"); |
| 4317 | /* Send a Hotplug Uevent to userspace to start modeset */ |
| 4318 | drm_kms_helper_hotplug_event(intel_encoder->base.dev); |
| 4319 | } |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4320 | |
| 4321 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4322 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4323 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4324 | /* XXX this is probably wrong for multiple downstream ports */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4325 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4326 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4327 | { |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4328 | uint8_t *dpcd = intel_dp->dpcd; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4329 | uint8_t type; |
| 4330 | |
| 4331 | if (!intel_dp_get_dpcd(intel_dp)) |
| 4332 | return connector_status_disconnected; |
| 4333 | |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 4334 | if (is_edp(intel_dp)) |
| 4335 | return connector_status_connected; |
| 4336 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4337 | /* if there's no downstream port, we're done */ |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 4338 | if (!drm_dp_is_branch(dpcd)) |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4339 | return connector_status_connected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4340 | |
| 4341 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4342 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 4343 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4344 | |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 4345 | return intel_dp->sink_count ? |
| 4346 | connector_status_connected : connector_status_disconnected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4349 | if (intel_dp_can_mst(intel_dp)) |
| 4350 | return connector_status_connected; |
| 4351 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4352 | /* If no HPD, poke DDC gently */ |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 4353 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4354 | return connector_status_connected; |
| 4355 | |
| 4356 | /* Well we tried, say unknown for unreliable port types */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4357 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 4358 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 4359 | if (type == DP_DS_PORT_TYPE_VGA || |
| 4360 | type == DP_DS_PORT_TYPE_NON_EDID) |
| 4361 | return connector_status_unknown; |
| 4362 | } else { |
| 4363 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
| 4364 | DP_DWN_STRM_PORT_TYPE_MASK; |
| 4365 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || |
| 4366 | type == DP_DWN_STRM_PORT_TYPE_OTHER) |
| 4367 | return connector_status_unknown; |
| 4368 | } |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4369 | |
| 4370 | /* Anything else is out of spec, warn and ignore */ |
| 4371 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4372 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | static enum drm_connector_status |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4376 | edp_detect(struct intel_dp *intel_dp) |
| 4377 | { |
| 4378 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4379 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4380 | enum drm_connector_status status; |
| 4381 | |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4382 | status = intel_panel_detect(dev_priv); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4383 | if (status == connector_status_unknown) |
| 4384 | status = connector_status_connected; |
| 4385 | |
| 4386 | return status; |
| 4387 | } |
| 4388 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4389 | static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4390 | struct intel_digital_port *port) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4391 | { |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4392 | u32 bit; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 4393 | |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4394 | switch (port->port) { |
| 4395 | case PORT_A: |
| 4396 | return true; |
| 4397 | case PORT_B: |
| 4398 | bit = SDE_PORTB_HOTPLUG; |
| 4399 | break; |
| 4400 | case PORT_C: |
| 4401 | bit = SDE_PORTC_HOTPLUG; |
| 4402 | break; |
| 4403 | case PORT_D: |
| 4404 | bit = SDE_PORTD_HOTPLUG; |
| 4405 | break; |
| 4406 | default: |
| 4407 | MISSING_CASE(port->port); |
| 4408 | return false; |
| 4409 | } |
| 4410 | |
| 4411 | return I915_READ(SDEISR) & bit; |
| 4412 | } |
| 4413 | |
| 4414 | static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4415 | struct intel_digital_port *port) |
| 4416 | { |
| 4417 | u32 bit; |
| 4418 | |
| 4419 | switch (port->port) { |
| 4420 | case PORT_A: |
| 4421 | return true; |
| 4422 | case PORT_B: |
| 4423 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 4424 | break; |
| 4425 | case PORT_C: |
| 4426 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 4427 | break; |
| 4428 | case PORT_D: |
| 4429 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 4430 | break; |
Jani Nikula | a78695d | 2015-09-18 15:54:50 +0300 | [diff] [blame] | 4431 | case PORT_E: |
| 4432 | bit = SDE_PORTE_HOTPLUG_SPT; |
| 4433 | break; |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4434 | default: |
| 4435 | MISSING_CASE(port->port); |
| 4436 | return false; |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4437 | } |
Damien Lespiau | 1b46963 | 2012-12-13 16:09:01 +0000 | [diff] [blame] | 4438 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4439 | return I915_READ(SDEISR) & bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4440 | } |
| 4441 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4442 | static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv, |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4443 | struct intel_digital_port *port) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4444 | { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4445 | u32 bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4446 | |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4447 | switch (port->port) { |
| 4448 | case PORT_B: |
| 4449 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; |
| 4450 | break; |
| 4451 | case PORT_C: |
| 4452 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; |
| 4453 | break; |
| 4454 | case PORT_D: |
| 4455 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; |
| 4456 | break; |
| 4457 | default: |
| 4458 | MISSING_CASE(port->port); |
| 4459 | return false; |
| 4460 | } |
| 4461 | |
| 4462 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 4463 | } |
| 4464 | |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4465 | static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4466 | struct intel_digital_port *port) |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4467 | { |
| 4468 | u32 bit; |
| 4469 | |
| 4470 | switch (port->port) { |
| 4471 | case PORT_B: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4472 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4473 | break; |
| 4474 | case PORT_C: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4475 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4476 | break; |
| 4477 | case PORT_D: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4478 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4479 | break; |
| 4480 | default: |
| 4481 | MISSING_CASE(port->port); |
| 4482 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4485 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
Dave Airlie | 2a592be | 2014-09-01 16:58:12 +1000 | [diff] [blame] | 4486 | } |
| 4487 | |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4488 | static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv, |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4489 | struct intel_digital_port *intel_dig_port) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4490 | { |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4491 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 4492 | enum port port; |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4493 | u32 bit; |
| 4494 | |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4495 | intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port); |
| 4496 | switch (port) { |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4497 | case PORT_A: |
| 4498 | bit = BXT_DE_PORT_HP_DDIA; |
| 4499 | break; |
| 4500 | case PORT_B: |
| 4501 | bit = BXT_DE_PORT_HP_DDIB; |
| 4502 | break; |
| 4503 | case PORT_C: |
| 4504 | bit = BXT_DE_PORT_HP_DDIC; |
| 4505 | break; |
| 4506 | default: |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4507 | MISSING_CASE(port); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4508 | return false; |
| 4509 | } |
| 4510 | |
| 4511 | return I915_READ(GEN8_DE_PORT_ISR) & bit; |
| 4512 | } |
| 4513 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4514 | /* |
| 4515 | * intel_digital_port_connected - is the specified port connected? |
| 4516 | * @dev_priv: i915 private structure |
| 4517 | * @port: the port to test |
| 4518 | * |
| 4519 | * Return %true if @port is connected, %false otherwise. |
| 4520 | */ |
Imre Deak | 390b4e0 | 2017-01-27 11:39:19 +0200 | [diff] [blame] | 4521 | bool intel_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4522 | struct intel_digital_port *port) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4523 | { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4524 | if (HAS_PCH_IBX(dev_priv)) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4525 | return ibx_digital_port_connected(dev_priv, port); |
Ville Syrjälä | 22824fa | 2016-02-11 16:44:28 +0200 | [diff] [blame] | 4526 | else if (HAS_PCH_SPLIT(dev_priv)) |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4527 | return cpt_digital_port_connected(dev_priv, port); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4528 | else if (IS_GEN9_LP(dev_priv)) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4529 | return bxt_digital_port_connected(dev_priv, port); |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4530 | else if (IS_GM45(dev_priv)) |
| 4531 | return gm45_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4532 | else |
| 4533 | return g4x_digital_port_connected(dev_priv, port); |
| 4534 | } |
| 4535 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4536 | static struct edid * |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4537 | intel_dp_get_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4538 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4539 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4540 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4541 | /* use cached edid if we have one */ |
| 4542 | if (intel_connector->edid) { |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4543 | /* invalid edid */ |
| 4544 | if (IS_ERR(intel_connector->edid)) |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4545 | return NULL; |
| 4546 | |
Jani Nikula | 55e9ede | 2013-10-01 10:38:54 +0300 | [diff] [blame] | 4547 | return drm_edid_duplicate(intel_connector->edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4548 | } else |
| 4549 | return drm_get_edid(&intel_connector->base, |
| 4550 | &intel_dp->aux.ddc); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4553 | static void |
| 4554 | intel_dp_set_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4555 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4556 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4557 | struct edid *edid; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4558 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4559 | intel_dp_unset_edid(intel_dp); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4560 | edid = intel_dp_get_edid(intel_dp); |
| 4561 | intel_connector->detect_edid = edid; |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4562 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4563 | if (intel_dp->force_audio != HDMI_AUDIO_AUTO) |
| 4564 | intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON; |
| 4565 | else |
| 4566 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
| 4567 | } |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4568 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4569 | static void |
| 4570 | intel_dp_unset_edid(struct intel_dp *intel_dp) |
| 4571 | { |
| 4572 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4573 | |
| 4574 | kfree(intel_connector->detect_edid); |
| 4575 | intel_connector->detect_edid = NULL; |
| 4576 | |
| 4577 | intel_dp->has_audio = false; |
| 4578 | } |
| 4579 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4580 | static enum drm_connector_status |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4581 | intel_dp_long_pulse(struct intel_connector *intel_connector) |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4582 | { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4583 | struct drm_connector *connector = &intel_connector->base; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4584 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Paulo Zanoni | d63885d | 2012-10-26 19:05:49 -0200 | [diff] [blame] | 4585 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4586 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 4587 | struct drm_device *dev = connector->dev; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4588 | enum drm_connector_status status; |
Imre Deak | 671dedd | 2014-03-05 16:20:53 +0200 | [diff] [blame] | 4589 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4590 | u8 sink_irq_vector = 0; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4591 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4592 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
| 4593 | intel_display_power_get(to_i915(dev), power_domain); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4594 | |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4595 | /* Can't disconnect eDP, but you can close the lid... */ |
| 4596 | if (is_edp(intel_dp)) |
| 4597 | status = edp_detect(intel_dp); |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4598 | else if (intel_digital_port_connected(to_i915(dev), |
| 4599 | dp_to_dig_port(intel_dp))) |
| 4600 | status = intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4601 | else |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4602 | status = connector_status_disconnected; |
| 4603 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4604 | if (status == connector_status_disconnected) { |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4605 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4606 | |
jim.bride@linux.intel.com | 0e505a0 | 2016-04-11 10:11:24 -0700 | [diff] [blame] | 4607 | if (intel_dp->is_mst) { |
| 4608 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4609 | intel_dp->is_mst, |
| 4610 | intel_dp->mst_mgr.mst_state); |
| 4611 | intel_dp->is_mst = false; |
| 4612 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4613 | intel_dp->is_mst); |
| 4614 | } |
| 4615 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4616 | goto out; |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4617 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4618 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4619 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4620 | intel_encoder->type = INTEL_OUTPUT_DP; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4621 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4622 | DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n", |
| 4623 | yesno(intel_dp_source_supports_hbr2(intel_dp)), |
| 4624 | yesno(drm_dp_tps3_supported(intel_dp->dpcd))); |
| 4625 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4626 | if (intel_dp->reset_link_params) { |
| 4627 | /* Set the max lane count for sink */ |
| 4628 | intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd); |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4629 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4630 | /* Set the max link BW for sink */ |
| 4631 | intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp); |
| 4632 | |
| 4633 | intel_dp->reset_link_params = false; |
| 4634 | } |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4635 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4636 | intel_dp_print_rates(intel_dp); |
| 4637 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 4638 | intel_dp_read_desc(intel_dp); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 4639 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4640 | intel_dp_configure_mst(intel_dp); |
| 4641 | |
| 4642 | if (intel_dp->is_mst) { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4643 | /* |
| 4644 | * If we are in MST mode then this connector |
| 4645 | * won't appear connected or have anything |
| 4646 | * with EDID on it |
| 4647 | */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4648 | status = connector_status_disconnected; |
| 4649 | goto out; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4650 | } else if (connector->status == connector_status_connected) { |
| 4651 | /* |
| 4652 | * If display was connected already and is still connected |
| 4653 | * check links status, there has been known issues of |
| 4654 | * link loss triggerring long pulse!!!! |
| 4655 | */ |
| 4656 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4657 | intel_dp_check_link_status(intel_dp); |
| 4658 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 4659 | goto out; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4660 | } |
| 4661 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4662 | /* |
| 4663 | * Clearing NACK and defer counts to get their exact values |
| 4664 | * while reading EDID which are required by Compliance tests |
| 4665 | * 4.2.2.4 and 4.2.2.5 |
| 4666 | */ |
| 4667 | intel_dp->aux.i2c_nack_count = 0; |
| 4668 | intel_dp->aux.i2c_defer_count = 0; |
| 4669 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4670 | intel_dp_set_edid(intel_dp); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4671 | if (is_edp(intel_dp) || intel_connector->detect_edid) |
| 4672 | status = connector_status_connected; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4673 | intel_dp->detect_done = true; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4674 | |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4675 | /* Try to read the source of the interrupt */ |
| 4676 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4677 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4678 | sink_irq_vector != 0) { |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4679 | /* Clear interrupt source */ |
| 4680 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4681 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4682 | sink_irq_vector); |
| 4683 | |
| 4684 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
| 4685 | intel_dp_handle_test_request(intel_dp); |
| 4686 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4687 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4688 | } |
| 4689 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4690 | out: |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4691 | if (status != connector_status_connected && !intel_dp->is_mst) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4692 | intel_dp_unset_edid(intel_dp); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4693 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4694 | intel_display_power_put(to_i915(dev), power_domain); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4695 | return status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | static enum drm_connector_status |
| 4699 | intel_dp_detect(struct drm_connector *connector, bool force) |
| 4700 | { |
| 4701 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4702 | enum drm_connector_status status = connector->status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4703 | |
| 4704 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4705 | connector->base.id, connector->name); |
| 4706 | |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4707 | /* If full detect is not performed yet, do a full detect */ |
| 4708 | if (!intel_dp->detect_done) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4709 | status = intel_dp_long_pulse(intel_dp->attached_connector); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4710 | |
| 4711 | intel_dp->detect_done = false; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4712 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4713 | return status; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4714 | } |
| 4715 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4716 | static void |
| 4717 | intel_dp_force(struct drm_connector *connector) |
| 4718 | { |
| 4719 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 4720 | 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] | 4721 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4722 | enum intel_display_power_domain power_domain; |
| 4723 | |
| 4724 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4725 | connector->base.id, connector->name); |
| 4726 | intel_dp_unset_edid(intel_dp); |
| 4727 | |
| 4728 | if (connector->status != connector_status_connected) |
| 4729 | return; |
| 4730 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4731 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
| 4732 | intel_display_power_get(dev_priv, power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4733 | |
| 4734 | intel_dp_set_edid(intel_dp); |
| 4735 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 4736 | intel_display_power_put(dev_priv, power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4737 | |
| 4738 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4739 | intel_encoder->type = INTEL_OUTPUT_DP; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4740 | } |
| 4741 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4742 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 4743 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4744 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4745 | struct edid *edid; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4746 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4747 | edid = intel_connector->detect_edid; |
| 4748 | if (edid) { |
| 4749 | int ret = intel_connector_update_modes(connector, edid); |
| 4750 | if (ret) |
| 4751 | return ret; |
| 4752 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4753 | |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4754 | /* if eDP has no EDID, fall back to fixed mode */ |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4755 | if (is_edp(intel_attached_dp(connector)) && |
| 4756 | intel_connector->panel.fixed_mode) { |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4757 | struct drm_display_mode *mode; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4758 | |
| 4759 | mode = drm_mode_duplicate(connector->dev, |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4760 | intel_connector->panel.fixed_mode); |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4761 | if (mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4762 | drm_mode_probed_add(connector, mode); |
| 4763 | return 1; |
| 4764 | } |
| 4765 | } |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4766 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4767 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4768 | } |
| 4769 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4770 | static bool |
| 4771 | intel_dp_detect_audio(struct drm_connector *connector) |
| 4772 | { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4773 | bool has_audio = false; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4774 | struct edid *edid; |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4775 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4776 | edid = to_intel_connector(connector)->detect_edid; |
| 4777 | if (edid) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4778 | has_audio = drm_detect_monitor_audio(edid); |
Imre Deak | 671dedd | 2014-03-05 16:20:53 +0200 | [diff] [blame] | 4779 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4780 | return has_audio; |
| 4781 | } |
| 4782 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4783 | static int |
| 4784 | intel_dp_set_property(struct drm_connector *connector, |
| 4785 | struct drm_property *property, |
| 4786 | uint64_t val) |
| 4787 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4788 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4789 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4790 | struct intel_encoder *intel_encoder = intel_attached_encoder(connector); |
| 4791 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4792 | int ret; |
| 4793 | |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 4794 | ret = drm_object_property_set_value(&connector->base, property, val); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4795 | if (ret) |
| 4796 | return ret; |
| 4797 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 4798 | if (property == dev_priv->force_audio_property) { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4799 | int i = val; |
| 4800 | bool has_audio; |
| 4801 | |
| 4802 | if (i == intel_dp->force_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4803 | return 0; |
| 4804 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4805 | intel_dp->force_audio = i; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4806 | |
Daniel Vetter | c3e5f67 | 2012-02-23 17:14:47 +0100 | [diff] [blame] | 4807 | if (i == HDMI_AUDIO_AUTO) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4808 | has_audio = intel_dp_detect_audio(connector); |
| 4809 | else |
Daniel Vetter | c3e5f67 | 2012-02-23 17:14:47 +0100 | [diff] [blame] | 4810 | has_audio = (i == HDMI_AUDIO_ON); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4811 | |
| 4812 | if (has_audio == intel_dp->has_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4813 | return 0; |
| 4814 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4815 | intel_dp->has_audio = has_audio; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4816 | goto done; |
| 4817 | } |
| 4818 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4819 | if (property == dev_priv->broadcast_rgb_property) { |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4820 | bool old_auto = intel_dp->color_range_auto; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4821 | bool old_range = intel_dp->limited_color_range; |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4822 | |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4823 | switch (val) { |
| 4824 | case INTEL_BROADCAST_RGB_AUTO: |
| 4825 | intel_dp->color_range_auto = true; |
| 4826 | break; |
| 4827 | case INTEL_BROADCAST_RGB_FULL: |
| 4828 | intel_dp->color_range_auto = false; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4829 | intel_dp->limited_color_range = false; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4830 | break; |
| 4831 | case INTEL_BROADCAST_RGB_LIMITED: |
| 4832 | intel_dp->color_range_auto = false; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4833 | intel_dp->limited_color_range = true; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4834 | break; |
| 4835 | default: |
| 4836 | return -EINVAL; |
| 4837 | } |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4838 | |
| 4839 | if (old_auto == intel_dp->color_range_auto && |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4840 | old_range == intel_dp->limited_color_range) |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4841 | return 0; |
| 4842 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4843 | goto done; |
| 4844 | } |
| 4845 | |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4846 | if (is_edp(intel_dp) && |
| 4847 | property == connector->dev->mode_config.scaling_mode_property) { |
| 4848 | if (val == DRM_MODE_SCALE_NONE) { |
| 4849 | DRM_DEBUG_KMS("no scaling not supported\n"); |
| 4850 | return -EINVAL; |
| 4851 | } |
Ville Syrjälä | 234126c | 2016-04-12 22:14:38 +0300 | [diff] [blame] | 4852 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 4853 | val == DRM_MODE_SCALE_CENTER) { |
| 4854 | DRM_DEBUG_KMS("centering not supported\n"); |
| 4855 | return -EINVAL; |
| 4856 | } |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4857 | |
| 4858 | if (intel_connector->panel.fitting_mode == val) { |
| 4859 | /* the eDP scaling property is not changed */ |
| 4860 | return 0; |
| 4861 | } |
| 4862 | intel_connector->panel.fitting_mode = val; |
| 4863 | |
| 4864 | goto done; |
| 4865 | } |
| 4866 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4867 | return -EINVAL; |
| 4868 | |
| 4869 | done: |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 4870 | if (intel_encoder->base.crtc) |
| 4871 | intel_crtc_restore_mode(intel_encoder->base.crtc); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4872 | |
| 4873 | return 0; |
| 4874 | } |
| 4875 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4876 | static int |
| 4877 | intel_dp_connector_register(struct drm_connector *connector) |
| 4878 | { |
| 4879 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 4880 | int ret; |
| 4881 | |
| 4882 | ret = intel_connector_register(connector); |
| 4883 | if (ret) |
| 4884 | return ret; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4885 | |
| 4886 | i915_debugfs_connector_add(connector); |
| 4887 | |
| 4888 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
| 4889 | intel_dp->aux.name, connector->kdev->kobj.name); |
| 4890 | |
| 4891 | intel_dp->aux.dev = connector->kdev; |
| 4892 | return drm_dp_aux_register(&intel_dp->aux); |
| 4893 | } |
| 4894 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4895 | static void |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4896 | intel_dp_connector_unregister(struct drm_connector *connector) |
| 4897 | { |
| 4898 | drm_dp_aux_unregister(&intel_attached_dp(connector)->aux); |
| 4899 | intel_connector_unregister(connector); |
| 4900 | } |
| 4901 | |
| 4902 | static void |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 4903 | intel_dp_connector_destroy(struct drm_connector *connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4904 | { |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4905 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4906 | |
Chris Wilson | 10e972d | 2014-09-04 21:43:45 +0100 | [diff] [blame] | 4907 | kfree(intel_connector->detect_edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4908 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4909 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 4910 | kfree(intel_connector->edid); |
| 4911 | |
Paulo Zanoni | acd8db10 | 2013-06-12 17:27:23 -0300 | [diff] [blame] | 4912 | /* Can't call is_edp() since the encoder may have been destroyed |
| 4913 | * already. */ |
| 4914 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4915 | intel_panel_fini(&intel_connector->panel); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4916 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4917 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 4918 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4919 | } |
| 4920 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 4921 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4922 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4923 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 4924 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4925 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4926 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4927 | if (is_edp(intel_dp)) { |
| 4928 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4929 | /* |
| 4930 | * vdd might still be enabled do to the delayed vdd off. |
| 4931 | * Make sure vdd is actually turned off here. |
| 4932 | */ |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4933 | pps_lock(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 4934 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4935 | pps_unlock(intel_dp); |
| 4936 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 4937 | if (intel_dp->edp_notifier.notifier_call) { |
| 4938 | unregister_reboot_notifier(&intel_dp->edp_notifier); |
| 4939 | intel_dp->edp_notifier.notifier_call = NULL; |
| 4940 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4941 | } |
Chris Wilson | 9968188 | 2016-06-20 09:29:17 +0100 | [diff] [blame] | 4942 | |
| 4943 | intel_dp_aux_fini(intel_dp); |
| 4944 | |
Imre Deak | c8bd0e4 | 2014-12-12 17:57:38 +0200 | [diff] [blame] | 4945 | drm_encoder_cleanup(encoder); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4946 | kfree(intel_dig_port); |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4947 | } |
| 4948 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 4949 | void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4950 | { |
| 4951 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 4952 | |
| 4953 | if (!is_edp(intel_dp)) |
| 4954 | return; |
| 4955 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4956 | /* |
| 4957 | * vdd might still be enabled do to the delayed vdd off. |
| 4958 | * Make sure vdd is actually turned off here. |
| 4959 | */ |
Ville Syrjälä | afa4e53 | 2014-11-25 15:43:48 +0200 | [diff] [blame] | 4960 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4961 | pps_lock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4962 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4963 | pps_unlock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4964 | } |
| 4965 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4966 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
| 4967 | { |
| 4968 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4969 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4970 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4971 | enum intel_display_power_domain power_domain; |
| 4972 | |
| 4973 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 4974 | |
| 4975 | if (!edp_have_panel_vdd(intel_dp)) |
| 4976 | return; |
| 4977 | |
| 4978 | /* |
| 4979 | * The VDD bit needs a power domain reference, so if the bit is |
| 4980 | * already enabled when we boot or resume, grab this reference and |
| 4981 | * schedule a vdd off, so we don't hold on to the reference |
| 4982 | * indefinitely. |
| 4983 | */ |
| 4984 | 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] | 4985 | 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] | 4986 | intel_display_power_get(dev_priv, power_domain); |
| 4987 | |
| 4988 | edp_panel_vdd_schedule_off(intel_dp); |
| 4989 | } |
| 4990 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 4991 | static enum pipe vlv_active_pipe(struct intel_dp *intel_dp) |
| 4992 | { |
| 4993 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 4994 | |
| 4995 | if ((intel_dp->DP & DP_PORT_EN) == 0) |
| 4996 | return INVALID_PIPE; |
| 4997 | |
| 4998 | if (IS_CHERRYVIEW(dev_priv)) |
| 4999 | return DP_PORT_TO_PIPE_CHV(intel_dp->DP); |
| 5000 | else |
| 5001 | return PORT_TO_PIPE(intel_dp->DP); |
| 5002 | } |
| 5003 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 5004 | void intel_dp_encoder_reset(struct drm_encoder *encoder) |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5005 | { |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5006 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5007 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 5008 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5009 | |
| 5010 | if (!HAS_DDI(dev_priv)) |
| 5011 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5012 | |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5013 | if (lspcon->active) |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 5014 | lspcon_resume(lspcon); |
| 5015 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5016 | intel_dp->reset_link_params = true; |
| 5017 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5018 | pps_lock(intel_dp); |
| 5019 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5020 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5021 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 5022 | |
| 5023 | if (is_edp(intel_dp)) { |
| 5024 | /* Reinit the power sequencer, in case BIOS did something with it. */ |
| 5025 | intel_dp_pps_init(encoder->dev, intel_dp); |
| 5026 | intel_edp_panel_vdd_sanitize(intel_dp); |
| 5027 | } |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5028 | |
| 5029 | pps_unlock(intel_dp); |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5030 | } |
| 5031 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5032 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 5033 | .dpms = drm_atomic_helper_connector_dpms, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5034 | .detect = intel_dp_detect, |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 5035 | .force = intel_dp_force, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5036 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5037 | .set_property = intel_dp_set_property, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 5038 | .atomic_get_property = intel_connector_atomic_get_property, |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5039 | .late_register = intel_dp_connector_register, |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 5040 | .early_unregister = intel_dp_connector_unregister, |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 5041 | .destroy = intel_dp_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 5042 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Ander Conselvan de Oliveira | 9896972 | 2015-03-20 16:18:06 +0200 | [diff] [blame] | 5043 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5044 | }; |
| 5045 | |
| 5046 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
| 5047 | .get_modes = intel_dp_get_modes, |
| 5048 | .mode_valid = intel_dp_mode_valid, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5049 | }; |
| 5050 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5051 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5052 | .reset = intel_dp_encoder_reset, |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5053 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5054 | }; |
| 5055 | |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5056 | enum irqreturn |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5057 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
| 5058 | { |
| 5059 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5060 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5061 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5062 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5063 | enum intel_display_power_domain power_domain; |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5064 | enum irqreturn ret = IRQ_NONE; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5065 | |
Takashi Iwai | 2540058 | 2015-11-19 12:09:56 +0100 | [diff] [blame] | 5066 | if (intel_dig_port->base.type != INTEL_OUTPUT_EDP && |
| 5067 | intel_dig_port->base.type != INTEL_OUTPUT_HDMI) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 5068 | intel_dig_port->base.type = INTEL_OUTPUT_DP; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5069 | |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5070 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
| 5071 | /* |
| 5072 | * vdd off can generate a long pulse on eDP which |
| 5073 | * would require vdd on to handle it, and thus we |
| 5074 | * would end up in an endless cycle of |
| 5075 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." |
| 5076 | */ |
| 5077 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", |
| 5078 | port_name(intel_dig_port->port)); |
Ville Syrjälä | a8b3d52f8 | 2015-02-10 14:11:46 +0200 | [diff] [blame] | 5079 | return IRQ_HANDLED; |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5080 | } |
| 5081 | |
Ville Syrjälä | 26fbb77 | 2014-08-11 18:37:37 +0300 | [diff] [blame] | 5082 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
| 5083 | port_name(intel_dig_port->port), |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5084 | long_hpd ? "long" : "short"); |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5085 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5086 | if (long_hpd) { |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5087 | intel_dp->reset_link_params = true; |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5088 | intel_dp->detect_done = false; |
| 5089 | return IRQ_NONE; |
| 5090 | } |
| 5091 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5092 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5093 | intel_display_power_get(dev_priv, power_domain); |
| 5094 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5095 | if (intel_dp->is_mst) { |
| 5096 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) { |
| 5097 | /* |
| 5098 | * If we were in MST mode, and device is not |
| 5099 | * there, get out of MST mode |
| 5100 | */ |
| 5101 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 5102 | intel_dp->is_mst, intel_dp->mst_mgr.mst_state); |
| 5103 | intel_dp->is_mst = false; |
| 5104 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 5105 | intel_dp->is_mst); |
| 5106 | intel_dp->detect_done = false; |
| 5107 | goto put_power; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5108 | } |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5109 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5110 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5111 | if (!intel_dp->is_mst) { |
| 5112 | if (!intel_dp_short_pulse(intel_dp)) { |
| 5113 | intel_dp->detect_done = false; |
| 5114 | goto put_power; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 5115 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5116 | } |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5117 | |
| 5118 | ret = IRQ_HANDLED; |
| 5119 | |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5120 | put_power: |
| 5121 | intel_display_power_put(dev_priv, power_domain); |
| 5122 | |
| 5123 | return ret; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5124 | } |
| 5125 | |
Rodrigo Vivi | 477ec32 | 2015-08-06 15:51:39 +0800 | [diff] [blame] | 5126 | /* check the VBT to see whether the eDP is on another port */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5127 | 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] | 5128 | { |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5129 | /* |
| 5130 | * eDP not supported on g4x. so bail out early just |
| 5131 | * for a bit extra safety in case the VBT is bonkers. |
| 5132 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5133 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5134 | return false; |
| 5135 | |
Imre Deak | a98d9c1 | 2016-12-21 12:17:24 +0200 | [diff] [blame] | 5136 | if (INTEL_GEN(dev_priv) < 9 && port == PORT_A) |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5137 | return true; |
| 5138 | |
Jani Nikula | 951d9ef | 2016-03-16 12:43:31 +0200 | [diff] [blame] | 5139 | return intel_bios_is_port_edp(dev_priv, port); |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 5140 | } |
| 5141 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5142 | void |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5143 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 5144 | { |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5145 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 5146 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 5147 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 5148 | intel_attach_broadcast_rgb_property(connector); |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 5149 | intel_dp->color_range_auto = true; |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5150 | |
| 5151 | if (is_edp(intel_dp)) { |
| 5152 | drm_mode_create_scaling_mode_property(connector->dev); |
Rob Clark | 6de6d84 | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 5153 | drm_object_attach_property( |
| 5154 | &connector->base, |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5155 | connector->dev->mode_config.scaling_mode_property, |
Yuly Novikov | 8e740cd | 2012-10-26 12:04:01 +0300 | [diff] [blame] | 5156 | DRM_MODE_SCALE_ASPECT); |
| 5157 | intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT; |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5158 | } |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5159 | } |
| 5160 | |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5161 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
| 5162 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 5163 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5164 | intel_dp->last_power_on = jiffies; |
| 5165 | intel_dp->last_backlight_off = jiffies; |
| 5166 | } |
| 5167 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5168 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5169 | intel_pps_readout_hw_state(struct drm_i915_private *dev_priv, |
| 5170 | struct intel_dp *intel_dp, struct edp_power_seq *seq) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5171 | { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5172 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5173 | struct pps_registers regs; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5174 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5175 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5176 | |
| 5177 | /* Workaround: Need to write PP_CONTROL with the unlock key as |
| 5178 | * the very first thing. */ |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5179 | pp_ctl = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5180 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5181 | pp_on = I915_READ(regs.pp_on); |
| 5182 | pp_off = I915_READ(regs.pp_off); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5183 | if (!IS_GEN9_LP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5184 | I915_WRITE(regs.pp_ctrl, pp_ctl); |
| 5185 | pp_div = I915_READ(regs.pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5186 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5187 | |
| 5188 | /* Pull timing values out of registers */ |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5189 | seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 5190 | PANEL_POWER_UP_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5191 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5192 | seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 5193 | PANEL_LIGHT_ON_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5194 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5195 | seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 5196 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5197 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5198 | seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 5199 | PANEL_POWER_DOWN_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5200 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5201 | if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5202 | u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> |
| 5203 | BXT_POWER_CYCLE_DELAY_SHIFT; |
| 5204 | if (tmp > 0) |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5205 | seq->t11_t12 = (tmp - 1) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5206 | else |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5207 | seq->t11_t12 = 0; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5208 | } else { |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5209 | seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5210 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5211 | } |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | static void |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5215 | intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq) |
| 5216 | { |
| 5217 | DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 5218 | state_name, |
| 5219 | seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12); |
| 5220 | } |
| 5221 | |
| 5222 | static void |
| 5223 | intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 5224 | struct intel_dp *intel_dp) |
| 5225 | { |
| 5226 | struct edp_power_seq hw; |
| 5227 | struct edp_power_seq *sw = &intel_dp->pps_delays; |
| 5228 | |
| 5229 | intel_pps_readout_hw_state(dev_priv, intel_dp, &hw); |
| 5230 | |
| 5231 | if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 || |
| 5232 | hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) { |
| 5233 | DRM_ERROR("PPS state mismatch\n"); |
| 5234 | intel_pps_dump_state("sw", sw); |
| 5235 | intel_pps_dump_state("hw", &hw); |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5240 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
| 5241 | struct intel_dp *intel_dp) |
| 5242 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5243 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5244 | struct edp_power_seq cur, vbt, spec, |
| 5245 | *final = &intel_dp->pps_delays; |
| 5246 | |
| 5247 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5248 | |
| 5249 | /* already initialized? */ |
| 5250 | if (final->t11_t12 != 0) |
| 5251 | return; |
| 5252 | |
| 5253 | intel_pps_readout_hw_state(dev_priv, intel_dp, &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5254 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5255 | intel_pps_dump_state("cur", &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5256 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 5257 | vbt = dev_priv->vbt.edp.pps; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5258 | |
| 5259 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of |
| 5260 | * our hw here, which are all in 100usec. */ |
| 5261 | spec.t1_t3 = 210 * 10; |
| 5262 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ |
| 5263 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ |
| 5264 | spec.t10 = 500 * 10; |
| 5265 | /* This one is special and actually in units of 100ms, but zero |
| 5266 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5267 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5268 | * too. */ |
| 5269 | spec.t11_t12 = (510 + 100) * 10; |
| 5270 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5271 | intel_pps_dump_state("vbt", &vbt); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5272 | |
| 5273 | /* Use the max of the register settings and vbt. If both are |
| 5274 | * unset, fall back to the spec limits. */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5275 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5276 | spec.field : \ |
| 5277 | max(cur.field, vbt.field)) |
| 5278 | assign_final(t1_t3); |
| 5279 | assign_final(t8); |
| 5280 | assign_final(t9); |
| 5281 | assign_final(t10); |
| 5282 | assign_final(t11_t12); |
| 5283 | #undef assign_final |
| 5284 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5285 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5286 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 5287 | intel_dp->backlight_on_delay = get_delay(t8); |
| 5288 | intel_dp->backlight_off_delay = get_delay(t9); |
| 5289 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 5290 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 5291 | #undef get_delay |
| 5292 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5293 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 5294 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 5295 | intel_dp->panel_power_cycle_delay); |
| 5296 | |
| 5297 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 5298 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5299 | |
| 5300 | /* |
| 5301 | * We override the HW backlight delays to 1 because we do manual waits |
| 5302 | * on them. For T8, even BSpec recommends doing it. For T9, if we |
| 5303 | * don't do this, we'll end up waiting for the backlight off delay |
| 5304 | * twice: once when we do the manual sleep, and once when we disable |
| 5305 | * the panel and wait for the PP_STATUS bit to become zero. |
| 5306 | */ |
| 5307 | final->t8 = 1; |
| 5308 | final->t9 = 1; |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | static void |
| 5312 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5313 | struct intel_dp *intel_dp, |
| 5314 | bool force_disable_vdd) |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5315 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5316 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5317 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 5318 | int div = dev_priv->rawclk_freq / 1000; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5319 | struct pps_registers regs; |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5320 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5321 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5322 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 5323 | lockdep_assert_held(&dev_priv->pps_mutex); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5324 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5325 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5326 | |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5327 | /* |
| 5328 | * On some VLV machines the BIOS can leave the VDD |
| 5329 | * enabled even on power seqeuencers which aren't |
| 5330 | * hooked up to any port. This would mess up the |
| 5331 | * power domain tracking the first time we pick |
| 5332 | * one of these power sequencers for use since |
| 5333 | * edp_panel_vdd_on() would notice that the VDD was |
| 5334 | * already on and therefore wouldn't grab the power |
| 5335 | * domain reference. Disable VDD first to avoid this. |
| 5336 | * This also avoids spuriously turning the VDD on as |
| 5337 | * soon as the new power seqeuencer gets initialized. |
| 5338 | */ |
| 5339 | if (force_disable_vdd) { |
| 5340 | u32 pp = ironlake_get_pp_control(intel_dp); |
| 5341 | |
| 5342 | WARN(pp & PANEL_POWER_ON, "Panel power already on\n"); |
| 5343 | |
| 5344 | if (pp & EDP_FORCE_VDD) |
| 5345 | DRM_DEBUG_KMS("VDD already on, disabling first\n"); |
| 5346 | |
| 5347 | pp &= ~EDP_FORCE_VDD; |
| 5348 | |
| 5349 | I915_WRITE(regs.pp_ctrl, pp); |
| 5350 | } |
| 5351 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5352 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5353 | (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT); |
| 5354 | pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5355 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5356 | /* Compute the divisor for the pp clock, simply match the Bspec |
| 5357 | * formula. */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5358 | if (IS_GEN9_LP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5359 | pp_div = I915_READ(regs.pp_ctrl); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5360 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; |
| 5361 | pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000) |
| 5362 | << BXT_POWER_CYCLE_DELAY_SHIFT); |
| 5363 | } else { |
| 5364 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 5365 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
| 5366 | << PANEL_POWER_CYCLE_DELAY_SHIFT); |
| 5367 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5368 | |
| 5369 | /* Haswell doesn't have any port selection bits for the panel |
| 5370 | * power sequencer any more. */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5371 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5372 | port_sel = PANEL_PORT_SELECT_VLV(port); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5373 | } 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] | 5374 | if (port == PORT_A) |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5375 | port_sel = PANEL_PORT_SELECT_DPA; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5376 | else |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5377 | port_sel = PANEL_PORT_SELECT_DPD; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5378 | } |
| 5379 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5380 | pp_on |= port_sel; |
| 5381 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5382 | I915_WRITE(regs.pp_on, pp_on); |
| 5383 | I915_WRITE(regs.pp_off, pp_off); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5384 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5385 | I915_WRITE(regs.pp_ctrl, pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5386 | else |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5387 | I915_WRITE(regs.pp_div, pp_div); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5388 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5389 | 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] | 5390 | I915_READ(regs.pp_on), |
| 5391 | I915_READ(regs.pp_off), |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5392 | IS_GEN9_LP(dev_priv) ? |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5393 | (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) : |
| 5394 | I915_READ(regs.pp_div)); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 5395 | } |
| 5396 | |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5397 | static void intel_dp_pps_init(struct drm_device *dev, |
| 5398 | struct intel_dp *intel_dp) |
| 5399 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5400 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5401 | |
| 5402 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5403 | vlv_initial_power_sequencer_setup(intel_dp); |
| 5404 | } else { |
| 5405 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5406 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5407 | } |
| 5408 | } |
| 5409 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5410 | /** |
| 5411 | * 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] | 5412 | * @dev_priv: i915 device |
Maarten Lankhorst | e896402 | 2016-08-25 11:07:02 +0200 | [diff] [blame] | 5413 | * @crtc_state: a pointer to the active intel_crtc_state |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5414 | * @refresh_rate: RR to be programmed |
| 5415 | * |
| 5416 | * This function gets called when refresh rate (RR) has to be changed from |
| 5417 | * one frequency to another. Switches can be between high and low RR |
| 5418 | * supported by the panel or to any other RR based on media playback (in |
| 5419 | * this case, RR value needs to be passed from user space). |
| 5420 | * |
| 5421 | * The caller of this function needs to take a lock on dev_priv->drrs. |
| 5422 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5423 | static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv, |
| 5424 | struct intel_crtc_state *crtc_state, |
| 5425 | int refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5426 | { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5427 | struct intel_encoder *encoder; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5428 | struct intel_digital_port *dig_port = NULL; |
| 5429 | struct intel_dp *intel_dp = dev_priv->drrs.dp; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5430 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5431 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5432 | |
| 5433 | if (refresh_rate <= 0) { |
| 5434 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); |
| 5435 | return; |
| 5436 | } |
| 5437 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5438 | if (intel_dp == NULL) { |
| 5439 | DRM_DEBUG_KMS("DRRS not supported.\n"); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5440 | return; |
| 5441 | } |
| 5442 | |
Daniel Vetter | 1fcc9d1 | 2014-07-11 10:30:10 -0700 | [diff] [blame] | 5443 | /* |
Rodrigo Vivi | e4d59f6 | 2014-11-20 02:22:08 -0800 | [diff] [blame] | 5444 | * FIXME: This needs proper synchronization with psr state for some |
| 5445 | * platforms that cannot have PSR and DRRS enabled at the same time. |
Daniel Vetter | 1fcc9d1 | 2014-07-11 10:30:10 -0700 | [diff] [blame] | 5446 | */ |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5447 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5448 | dig_port = dp_to_dig_port(intel_dp); |
| 5449 | encoder = &dig_port->base; |
Ander Conselvan de Oliveira | 723f9aa | 2015-03-20 16:18:18 +0200 | [diff] [blame] | 5450 | intel_crtc = to_intel_crtc(encoder->base.crtc); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5451 | |
| 5452 | if (!intel_crtc) { |
| 5453 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); |
| 5454 | return; |
| 5455 | } |
| 5456 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5457 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5458 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
| 5459 | return; |
| 5460 | } |
| 5461 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5462 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
| 5463 | refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5464 | index = DRRS_LOW_RR; |
| 5465 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5466 | if (index == dev_priv->drrs.refresh_rate_type) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5467 | DRM_DEBUG_KMS( |
| 5468 | "DRRS requested for previously set RR...ignoring\n"); |
| 5469 | return; |
| 5470 | } |
| 5471 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5472 | if (!crtc_state->base.active) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5473 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); |
| 5474 | return; |
| 5475 | } |
| 5476 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5477 | if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) { |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5478 | switch (index) { |
| 5479 | case DRRS_HIGH_RR: |
| 5480 | intel_dp_set_m_n(intel_crtc, M1_N1); |
| 5481 | break; |
| 5482 | case DRRS_LOW_RR: |
| 5483 | intel_dp_set_m_n(intel_crtc, M2_N2); |
| 5484 | break; |
| 5485 | case DRRS_MAX_RR: |
| 5486 | default: |
| 5487 | DRM_ERROR("Unsupported refreshrate type\n"); |
| 5488 | } |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5489 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 5490 | i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5491 | u32 val; |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5492 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5493 | val = I915_READ(reg); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5494 | if (index > DRRS_HIGH_RR) { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5495 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5496 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5497 | else |
| 5498 | val |= PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5499 | } else { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5500 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5501 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5502 | else |
| 5503 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5504 | } |
| 5505 | I915_WRITE(reg, val); |
| 5506 | } |
| 5507 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5508 | dev_priv->drrs.refresh_rate_type = index; |
| 5509 | |
| 5510 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); |
| 5511 | } |
| 5512 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5513 | /** |
| 5514 | * intel_edp_drrs_enable - init drrs struct if supported |
| 5515 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5516 | * @crtc_state: A pointer to the active crtc state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5517 | * |
| 5518 | * Initializes frontbuffer_bits and drrs.dp |
| 5519 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5520 | void intel_edp_drrs_enable(struct intel_dp *intel_dp, |
| 5521 | struct intel_crtc_state *crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5522 | { |
| 5523 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5524 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5525 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5526 | if (!crtc_state->has_drrs) { |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5527 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); |
| 5528 | return; |
| 5529 | } |
| 5530 | |
| 5531 | mutex_lock(&dev_priv->drrs.mutex); |
| 5532 | if (WARN_ON(dev_priv->drrs.dp)) { |
| 5533 | DRM_ERROR("DRRS already enabled\n"); |
| 5534 | goto unlock; |
| 5535 | } |
| 5536 | |
| 5537 | dev_priv->drrs.busy_frontbuffer_bits = 0; |
| 5538 | |
| 5539 | dev_priv->drrs.dp = intel_dp; |
| 5540 | |
| 5541 | unlock: |
| 5542 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5543 | } |
| 5544 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5545 | /** |
| 5546 | * intel_edp_drrs_disable - Disable DRRS |
| 5547 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5548 | * @old_crtc_state: Pointer to old crtc_state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5549 | * |
| 5550 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5551 | void intel_edp_drrs_disable(struct intel_dp *intel_dp, |
| 5552 | struct intel_crtc_state *old_crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5553 | { |
| 5554 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5555 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5556 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5557 | if (!old_crtc_state->has_drrs) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5558 | return; |
| 5559 | |
| 5560 | mutex_lock(&dev_priv->drrs.mutex); |
| 5561 | if (!dev_priv->drrs.dp) { |
| 5562 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5563 | return; |
| 5564 | } |
| 5565 | |
| 5566 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5567 | intel_dp_set_drrs_state(dev_priv, old_crtc_state, |
| 5568 | intel_dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5569 | |
| 5570 | dev_priv->drrs.dp = NULL; |
| 5571 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5572 | |
| 5573 | cancel_delayed_work_sync(&dev_priv->drrs.work); |
| 5574 | } |
| 5575 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5576 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
| 5577 | { |
| 5578 | struct drm_i915_private *dev_priv = |
| 5579 | container_of(work, typeof(*dev_priv), drrs.work.work); |
| 5580 | struct intel_dp *intel_dp; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5581 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5582 | mutex_lock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5583 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5584 | intel_dp = dev_priv->drrs.dp; |
| 5585 | |
| 5586 | if (!intel_dp) |
| 5587 | goto unlock; |
| 5588 | |
| 5589 | /* |
| 5590 | * The delayed work can race with an invalidate hence we need to |
| 5591 | * recheck. |
| 5592 | */ |
| 5593 | |
| 5594 | if (dev_priv->drrs.busy_frontbuffer_bits) |
| 5595 | goto unlock; |
| 5596 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5597 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) { |
| 5598 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 5599 | |
| 5600 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5601 | intel_dp->attached_connector->panel.downclock_mode->vrefresh); |
| 5602 | } |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5603 | |
| 5604 | unlock: |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5605 | mutex_unlock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5606 | } |
| 5607 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5608 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5609 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5610 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5611 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5612 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5613 | * This function gets called everytime rendering on the given planes start. |
| 5614 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5615 | * |
| 5616 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5617 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5618 | void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv, |
| 5619 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5620 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5621 | struct drm_crtc *crtc; |
| 5622 | enum pipe pipe; |
| 5623 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5624 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5625 | return; |
| 5626 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5627 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5628 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5629 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5630 | if (!dev_priv->drrs.dp) { |
| 5631 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5632 | return; |
| 5633 | } |
| 5634 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5635 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5636 | pipe = to_intel_crtc(crtc)->pipe; |
| 5637 | |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5638 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 5639 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; |
| 5640 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5641 | /* invalidate means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5642 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5643 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5644 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5645 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5646 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5647 | } |
| 5648 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5649 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5650 | * intel_edp_drrs_flush - Restart Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5651 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5652 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5653 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5654 | * This function gets called every time rendering on the given planes has |
| 5655 | * completed or flip on a crtc is completed. So DRRS should be upclocked |
| 5656 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, |
| 5657 | * if no other planes are dirty. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5658 | * |
| 5659 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5660 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5661 | void intel_edp_drrs_flush(struct drm_i915_private *dev_priv, |
| 5662 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5663 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5664 | struct drm_crtc *crtc; |
| 5665 | enum pipe pipe; |
| 5666 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5667 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5668 | return; |
| 5669 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5670 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5671 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5672 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5673 | if (!dev_priv->drrs.dp) { |
| 5674 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5675 | return; |
| 5676 | } |
| 5677 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5678 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5679 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5680 | |
| 5681 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5682 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 5683 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5684 | /* flush means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5685 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5686 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5687 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5688 | |
| 5689 | /* |
| 5690 | * flush also means no more activity hence schedule downclock, if all |
| 5691 | * other fbs are quiescent too |
| 5692 | */ |
| 5693 | if (!dev_priv->drrs.busy_frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5694 | schedule_delayed_work(&dev_priv->drrs.work, |
| 5695 | msecs_to_jiffies(1000)); |
| 5696 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5697 | } |
| 5698 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5699 | /** |
| 5700 | * DOC: Display Refresh Rate Switching (DRRS) |
| 5701 | * |
| 5702 | * Display Refresh Rate Switching (DRRS) is a power conservation feature |
| 5703 | * which enables swtching between low and high refresh rates, |
| 5704 | * dynamically, based on the usage scenario. This feature is applicable |
| 5705 | * for internal panels. |
| 5706 | * |
| 5707 | * Indication that the panel supports DRRS is given by the panel EDID, which |
| 5708 | * would list multiple refresh rates for one resolution. |
| 5709 | * |
| 5710 | * DRRS is of 2 types - static and seamless. |
| 5711 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset |
| 5712 | * (may appear as a blink on screen) and is used in dock-undock scenario. |
| 5713 | * Seamless DRRS involves changing RR without any visual effect to the user |
| 5714 | * and can be used during normal system usage. This is done by programming |
| 5715 | * certain registers. |
| 5716 | * |
| 5717 | * Support for static/seamless DRRS may be indicated in the VBT based on |
| 5718 | * inputs from the panel spec. |
| 5719 | * |
| 5720 | * DRRS saves power by switching to low RR based on usage scenarios. |
| 5721 | * |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 5722 | * The implementation is based on frontbuffer tracking implementation. When |
| 5723 | * there is a disturbance on the screen triggered by user activity or a periodic |
| 5724 | * system activity, DRRS is disabled (RR is changed to high RR). When there is |
| 5725 | * no movement on screen, after a timeout of 1 second, a switch to low RR is |
| 5726 | * made. |
| 5727 | * |
| 5728 | * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate() |
| 5729 | * and intel_edp_drrs_flush() are called. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5730 | * |
| 5731 | * DRRS can be further extended to support other internal panels and also |
| 5732 | * the scenario of video playback wherein RR is set based on the rate |
| 5733 | * requested by userspace. |
| 5734 | */ |
| 5735 | |
| 5736 | /** |
| 5737 | * intel_dp_drrs_init - Init basic DRRS work and mutex. |
| 5738 | * @intel_connector: eDP connector |
| 5739 | * @fixed_mode: preferred mode of panel |
| 5740 | * |
| 5741 | * This function is called only once at driver load to initialize basic |
| 5742 | * DRRS stuff. |
| 5743 | * |
| 5744 | * Returns: |
| 5745 | * Downclock mode if panel supports it, else return NULL. |
| 5746 | * DRRS support is determined by the presence of downclock mode (apart |
| 5747 | * from VBT setting). |
| 5748 | */ |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5749 | static struct drm_display_mode * |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5750 | intel_dp_drrs_init(struct intel_connector *intel_connector, |
| 5751 | struct drm_display_mode *fixed_mode) |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5752 | { |
| 5753 | struct drm_connector *connector = &intel_connector->base; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5754 | struct drm_device *dev = connector->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5755 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5756 | struct drm_display_mode *downclock_mode = NULL; |
| 5757 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5758 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
| 5759 | mutex_init(&dev_priv->drrs.mutex); |
| 5760 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5761 | if (INTEL_GEN(dev_priv) <= 6) { |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5762 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); |
| 5763 | return NULL; |
| 5764 | } |
| 5765 | |
| 5766 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5767 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5768 | return NULL; |
| 5769 | } |
| 5770 | |
| 5771 | downclock_mode = intel_find_panel_downclock |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 5772 | (dev_priv, fixed_mode, connector); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5773 | |
| 5774 | if (!downclock_mode) { |
Ramalingam C | a1d2634 | 2015-02-23 17:38:33 +0530 | [diff] [blame] | 5775 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5776 | return NULL; |
| 5777 | } |
| 5778 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5779 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5780 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5781 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5782 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5783 | return downclock_mode; |
| 5784 | } |
| 5785 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5786 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5787 | struct intel_connector *intel_connector) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5788 | { |
| 5789 | struct drm_connector *connector = &intel_connector->base; |
| 5790 | 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] | 5791 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5792 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5793 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5794 | struct drm_display_mode *fixed_mode = NULL; |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5795 | struct drm_display_mode *downclock_mode = NULL; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5796 | bool has_dpcd; |
| 5797 | struct drm_display_mode *scan; |
| 5798 | struct edid *edid; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5799 | enum pipe pipe = INVALID_PIPE; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5800 | |
| 5801 | if (!is_edp(intel_dp)) |
| 5802 | return true; |
| 5803 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 5804 | /* |
| 5805 | * On IBX/CPT we may get here with LVDS already registered. Since the |
| 5806 | * driver uses the only internal power sequencer available for both |
| 5807 | * eDP and LVDS bail out early in this case to prevent interfering |
| 5808 | * with an already powered-on LVDS power sequencer. |
| 5809 | */ |
| 5810 | if (intel_get_lvds_encoder(dev)) { |
| 5811 | WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))); |
| 5812 | DRM_INFO("LVDS was detected, not registering eDP\n"); |
| 5813 | |
| 5814 | return false; |
| 5815 | } |
| 5816 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5817 | pps_lock(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5818 | |
| 5819 | intel_dp_init_panel_power_timestamps(intel_dp); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5820 | intel_dp_pps_init(dev, intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5821 | intel_edp_panel_vdd_sanitize(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5822 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5823 | pps_unlock(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5824 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5825 | /* Cache DPCD and EDID for edp. */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5826 | has_dpcd = intel_edp_init_dpcd(intel_dp); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5827 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5828 | if (!has_dpcd) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5829 | /* if this fails, presume the device is a ghost */ |
| 5830 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5831 | goto out_vdd_off; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5832 | } |
| 5833 | |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5834 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 5835 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5836 | if (edid) { |
| 5837 | if (drm_add_edid_modes(connector, edid)) { |
| 5838 | drm_mode_connector_update_edid_property(connector, |
| 5839 | edid); |
| 5840 | drm_edid_to_eld(connector, edid); |
| 5841 | } else { |
| 5842 | kfree(edid); |
| 5843 | edid = ERR_PTR(-EINVAL); |
| 5844 | } |
| 5845 | } else { |
| 5846 | edid = ERR_PTR(-ENOENT); |
| 5847 | } |
| 5848 | intel_connector->edid = edid; |
| 5849 | |
| 5850 | /* prefer fixed mode from EDID if available */ |
| 5851 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 5852 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 5853 | fixed_mode = drm_mode_duplicate(dev, scan); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5854 | downclock_mode = intel_dp_drrs_init( |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5855 | intel_connector, fixed_mode); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5856 | break; |
| 5857 | } |
| 5858 | } |
| 5859 | |
| 5860 | /* fallback to VBT if available for eDP */ |
| 5861 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { |
| 5862 | fixed_mode = drm_mode_duplicate(dev, |
| 5863 | dev_priv->vbt.lfp_lvds_vbt_mode); |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5864 | if (fixed_mode) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5865 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5866 | connector->display_info.width_mm = fixed_mode->width_mm; |
| 5867 | connector->display_info.height_mm = fixed_mode->height_mm; |
| 5868 | } |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5869 | } |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5870 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5871 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5872 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5873 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
| 5874 | register_reboot_notifier(&intel_dp->edp_notifier); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5875 | |
| 5876 | /* |
| 5877 | * Figure out the current pipe for the initial backlight setup. |
| 5878 | * If the current pipe isn't valid, try the PPS pipe, and if that |
| 5879 | * fails just assume pipe A. |
| 5880 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5881 | pipe = vlv_active_pipe(intel_dp); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5882 | |
| 5883 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5884 | pipe = intel_dp->pps_pipe; |
| 5885 | |
| 5886 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5887 | pipe = PIPE_A; |
| 5888 | |
| 5889 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", |
| 5890 | pipe_name(pipe)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5891 | } |
| 5892 | |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5893 | intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 5894 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5895 | intel_panel_setup_backlight(connector, pipe); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5896 | |
| 5897 | return true; |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5898 | |
| 5899 | out_vdd_off: |
| 5900 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 5901 | /* |
| 5902 | * vdd might still be enabled do to the delayed vdd off. |
| 5903 | * Make sure vdd is actually turned off here. |
| 5904 | */ |
| 5905 | pps_lock(intel_dp); |
| 5906 | edp_panel_vdd_off_sync(intel_dp); |
| 5907 | pps_unlock(intel_dp); |
| 5908 | |
| 5909 | return false; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5910 | } |
| 5911 | |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5912 | static void |
| 5913 | intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port) |
| 5914 | { |
| 5915 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 5916 | |
| 5917 | /* Set up the hotplug pin. */ |
| 5918 | switch (intel_dig_port->port) { |
| 5919 | case PORT_A: |
| 5920 | encoder->hpd_pin = HPD_PORT_A; |
| 5921 | break; |
| 5922 | case PORT_B: |
| 5923 | encoder->hpd_pin = HPD_PORT_B; |
| 5924 | break; |
| 5925 | case PORT_C: |
| 5926 | encoder->hpd_pin = HPD_PORT_C; |
| 5927 | break; |
| 5928 | case PORT_D: |
| 5929 | encoder->hpd_pin = HPD_PORT_D; |
| 5930 | break; |
| 5931 | case PORT_E: |
| 5932 | encoder->hpd_pin = HPD_PORT_E; |
| 5933 | break; |
| 5934 | default: |
| 5935 | MISSING_CASE(intel_dig_port->port); |
| 5936 | } |
| 5937 | } |
| 5938 | |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 5939 | bool |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5940 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
| 5941 | struct intel_connector *intel_connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5942 | { |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5943 | struct drm_connector *connector = &intel_connector->base; |
| 5944 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 5945 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5946 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5947 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 5948 | enum port port = intel_dig_port->port; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5949 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5950 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 5951 | if (WARN(intel_dig_port->max_lanes < 1, |
| 5952 | "Not enough lanes (%d) for DP on port %c\n", |
| 5953 | intel_dig_port->max_lanes, port_name(port))) |
| 5954 | return false; |
| 5955 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5956 | intel_dp->reset_link_params = true; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 5957 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5958 | intel_dp->active_pipe = INVALID_PIPE; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 5959 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5960 | /* intel_dp vfuncs */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5961 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 5962 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5963 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5964 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5965 | else if (HAS_PCH_SPLIT(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5966 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; |
| 5967 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 5968 | intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider; |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5969 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5970 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 5971 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; |
| 5972 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 5973 | intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl; |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 5974 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5975 | if (HAS_DDI(dev_priv)) |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 5976 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; |
| 5977 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 5978 | /* Preserve the current hw state. */ |
| 5979 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 5980 | intel_dp->attached_connector = intel_connector; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 5981 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5982 | if (intel_dp_is_edp(dev_priv, port)) |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 5983 | type = DRM_MODE_CONNECTOR_eDP; |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5984 | else |
| 5985 | type = DRM_MODE_CONNECTOR_DisplayPort; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 5986 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5987 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5988 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 5989 | |
Imre Deak | f7d2490 | 2013-05-08 13:14:05 +0300 | [diff] [blame] | 5990 | /* |
| 5991 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but |
| 5992 | * for DP the encoder type can be set by the caller to |
| 5993 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. |
| 5994 | */ |
| 5995 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 5996 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 5997 | |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 5998 | /* eDP only on port B and/or C on vlv/chv */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5999 | if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 6000 | is_edp(intel_dp) && port != PORT_B && port != PORT_C)) |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6001 | return false; |
| 6002 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 6003 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
| 6004 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", |
| 6005 | port_name(port)); |
| 6006 | |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6007 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6008 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 6009 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6010 | connector->interlace_allowed = true; |
| 6011 | connector->doublescan_allowed = 0; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 6012 | |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 6013 | intel_dp_aux_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6014 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 6015 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 6016 | edp_panel_vdd_work); |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 6017 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6018 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6019 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6020 | if (HAS_DDI(dev_priv)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 6021 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 6022 | else |
| 6023 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
| 6024 | |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 6025 | intel_dp_init_connector_port_info(intel_dig_port); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 6026 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6027 | /* init MST on ports that can support it */ |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 6028 | if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) && |
Jani Nikula | 0c9b371 | 2015-05-18 17:10:01 +0300 | [diff] [blame] | 6029 | (port == PORT_B || port == PORT_C || port == PORT_D)) |
| 6030 | intel_dp_mst_encoder_init(intel_dig_port, |
| 6031 | intel_connector->base.base.id); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6032 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 6033 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6034 | intel_dp_aux_fini(intel_dp); |
| 6035 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
| 6036 | goto fail; |
Paulo Zanoni | b2f246a | 2013-06-12 17:27:26 -0300 | [diff] [blame] | 6037 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 6038 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 6039 | intel_dp_add_properties(intel_dp, connector); |
| 6040 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6041 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 6042 | * 0xd. Failure to do so will result in spurious interrupts being |
| 6043 | * generated on the port when a cable is not attached. |
| 6044 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6045 | if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6046 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 6047 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 6048 | } |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6049 | |
| 6050 | return true; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6051 | |
| 6052 | fail: |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6053 | drm_connector_cleanup(connector); |
| 6054 | |
| 6055 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6056 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6057 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6058 | bool intel_dp_init(struct drm_i915_private *dev_priv, |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6059 | i915_reg_t output_reg, |
| 6060 | enum port port) |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6061 | { |
| 6062 | struct intel_digital_port *intel_dig_port; |
| 6063 | struct intel_encoder *intel_encoder; |
| 6064 | struct drm_encoder *encoder; |
| 6065 | struct intel_connector *intel_connector; |
| 6066 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 6067 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6068 | if (!intel_dig_port) |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6069 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6070 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6071 | intel_connector = intel_connector_alloc(); |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6072 | if (!intel_connector) |
| 6073 | goto err_connector_alloc; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6074 | |
| 6075 | intel_encoder = &intel_dig_port->base; |
| 6076 | encoder = &intel_encoder->base; |
| 6077 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6078 | if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, |
| 6079 | &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, |
| 6080 | "DP %c", port_name(port))) |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6081 | goto err_encoder_init; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6082 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 6083 | intel_encoder->compute_config = intel_dp_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6084 | intel_encoder->disable = intel_disable_dp; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6085 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 6086 | intel_encoder->get_config = intel_dp_get_config; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 6087 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6088 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 6089 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 6090 | intel_encoder->pre_enable = chv_pre_enable_dp; |
| 6091 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 6092 | intel_encoder->post_disable = chv_post_disable_dp; |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6093 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6094 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6095 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6096 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
| 6097 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 6098 | intel_encoder->post_disable = vlv_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6099 | } else { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6100 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6101 | intel_encoder->enable = g4x_enable_dp; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6102 | if (INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 6103 | intel_encoder->post_disable = ilk_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6104 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6105 | |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 6106 | intel_dig_port->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6107 | intel_dig_port->dp.output_reg = output_reg; |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6108 | intel_dig_port->max_lanes = 4; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6109 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 6110 | intel_encoder->type = INTEL_OUTPUT_DP; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6111 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 882ec38 | 2014-04-28 14:07:43 +0300 | [diff] [blame] | 6112 | if (port == PORT_D) |
| 6113 | intel_encoder->crtc_mask = 1 << 2; |
| 6114 | else |
| 6115 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
| 6116 | } else { |
| 6117 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 6118 | } |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 6119 | intel_encoder->cloneable = 0; |
Pandiyan, Dhinakaran | 03cdc1d | 2016-09-19 18:24:38 -0700 | [diff] [blame] | 6120 | intel_encoder->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6121 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6122 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6123 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6124 | |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6125 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
| 6126 | goto err_init_connector; |
| 6127 | |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6128 | return true; |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6129 | |
| 6130 | err_init_connector: |
| 6131 | drm_encoder_cleanup(encoder); |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6132 | err_encoder_init: |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6133 | kfree(intel_connector); |
| 6134 | err_connector_alloc: |
| 6135 | kfree(intel_dig_port); |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6136 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6137 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6138 | |
| 6139 | void intel_dp_mst_suspend(struct drm_device *dev) |
| 6140 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6141 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6142 | int i; |
| 6143 | |
| 6144 | /* disable MST */ |
| 6145 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6146 | 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] | 6147 | |
| 6148 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6149 | continue; |
| 6150 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6151 | if (intel_dig_port->dp.is_mst) |
| 6152 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | void intel_dp_mst_resume(struct drm_device *dev) |
| 6157 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6158 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6159 | int i; |
| 6160 | |
| 6161 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6162 | 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] | 6163 | int ret; |
| 6164 | |
| 6165 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6166 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6167 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6168 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); |
| 6169 | if (ret) |
| 6170 | intel_dp_check_mst_status(&intel_dig_port->dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6171 | } |
| 6172 | } |