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 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 136 | static int intel_dp_num_rates(u8 link_bw_code) |
| 137 | { |
| 138 | switch (link_bw_code) { |
| 139 | default: |
| 140 | WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n", |
| 141 | link_bw_code); |
| 142 | case DP_LINK_BW_1_62: |
| 143 | return 1; |
| 144 | case DP_LINK_BW_2_7: |
| 145 | return 2; |
| 146 | case DP_LINK_BW_5_4: |
| 147 | return 3; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /* update sink rates from dpcd */ |
| 152 | static void intel_dp_set_sink_rates(struct intel_dp *intel_dp) |
| 153 | { |
| 154 | int i, num_rates; |
| 155 | |
| 156 | num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]); |
| 157 | |
| 158 | for (i = 0; i < num_rates; i++) |
| 159 | intel_dp->sink_rates[i] = default_rates[i]; |
| 160 | |
| 161 | intel_dp->num_sink_rates = num_rates; |
| 162 | } |
| 163 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 164 | static int |
| 165 | intel_dp_max_link_bw(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 166 | { |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 167 | int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 168 | |
| 169 | switch (max_link_bw) { |
| 170 | case DP_LINK_BW_1_62: |
| 171 | case DP_LINK_BW_2_7: |
Ville Syrjälä | 1db10e2 | 2015-03-12 17:10:32 +0200 | [diff] [blame] | 172 | case DP_LINK_BW_5_4: |
Imre Deak | d4eead5 | 2013-07-09 17:05:26 +0300 | [diff] [blame] | 173 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 174 | default: |
Imre Deak | d4eead5 | 2013-07-09 17:05:26 +0300 | [diff] [blame] | 175 | WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n", |
| 176 | max_link_bw); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 177 | max_link_bw = DP_LINK_BW_1_62; |
| 178 | break; |
| 179 | } |
| 180 | return max_link_bw; |
| 181 | } |
| 182 | |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 183 | static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp) |
| 184 | { |
| 185 | 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] | 186 | u8 source_max, sink_max; |
| 187 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 188 | source_max = intel_dig_port->max_lanes; |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 189 | sink_max = intel_dp->max_sink_lane_count; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 190 | |
| 191 | return min(source_max, sink_max); |
| 192 | } |
| 193 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 194 | int |
Keith Packard | c898261 | 2012-01-25 08:16:25 -0800 | [diff] [blame] | 195 | intel_dp_link_required(int pixel_clock, int bpp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 196 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 197 | /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */ |
| 198 | return DIV_ROUND_UP(pixel_clock * bpp, 8); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 201 | int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 202 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 203 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 204 | /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the |
| 205 | * link rate that is generally expressed in Gbps. Since, 8 bits of data |
| 206 | * is transmitted every LS_Clk per lane, there is no need to account for |
| 207 | * the channel encoding that is done in the PHY layer here. |
| 208 | */ |
| 209 | |
| 210 | return max_link_clock * max_lanes; |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 211 | } |
| 212 | |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 213 | static int |
| 214 | intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp) |
| 215 | { |
| 216 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 217 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 218 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 219 | int max_dotclk = dev_priv->max_dotclk_freq; |
| 220 | int ds_max_dotclk; |
| 221 | |
| 222 | int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 223 | |
| 224 | if (type != DP_DS_PORT_TYPE_VGA) |
| 225 | return max_dotclk; |
| 226 | |
| 227 | ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd, |
| 228 | intel_dp->downstream_ports); |
| 229 | |
| 230 | if (ds_max_dotclk != 0) |
| 231 | max_dotclk = min(max_dotclk, ds_max_dotclk); |
| 232 | |
| 233 | return max_dotclk; |
| 234 | } |
| 235 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 236 | static void |
| 237 | intel_dp_set_source_rates(struct intel_dp *intel_dp) |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 238 | { |
| 239 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 240 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 241 | const int *source_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 242 | int size; |
| 243 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 244 | /* This should only be done once */ |
| 245 | WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates); |
| 246 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 247 | if (IS_GEN9_LP(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 248 | source_rates = bxt_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 249 | size = ARRAY_SIZE(bxt_rates); |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 250 | } else if (IS_GEN9_BC(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 251 | source_rates = skl_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 252 | size = ARRAY_SIZE(skl_rates); |
| 253 | } else { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 254 | source_rates = default_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 255 | size = ARRAY_SIZE(default_rates); |
| 256 | } |
| 257 | |
| 258 | /* This depends on the fact that 5.4 is last value in the array */ |
| 259 | if (!intel_dp_source_supports_hbr2(intel_dp)) |
| 260 | size--; |
| 261 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 262 | intel_dp->source_rates = source_rates; |
| 263 | intel_dp->num_source_rates = size; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static int intersect_rates(const int *source_rates, int source_len, |
| 267 | const int *sink_rates, int sink_len, |
| 268 | int *common_rates) |
| 269 | { |
| 270 | int i = 0, j = 0, k = 0; |
| 271 | |
| 272 | while (i < source_len && j < sink_len) { |
| 273 | if (source_rates[i] == sink_rates[j]) { |
| 274 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
| 275 | return k; |
| 276 | common_rates[k] = source_rates[i]; |
| 277 | ++k; |
| 278 | ++i; |
| 279 | ++j; |
| 280 | } else if (source_rates[i] < sink_rates[j]) { |
| 281 | ++i; |
| 282 | } else { |
| 283 | ++j; |
| 284 | } |
| 285 | } |
| 286 | return k; |
| 287 | } |
| 288 | |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 289 | /* return index of rate in rates array, or -1 if not found */ |
| 290 | static int intel_dp_rate_index(const int *rates, int len, int rate) |
| 291 | { |
| 292 | int i; |
| 293 | |
| 294 | for (i = 0; i < len; i++) |
| 295 | if (rate == rates[i]) |
| 296 | return i; |
| 297 | |
| 298 | return -1; |
| 299 | } |
| 300 | |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 301 | static int intel_dp_common_rates(struct intel_dp *intel_dp, |
| 302 | int *common_rates) |
| 303 | { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 304 | int max_rate = drm_dp_bw_code_to_link_rate(intel_dp->max_sink_link_bw); |
| 305 | int i, common_len; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 306 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 307 | common_len = intersect_rates(intel_dp->source_rates, |
| 308 | intel_dp->num_source_rates, |
| 309 | intel_dp->sink_rates, |
| 310 | intel_dp->num_sink_rates, |
| 311 | common_rates); |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 312 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 313 | /* Limit results by potentially reduced max rate */ |
| 314 | for (i = 0; i < common_len; i++) { |
| 315 | if (common_rates[common_len - i - 1] <= max_rate) |
| 316 | return common_len - i; |
| 317 | } |
| 318 | |
| 319 | return 0; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 322 | static int intel_dp_link_rate_index(struct intel_dp *intel_dp, |
| 323 | int *common_rates, int link_rate) |
| 324 | { |
| 325 | int common_len; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 326 | |
| 327 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 328 | |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 329 | return intel_dp_rate_index(common_rates, common_len, link_rate); |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, |
| 333 | int link_rate, uint8_t lane_count) |
| 334 | { |
| 335 | int common_rates[DP_MAX_SUPPORTED_RATES]; |
| 336 | int link_rate_index; |
| 337 | |
| 338 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 339 | common_rates, |
| 340 | link_rate); |
| 341 | if (link_rate_index > 0) { |
| 342 | intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]); |
| 343 | intel_dp->max_sink_lane_count = lane_count; |
| 344 | } else if (lane_count > 1) { |
| 345 | intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp); |
| 346 | intel_dp->max_sink_lane_count = lane_count >> 1; |
| 347 | } else { |
| 348 | DRM_ERROR("Link Training Unsuccessful\n"); |
| 349 | return -1; |
| 350 | } |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 355 | static enum drm_mode_status |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 356 | intel_dp_mode_valid(struct drm_connector *connector, |
| 357 | struct drm_display_mode *mode) |
| 358 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 359 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 360 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 361 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 362 | int target_clock = mode->clock; |
| 363 | int max_rate, mode_rate, max_lanes, max_link_clock; |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 364 | int max_dotclk; |
| 365 | |
| 366 | max_dotclk = intel_dp_downstream_max_dotclock(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 367 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 368 | if (is_edp(intel_dp) && fixed_mode) { |
| 369 | if (mode->hdisplay > fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 370 | return MODE_PANEL; |
| 371 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 372 | if (mode->vdisplay > fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 373 | return MODE_PANEL; |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 374 | |
| 375 | target_clock = fixed_mode->clock; |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 376 | } |
| 377 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 378 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 379 | max_lanes = intel_dp_max_lane_count(intel_dp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 380 | |
| 381 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); |
| 382 | mode_rate = intel_dp_link_required(target_clock, 18); |
| 383 | |
Mika Kahola | 799487f | 2016-02-02 15:16:38 +0200 | [diff] [blame] | 384 | if (mode_rate > max_rate || target_clock > max_dotclk) |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 385 | return MODE_CLOCK_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 386 | |
| 387 | if (mode->clock < 10000) |
| 388 | return MODE_CLOCK_LOW; |
| 389 | |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 390 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 391 | return MODE_H_ILLEGAL; |
| 392 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 393 | return MODE_OK; |
| 394 | } |
| 395 | |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 396 | 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] | 397 | { |
| 398 | int i; |
| 399 | uint32_t v = 0; |
| 400 | |
| 401 | if (src_bytes > 4) |
| 402 | src_bytes = 4; |
| 403 | for (i = 0; i < src_bytes; i++) |
| 404 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 405 | return v; |
| 406 | } |
| 407 | |
Damien Lespiau | c2af70e | 2015-02-10 19:32:23 +0000 | [diff] [blame] | 408 | 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] | 409 | { |
| 410 | int i; |
| 411 | if (dst_bytes > 4) |
| 412 | dst_bytes = 4; |
| 413 | for (i = 0; i < dst_bytes; i++) |
| 414 | dst[i] = src >> ((3-i) * 8); |
| 415 | } |
| 416 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 417 | static void |
| 418 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 419 | struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 420 | static void |
| 421 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 422 | struct intel_dp *intel_dp, |
| 423 | bool force_disable_vdd); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 424 | static void |
| 425 | 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] | 426 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 427 | static void pps_lock(struct intel_dp *intel_dp) |
| 428 | { |
| 429 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 430 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 431 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 432 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 433 | |
| 434 | /* |
| 435 | * See vlv_power_sequencer_reset() why we need |
| 436 | * a power domain reference here. |
| 437 | */ |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 438 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 439 | |
| 440 | mutex_lock(&dev_priv->pps_mutex); |
| 441 | } |
| 442 | |
| 443 | static void pps_unlock(struct intel_dp *intel_dp) |
| 444 | { |
| 445 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 446 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 447 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 448 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 449 | |
| 450 | mutex_unlock(&dev_priv->pps_mutex); |
| 451 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 452 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 453 | } |
| 454 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 455 | static void |
| 456 | vlv_power_sequencer_kick(struct intel_dp *intel_dp) |
| 457 | { |
| 458 | 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] | 459 | 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] | 460 | enum pipe pipe = intel_dp->pps_pipe; |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 461 | bool pll_enabled, release_cl_override = false; |
| 462 | enum dpio_phy phy = DPIO_PHY(pipe); |
| 463 | enum dpio_channel ch = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 464 | uint32_t DP; |
| 465 | |
| 466 | if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN, |
| 467 | "skipping pipe %c power seqeuncer kick due to port %c being active\n", |
| 468 | pipe_name(pipe), port_name(intel_dig_port->port))) |
| 469 | return; |
| 470 | |
| 471 | DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n", |
| 472 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 473 | |
| 474 | /* Preserve the BIOS-computed detected bit. This is |
| 475 | * supposed to be read-only. |
| 476 | */ |
| 477 | DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
| 478 | DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
| 479 | DP |= DP_PORT_WIDTH(1); |
| 480 | DP |= DP_LINK_TRAIN_PAT_1; |
| 481 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 482 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 483 | DP |= DP_PIPE_SELECT_CHV(pipe); |
| 484 | else if (pipe == PIPE_B) |
| 485 | DP |= DP_PIPEB_SELECT; |
| 486 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 487 | pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE; |
| 488 | |
| 489 | /* |
| 490 | * The DPLL for the pipe must be enabled for this to work. |
| 491 | * So enable temporarily it if it's not already enabled. |
| 492 | */ |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 493 | if (!pll_enabled) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 494 | release_cl_override = IS_CHERRYVIEW(dev_priv) && |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 495 | !chv_phy_powergate_ch(dev_priv, phy, ch, true); |
| 496 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 497 | if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ? |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 498 | &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) { |
| 499 | DRM_ERROR("Failed to force on pll for pipe %c!\n", |
| 500 | pipe_name(pipe)); |
| 501 | return; |
| 502 | } |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 503 | } |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 504 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 505 | /* |
| 506 | * Similar magic as in intel_dp_enable_port(). |
| 507 | * We _must_ do this port enable + disable trick |
| 508 | * to make this power seqeuencer lock onto the port. |
| 509 | * Otherwise even VDD force bit won't work. |
| 510 | */ |
| 511 | I915_WRITE(intel_dp->output_reg, DP); |
| 512 | POSTING_READ(intel_dp->output_reg); |
| 513 | |
| 514 | I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN); |
| 515 | POSTING_READ(intel_dp->output_reg); |
| 516 | |
| 517 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
| 518 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 519 | |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 520 | if (!pll_enabled) { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 521 | vlv_force_pll_off(dev_priv, pipe); |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 522 | |
| 523 | if (release_cl_override) |
| 524 | chv_phy_powergate_ch(dev_priv, phy, ch, false); |
| 525 | } |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 526 | } |
| 527 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 528 | static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv) |
| 529 | { |
| 530 | struct intel_encoder *encoder; |
| 531 | unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); |
| 532 | |
| 533 | /* |
| 534 | * We don't have power sequencer currently. |
| 535 | * Pick one that's not used by other ports. |
| 536 | */ |
| 537 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 538 | struct intel_dp *intel_dp; |
| 539 | |
| 540 | if (encoder->type != INTEL_OUTPUT_DP && |
| 541 | encoder->type != INTEL_OUTPUT_EDP) |
| 542 | continue; |
| 543 | |
| 544 | intel_dp = enc_to_intel_dp(&encoder->base); |
| 545 | |
| 546 | if (encoder->type == INTEL_OUTPUT_EDP) { |
| 547 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 548 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 549 | |
| 550 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 551 | pipes &= ~(1 << intel_dp->pps_pipe); |
| 552 | } else { |
| 553 | WARN_ON(intel_dp->pps_pipe != INVALID_PIPE); |
| 554 | |
| 555 | if (intel_dp->active_pipe != INVALID_PIPE) |
| 556 | pipes &= ~(1 << intel_dp->active_pipe); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | if (pipes == 0) |
| 561 | return INVALID_PIPE; |
| 562 | |
| 563 | return ffs(pipes) - 1; |
| 564 | } |
| 565 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 566 | static enum pipe |
| 567 | vlv_power_sequencer_pipe(struct intel_dp *intel_dp) |
| 568 | { |
| 569 | 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] | 570 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 571 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 572 | enum pipe pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 573 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 574 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 575 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 576 | /* We should never land here with regular DP ports */ |
| 577 | WARN_ON(!is_edp(intel_dp)); |
| 578 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 579 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 580 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 581 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 582 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 583 | return intel_dp->pps_pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 584 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 585 | pipe = vlv_find_free_pps(dev_priv); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * Didn't find one. This should not happen since there |
| 589 | * are two power sequencers and up to two eDP ports. |
| 590 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 591 | if (WARN_ON(pipe == INVALID_PIPE)) |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 592 | pipe = PIPE_A; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 593 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 594 | vlv_steal_power_sequencer(dev, pipe); |
| 595 | intel_dp->pps_pipe = pipe; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 596 | |
| 597 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", |
| 598 | pipe_name(intel_dp->pps_pipe), |
| 599 | port_name(intel_dig_port->port)); |
| 600 | |
| 601 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 602 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 603 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 604 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 605 | /* |
| 606 | * Even vdd force doesn't work until we've made |
| 607 | * the power sequencer lock in on the port. |
| 608 | */ |
| 609 | vlv_power_sequencer_kick(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 610 | |
| 611 | return intel_dp->pps_pipe; |
| 612 | } |
| 613 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 614 | static int |
| 615 | bxt_power_sequencer_idx(struct intel_dp *intel_dp) |
| 616 | { |
| 617 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 618 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 619 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 620 | |
| 621 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 622 | |
| 623 | /* We should never land here with regular DP ports */ |
| 624 | WARN_ON(!is_edp(intel_dp)); |
| 625 | |
| 626 | /* |
| 627 | * TODO: BXT has 2 PPS instances. The correct port->PPS instance |
| 628 | * mapping needs to be retrieved from VBT, for now just hard-code to |
| 629 | * use instance #0 always. |
| 630 | */ |
| 631 | if (!intel_dp->pps_reset) |
| 632 | return 0; |
| 633 | |
| 634 | intel_dp->pps_reset = false; |
| 635 | |
| 636 | /* |
| 637 | * Only the HW needs to be reprogrammed, the SW state is fixed and |
| 638 | * has been setup during connector init. |
| 639 | */ |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 640 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 645 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
| 646 | enum pipe pipe); |
| 647 | |
| 648 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, |
| 649 | enum pipe pipe) |
| 650 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 651 | return I915_READ(PP_STATUS(pipe)) & PP_ON; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, |
| 655 | enum pipe pipe) |
| 656 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 657 | return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, |
| 661 | enum pipe pipe) |
| 662 | { |
| 663 | return true; |
| 664 | } |
| 665 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 666 | static enum pipe |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 667 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
| 668 | enum port port, |
| 669 | vlv_pipe_check pipe_check) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 670 | { |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 671 | enum pipe pipe; |
| 672 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 673 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 674 | u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) & |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 675 | PANEL_PORT_SELECT_MASK; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 676 | |
| 677 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) |
| 678 | continue; |
| 679 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 680 | if (!pipe_check(dev_priv, pipe)) |
| 681 | continue; |
| 682 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 683 | return pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 684 | } |
| 685 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 686 | return INVALID_PIPE; |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) |
| 691 | { |
| 692 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 693 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 694 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 695 | enum port port = intel_dig_port->port; |
| 696 | |
| 697 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 698 | |
| 699 | /* try to find a pipe with this port selected */ |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 700 | /* first pick one where the panel is on */ |
| 701 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 702 | vlv_pipe_has_pp_on); |
| 703 | /* didn't find one? pick one where vdd is on */ |
| 704 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 705 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 706 | vlv_pipe_has_vdd_on); |
| 707 | /* didn't find one? pick one with just the correct port */ |
| 708 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 709 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 710 | vlv_pipe_any); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 711 | |
| 712 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ |
| 713 | if (intel_dp->pps_pipe == INVALID_PIPE) { |
| 714 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", |
| 715 | port_name(port)); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
| 720 | port_name(port), pipe_name(intel_dp->pps_pipe)); |
| 721 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 722 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 723 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 724 | } |
| 725 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 726 | void intel_power_sequencer_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 727 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 728 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 729 | struct intel_encoder *encoder; |
| 730 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 731 | 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] | 732 | !IS_GEN9_LP(dev_priv))) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 733 | return; |
| 734 | |
| 735 | /* |
| 736 | * We can't grab pps_mutex here due to deadlock with power_domain |
| 737 | * mutex when power_domain functions are called while holding pps_mutex. |
| 738 | * That also means that in order to use pps_pipe the code needs to |
| 739 | * hold both a power domain reference and pps_mutex, and the power domain |
| 740 | * reference get/put must be done while _not_ holding pps_mutex. |
| 741 | * pps_{lock,unlock}() do these steps in the correct order, so one |
| 742 | * should use them always. |
| 743 | */ |
| 744 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 745 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 746 | struct intel_dp *intel_dp; |
| 747 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 748 | if (encoder->type != INTEL_OUTPUT_DP && |
| 749 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 750 | continue; |
| 751 | |
| 752 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 753 | |
| 754 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 755 | |
| 756 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 757 | continue; |
| 758 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 759 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 760 | intel_dp->pps_reset = true; |
| 761 | else |
| 762 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 763 | } |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 764 | } |
| 765 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 766 | struct pps_registers { |
| 767 | i915_reg_t pp_ctrl; |
| 768 | i915_reg_t pp_stat; |
| 769 | i915_reg_t pp_on; |
| 770 | i915_reg_t pp_off; |
| 771 | i915_reg_t pp_div; |
| 772 | }; |
| 773 | |
| 774 | static void intel_pps_get_registers(struct drm_i915_private *dev_priv, |
| 775 | struct intel_dp *intel_dp, |
| 776 | struct pps_registers *regs) |
| 777 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 778 | int pps_idx = 0; |
| 779 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 780 | memset(regs, 0, sizeof(*regs)); |
| 781 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 782 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 783 | pps_idx = bxt_power_sequencer_idx(intel_dp); |
| 784 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 785 | pps_idx = vlv_power_sequencer_pipe(intel_dp); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 786 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 787 | regs->pp_ctrl = PP_CONTROL(pps_idx); |
| 788 | regs->pp_stat = PP_STATUS(pps_idx); |
| 789 | regs->pp_on = PP_ON_DELAYS(pps_idx); |
| 790 | regs->pp_off = PP_OFF_DELAYS(pps_idx); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 791 | if (!IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 792 | regs->pp_div = PP_DIVISOR(pps_idx); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 793 | } |
| 794 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 795 | static i915_reg_t |
| 796 | _pp_ctrl_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 797 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 798 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 799 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 800 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 801 | ®s); |
| 802 | |
| 803 | return regs.pp_ctrl; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 804 | } |
| 805 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 806 | static i915_reg_t |
| 807 | _pp_stat_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 808 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 809 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 810 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 811 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 812 | ®s); |
| 813 | |
| 814 | return regs.pp_stat; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 815 | } |
| 816 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 817 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
| 818 | This function only applicable when panel PM state is not to be tracked */ |
| 819 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, |
| 820 | void *unused) |
| 821 | { |
| 822 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), |
| 823 | edp_notifier); |
| 824 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 825 | struct drm_i915_private *dev_priv = to_i915(dev); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 826 | |
| 827 | if (!is_edp(intel_dp) || code != SYS_RESTART) |
| 828 | return 0; |
| 829 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 830 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 831 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 832 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 833 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 834 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 835 | u32 pp_div; |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 836 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 837 | pp_ctrl_reg = PP_CONTROL(pipe); |
| 838 | pp_div_reg = PP_DIVISOR(pipe); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 839 | pp_div = I915_READ(pp_div_reg); |
| 840 | pp_div &= PP_REFERENCE_DIVIDER_MASK; |
| 841 | |
| 842 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ |
| 843 | I915_WRITE(pp_div_reg, pp_div | 0x1F); |
| 844 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 845 | msleep(intel_dp->panel_power_cycle_delay); |
| 846 | } |
| 847 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 848 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 849 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 850 | return 0; |
| 851 | } |
| 852 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 853 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 854 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 855 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 856 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 857 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 858 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 859 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 860 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 861 | intel_dp->pps_pipe == INVALID_PIPE) |
| 862 | return false; |
| 863 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 864 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 867 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 868 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 869 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 870 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 871 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 872 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 873 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 874 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 875 | intel_dp->pps_pipe == INVALID_PIPE) |
| 876 | return false; |
| 877 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 878 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 881 | static void |
| 882 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 883 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 884 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 885 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 886 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 887 | if (!is_edp(intel_dp)) |
| 888 | return; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 889 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 890 | 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] | 891 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 892 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 893 | I915_READ(_pp_stat_reg(intel_dp)), |
| 894 | I915_READ(_pp_ctrl_reg(intel_dp))); |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 898 | static uint32_t |
| 899 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) |
| 900 | { |
| 901 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 902 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 903 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 904 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 905 | uint32_t status; |
| 906 | bool done; |
| 907 | |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 908 | #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] | 909 | if (has_aux_irq) |
Paulo Zanoni | b18ac46 | 2013-02-18 19:00:24 -0300 | [diff] [blame] | 910 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
Imre Deak | 3598706 | 2013-05-21 20:03:20 +0300 | [diff] [blame] | 911 | msecs_to_jiffies_timeout(10)); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 912 | else |
Imre Deak | 713a6b66 | 2016-06-28 13:37:33 +0300 | [diff] [blame] | 913 | done = wait_for(C, 10) == 0; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 914 | if (!done) |
| 915 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", |
| 916 | has_aux_irq); |
| 917 | #undef C |
| 918 | |
| 919 | return status; |
| 920 | } |
| 921 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 922 | 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] | 923 | { |
| 924 | 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] | 925 | 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] | 926 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 927 | if (index) |
| 928 | return 0; |
| 929 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 930 | /* |
| 931 | * 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] | 932 | * 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] | 933 | */ |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 934 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 938 | { |
| 939 | 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] | 940 | 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] | 941 | |
| 942 | if (index) |
| 943 | return 0; |
| 944 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 945 | /* |
| 946 | * The clock divider is based off the cdclk or PCH rawclk, and would |
| 947 | * like to run at 2MHz. So, take the cdclk or PCH rawclk value and |
| 948 | * divide by 2000 and use that |
| 949 | */ |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 950 | if (intel_dig_port->port == PORT_A) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 951 | return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 952 | else |
| 953 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | 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] | 957 | { |
| 958 | 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] | 959 | 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] | 960 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 961 | 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] | 962 | /* Workaround for non-ULT HSW */ |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 963 | switch (index) { |
| 964 | case 0: return 63; |
| 965 | case 1: return 72; |
| 966 | default: return 0; |
| 967 | } |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 968 | } |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 969 | |
| 970 | return ilk_get_aux_clock_divider(intel_dp, index); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 971 | } |
| 972 | |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 973 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 974 | { |
| 975 | /* |
| 976 | * SKL doesn't need us to program the AUX clock divider (Hardware will |
| 977 | * derive the clock from CDCLK automatically). We still implement the |
| 978 | * get_aux_clock_divider vfunc to plug-in into the existing code. |
| 979 | */ |
| 980 | return index ? 0 : 1; |
| 981 | } |
| 982 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 983 | static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 984 | bool has_aux_irq, |
| 985 | int send_bytes, |
| 986 | uint32_t aux_clock_divider) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 987 | { |
| 988 | 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] | 989 | struct drm_i915_private *dev_priv = |
| 990 | to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 991 | uint32_t precharge, timeout; |
| 992 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 993 | if (IS_GEN6(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 994 | precharge = 3; |
| 995 | else |
| 996 | precharge = 5; |
| 997 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 998 | if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 999 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
| 1000 | else |
| 1001 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; |
| 1002 | |
| 1003 | return DP_AUX_CH_CTL_SEND_BUSY | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1004 | DP_AUX_CH_CTL_DONE | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1005 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1006 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1007 | timeout | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1008 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1009 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 1010 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1011 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1014 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 1015 | bool has_aux_irq, |
| 1016 | int send_bytes, |
| 1017 | uint32_t unused) |
| 1018 | { |
| 1019 | return DP_AUX_CH_CTL_SEND_BUSY | |
| 1020 | DP_AUX_CH_CTL_DONE | |
| 1021 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
| 1022 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1023 | DP_AUX_CH_CTL_TIME_OUT_1600us | |
| 1024 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
| 1025 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 1026 | DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1027 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); |
| 1028 | } |
| 1029 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1030 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1031 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
Daniel Vetter | bd9f74a | 2014-10-02 09:45:35 +0200 | [diff] [blame] | 1032 | const uint8_t *send, int send_bytes, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1033 | uint8_t *recv, int recv_size) |
| 1034 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1035 | 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] | 1036 | struct drm_i915_private *dev_priv = |
| 1037 | to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1038 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1039 | uint32_t aux_clock_divider; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1040 | int i, ret, recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1041 | uint32_t status; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1042 | int try, clock = 0; |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 1043 | bool has_aux_irq = HAS_AUX_IRQ(dev_priv); |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1044 | bool vdd; |
| 1045 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1046 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1047 | |
Ville Syrjälä | 72c3500 | 2014-08-18 22:16:00 +0300 | [diff] [blame] | 1048 | /* |
| 1049 | * We will be called with VDD already enabled for dpcd/edid/oui reads. |
| 1050 | * In such cases we want to leave VDD enabled and it's up to upper layers |
| 1051 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off |
| 1052 | * ourselves. |
| 1053 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 1054 | vdd = edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1055 | |
| 1056 | /* dp aux is extremely sensitive to irq latency, hence request the |
| 1057 | * lowest possible wakeup latency and so prevent the cpu from going into |
| 1058 | * deep sleep states. |
| 1059 | */ |
| 1060 | pm_qos_update_request(&dev_priv->pm_qos, 0); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1061 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 1062 | intel_dp_check_edp(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1063 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1064 | /* Try to wait for any previous AUX channel activity */ |
| 1065 | for (try = 0; try < 3; try++) { |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 1066 | status = I915_READ_NOTRACE(ch_ctl); |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1067 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 1068 | break; |
| 1069 | msleep(1); |
| 1070 | } |
| 1071 | |
| 1072 | if (try == 3) { |
Mika Kuoppala | 02196c7 | 2015-08-06 16:48:58 +0300 | [diff] [blame] | 1073 | static u32 last_status = -1; |
| 1074 | const u32 status = I915_READ(ch_ctl); |
| 1075 | |
| 1076 | if (status != last_status) { |
| 1077 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 1078 | status); |
| 1079 | last_status = status; |
| 1080 | } |
| 1081 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1082 | ret = -EBUSY; |
| 1083 | goto out; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1086 | /* Only 5 data registers! */ |
| 1087 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { |
| 1088 | ret = -E2BIG; |
| 1089 | goto out; |
| 1090 | } |
| 1091 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 1092 | 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] | 1093 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
| 1094 | has_aux_irq, |
| 1095 | send_bytes, |
| 1096 | aux_clock_divider); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1097 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1098 | /* Must try at least 3 times according to DP spec */ |
| 1099 | for (try = 0; try < 5; try++) { |
| 1100 | /* Load the send data into the aux channel data registers */ |
| 1101 | for (i = 0; i < send_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1102 | I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2], |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1103 | intel_dp_pack_aux(send + i, |
| 1104 | send_bytes - i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1105 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1106 | /* Send the command and wait for it to complete */ |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1107 | I915_WRITE(ch_ctl, send_ctl); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1108 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1109 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1110 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1111 | /* Clear done status and any errors */ |
| 1112 | I915_WRITE(ch_ctl, |
| 1113 | status | |
| 1114 | DP_AUX_CH_CTL_DONE | |
| 1115 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1116 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Adam Jackson | d7e96fe | 2011-07-26 15:39:46 -0400 | [diff] [blame] | 1117 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1118 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1119 | continue; |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1120 | |
| 1121 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 |
| 1122 | * 400us delay required for errors and timeouts |
| 1123 | * Timeout errors from the HW already meet this |
| 1124 | * requirement so skip to next iteration |
| 1125 | */ |
| 1126 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
| 1127 | usleep_range(400, 500); |
| 1128 | continue; |
| 1129 | } |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1130 | if (status & DP_AUX_CH_CTL_DONE) |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1131 | goto done; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1132 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1135 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1136 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1137 | ret = -EBUSY; |
| 1138 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1141 | done: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1142 | /* Check for timeout or receive error. |
| 1143 | * Timeouts occur when the sink is not connected |
| 1144 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1145 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1146 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1147 | ret = -EIO; |
| 1148 | goto out; |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1149 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1150 | |
| 1151 | /* Timeouts occur when the device isn't connected, so they're |
| 1152 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1153 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Chris Wilson | a5570fe | 2017-02-23 11:51:02 +0000 | [diff] [blame] | 1154 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1155 | ret = -ETIMEDOUT; |
| 1156 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /* Unload any bytes sent back from the other side */ |
| 1160 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 1161 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1162 | |
| 1163 | /* |
| 1164 | * By BSpec: "Message sizes of 0 or >20 are not allowed." |
| 1165 | * We have no idea of what happened so we return -EBUSY so |
| 1166 | * drm layer takes care for the necessary retries. |
| 1167 | */ |
| 1168 | if (recv_bytes == 0 || recv_bytes > 20) { |
| 1169 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", |
| 1170 | recv_bytes); |
| 1171 | /* |
| 1172 | * FIXME: This patch was created on top of a series that |
| 1173 | * organize the retries at drm level. There EBUSY should |
| 1174 | * also take care for 1ms wait before retrying. |
| 1175 | * That aux retries re-org is still needed and after that is |
| 1176 | * merged we remove this sleep from here. |
| 1177 | */ |
| 1178 | usleep_range(1000, 1500); |
| 1179 | ret = -EBUSY; |
| 1180 | goto out; |
| 1181 | } |
| 1182 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1183 | if (recv_bytes > recv_size) |
| 1184 | recv_bytes = recv_size; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1185 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1186 | for (i = 0; i < recv_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1187 | 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] | 1188 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1189 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1190 | ret = recv_bytes; |
| 1191 | out: |
| 1192 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); |
| 1193 | |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1194 | if (vdd) |
| 1195 | edp_panel_vdd_off(intel_dp, false); |
| 1196 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1197 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1198 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1199 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1202 | #define BARE_ADDRESS_SIZE 3 |
| 1203 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1204 | static ssize_t |
| 1205 | 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] | 1206 | { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1207 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
| 1208 | uint8_t txbuf[20], rxbuf[20]; |
| 1209 | size_t txsize, rxsize; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1210 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1211 | |
Ville Syrjälä | d2d9cbb | 2015-03-19 11:44:06 +0200 | [diff] [blame] | 1212 | txbuf[0] = (msg->request << 4) | |
| 1213 | ((msg->address >> 16) & 0xf); |
| 1214 | txbuf[1] = (msg->address >> 8) & 0xff; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1215 | txbuf[2] = msg->address & 0xff; |
| 1216 | txbuf[3] = msg->size - 1; |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1217 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1218 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
| 1219 | case DP_AUX_NATIVE_WRITE: |
| 1220 | case DP_AUX_I2C_WRITE: |
Ville Syrjälä | c1e74122 | 2015-08-27 17:23:27 +0300 | [diff] [blame] | 1221 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1222 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1223 | rxsize = 2; /* 0 or 1 data bytes */ |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1224 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1225 | if (WARN_ON(txsize > 20)) |
| 1226 | return -E2BIG; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1227 | |
Ville Syrjälä | dd78809 | 2016-07-28 17:55:04 +0300 | [diff] [blame] | 1228 | WARN_ON(!msg->buffer != !msg->size); |
| 1229 | |
Imre Deak | d81a67c | 2016-01-29 14:52:26 +0200 | [diff] [blame] | 1230 | if (msg->buffer) |
| 1231 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1232 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1233 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1234 | if (ret > 0) { |
| 1235 | msg->reply = rxbuf[0] >> 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1236 | |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1237 | if (ret > 1) { |
| 1238 | /* Number of bytes written in a short write. */ |
| 1239 | ret = clamp_t(int, rxbuf[1], 0, msg->size); |
| 1240 | } else { |
| 1241 | /* Return payload size. */ |
| 1242 | ret = msg->size; |
| 1243 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1244 | } |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1245 | break; |
| 1246 | |
| 1247 | case DP_AUX_NATIVE_READ: |
| 1248 | case DP_AUX_I2C_READ: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1249 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1250 | rxsize = msg->size + 1; |
| 1251 | |
| 1252 | if (WARN_ON(rxsize > 20)) |
| 1253 | return -E2BIG; |
| 1254 | |
| 1255 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1256 | if (ret > 0) { |
| 1257 | msg->reply = rxbuf[0] >> 4; |
| 1258 | /* |
| 1259 | * Assume happy day, and copy the data. The caller is |
| 1260 | * expected to check msg->reply before touching it. |
| 1261 | * |
| 1262 | * Return payload size. |
| 1263 | */ |
| 1264 | ret--; |
| 1265 | memcpy(msg->buffer, rxbuf + 1, ret); |
| 1266 | } |
| 1267 | break; |
| 1268 | |
| 1269 | default: |
| 1270 | ret = -EINVAL; |
| 1271 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1272 | } |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1273 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1274 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1277 | static enum port intel_aux_port(struct drm_i915_private *dev_priv, |
| 1278 | enum port port) |
| 1279 | { |
| 1280 | const struct ddi_vbt_port_info *info = |
| 1281 | &dev_priv->vbt.ddi_port_info[port]; |
| 1282 | enum port aux_port; |
| 1283 | |
| 1284 | if (!info->alternate_aux_channel) { |
| 1285 | DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n", |
| 1286 | port_name(port), port_name(port)); |
| 1287 | return port; |
| 1288 | } |
| 1289 | |
| 1290 | switch (info->alternate_aux_channel) { |
| 1291 | case DP_AUX_A: |
| 1292 | aux_port = PORT_A; |
| 1293 | break; |
| 1294 | case DP_AUX_B: |
| 1295 | aux_port = PORT_B; |
| 1296 | break; |
| 1297 | case DP_AUX_C: |
| 1298 | aux_port = PORT_C; |
| 1299 | break; |
| 1300 | case DP_AUX_D: |
| 1301 | aux_port = PORT_D; |
| 1302 | break; |
| 1303 | default: |
| 1304 | MISSING_CASE(info->alternate_aux_channel); |
| 1305 | aux_port = PORT_A; |
| 1306 | break; |
| 1307 | } |
| 1308 | |
| 1309 | DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n", |
| 1310 | port_name(aux_port), port_name(port)); |
| 1311 | |
| 1312 | return aux_port; |
| 1313 | } |
| 1314 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1315 | 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] | 1316 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1317 | { |
| 1318 | switch (port) { |
| 1319 | case PORT_B: |
| 1320 | case PORT_C: |
| 1321 | case PORT_D: |
| 1322 | return DP_AUX_CH_CTL(port); |
| 1323 | default: |
| 1324 | MISSING_CASE(port); |
| 1325 | return DP_AUX_CH_CTL(PORT_B); |
| 1326 | } |
| 1327 | } |
| 1328 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1329 | 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] | 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_B: |
| 1334 | case PORT_C: |
| 1335 | case PORT_D: |
| 1336 | return DP_AUX_CH_DATA(port, index); |
| 1337 | default: |
| 1338 | MISSING_CASE(port); |
| 1339 | return DP_AUX_CH_DATA(PORT_B, index); |
| 1340 | } |
| 1341 | } |
| 1342 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1343 | 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] | 1344 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1345 | { |
| 1346 | switch (port) { |
| 1347 | case PORT_A: |
| 1348 | return DP_AUX_CH_CTL(port); |
| 1349 | case PORT_B: |
| 1350 | case PORT_C: |
| 1351 | case PORT_D: |
| 1352 | return PCH_DP_AUX_CH_CTL(port); |
| 1353 | default: |
| 1354 | MISSING_CASE(port); |
| 1355 | return DP_AUX_CH_CTL(PORT_A); |
| 1356 | } |
| 1357 | } |
| 1358 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1359 | 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] | 1360 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1361 | { |
| 1362 | switch (port) { |
| 1363 | case PORT_A: |
| 1364 | return DP_AUX_CH_DATA(port, index); |
| 1365 | case PORT_B: |
| 1366 | case PORT_C: |
| 1367 | case PORT_D: |
| 1368 | return PCH_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 skl_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ä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1377 | { |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1378 | switch (port) { |
| 1379 | case PORT_A: |
| 1380 | case PORT_B: |
| 1381 | case PORT_C: |
| 1382 | case PORT_D: |
| 1383 | return DP_AUX_CH_CTL(port); |
| 1384 | default: |
| 1385 | MISSING_CASE(port); |
| 1386 | return DP_AUX_CH_CTL(PORT_A); |
| 1387 | } |
| 1388 | } |
| 1389 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1390 | 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] | 1391 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1392 | { |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1393 | switch (port) { |
| 1394 | case PORT_A: |
| 1395 | case PORT_B: |
| 1396 | case PORT_C: |
| 1397 | case PORT_D: |
| 1398 | return DP_AUX_CH_DATA(port, index); |
| 1399 | default: |
| 1400 | MISSING_CASE(port); |
| 1401 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1402 | } |
| 1403 | } |
| 1404 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1405 | 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] | 1406 | enum port port) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1407 | { |
| 1408 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1409 | return skl_aux_ctl_reg(dev_priv, port); |
| 1410 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1411 | return ilk_aux_ctl_reg(dev_priv, port); |
| 1412 | else |
| 1413 | return g4x_aux_ctl_reg(dev_priv, port); |
| 1414 | } |
| 1415 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1416 | 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] | 1417 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1418 | { |
| 1419 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1420 | return skl_aux_data_reg(dev_priv, port, index); |
| 1421 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1422 | return ilk_aux_data_reg(dev_priv, port, index); |
| 1423 | else |
| 1424 | return g4x_aux_data_reg(dev_priv, port, index); |
| 1425 | } |
| 1426 | |
| 1427 | static void intel_aux_reg_init(struct intel_dp *intel_dp) |
| 1428 | { |
| 1429 | 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] | 1430 | enum port port = intel_aux_port(dev_priv, |
| 1431 | dp_to_dig_port(intel_dp)->port); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1432 | int i; |
| 1433 | |
| 1434 | intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); |
| 1435 | for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++) |
| 1436 | intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i); |
| 1437 | } |
| 1438 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1439 | static void |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1440 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
| 1441 | { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1442 | kfree(intel_dp->aux.name); |
| 1443 | } |
| 1444 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1445 | static void |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 1446 | intel_dp_aux_init(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1447 | { |
Jani Nikula | 33ad662 | 2014-03-14 16:51:16 +0200 | [diff] [blame] | 1448 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 1449 | enum port port = intel_dig_port->port; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1450 | |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1451 | intel_aux_reg_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1452 | drm_dp_aux_init(&intel_dp->aux); |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 1453 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1454 | /* Failure to allocate our preferred name is not critical */ |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1455 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port)); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1456 | intel_dp->aux.transfer = intel_dp_aux_transfer; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1459 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1460 | { |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1461 | 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] | 1462 | 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] | 1463 | |
Navare, Manasi D | 577c543 | 2016-09-27 16:36:53 -0700 | [diff] [blame] | 1464 | if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) || |
| 1465 | IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9)) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1466 | return true; |
| 1467 | else |
| 1468 | return false; |
| 1469 | } |
| 1470 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 1471 | static void |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1472 | intel_dp_set_clock(struct intel_encoder *encoder, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1473 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1474 | { |
| 1475 | struct drm_device *dev = encoder->base.dev; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1476 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1477 | const struct dp_link_dpll *divisor = NULL; |
| 1478 | int i, count = 0; |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1479 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 1480 | if (IS_G4X(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1481 | divisor = gen4_dpll; |
| 1482 | count = ARRAY_SIZE(gen4_dpll); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1483 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1484 | divisor = pch_dpll; |
| 1485 | count = ARRAY_SIZE(pch_dpll); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1486 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1487 | divisor = chv_dpll; |
| 1488 | count = ARRAY_SIZE(chv_dpll); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 1489 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 1490 | divisor = vlv_dpll; |
| 1491 | count = ARRAY_SIZE(vlv_dpll); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1492 | } |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1493 | |
| 1494 | if (divisor && count) { |
| 1495 | for (i = 0; i < count; i++) { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1496 | if (pipe_config->port_clock == divisor[i].clock) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1497 | pipe_config->dpll = divisor[i].dpll; |
| 1498 | pipe_config->clock_set = true; |
| 1499 | break; |
| 1500 | } |
| 1501 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1505 | static void snprintf_int_array(char *str, size_t len, |
| 1506 | const int *array, int nelem) |
| 1507 | { |
| 1508 | int i; |
| 1509 | |
| 1510 | str[0] = '\0'; |
| 1511 | |
| 1512 | for (i = 0; i < nelem; i++) { |
Jani Nikula | b2f505b | 2015-05-18 16:01:45 +0300 | [diff] [blame] | 1513 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1514 | if (r >= len) |
| 1515 | return; |
| 1516 | str += r; |
| 1517 | len -= r; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | static void intel_dp_print_rates(struct intel_dp *intel_dp) |
| 1522 | { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 1523 | int common_len; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1524 | int common_rates[DP_MAX_SUPPORTED_RATES]; |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1525 | char str[128]; /* FIXME: too big for stack? */ |
| 1526 | |
| 1527 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 1528 | return; |
| 1529 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 1530 | snprintf_int_array(str, sizeof(str), |
| 1531 | intel_dp->source_rates, intel_dp->num_source_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1532 | DRM_DEBUG_KMS("source rates: %s\n", str); |
| 1533 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 1534 | snprintf_int_array(str, sizeof(str), |
| 1535 | intel_dp->sink_rates, intel_dp->num_sink_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1536 | DRM_DEBUG_KMS("sink rates: %s\n", str); |
| 1537 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1538 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
| 1539 | snprintf_int_array(str, sizeof(str), common_rates, common_len); |
| 1540 | DRM_DEBUG_KMS("common rates: %s\n", str); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1541 | } |
| 1542 | |
Imre Deak | 489375c | 2016-10-24 19:33:31 +0300 | [diff] [blame] | 1543 | bool |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1544 | __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] | 1545 | { |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1546 | u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI : |
| 1547 | DP_SINK_OUI; |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1548 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1549 | return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) == |
| 1550 | sizeof(*desc); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 1551 | } |
| 1552 | |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 1553 | bool intel_dp_read_desc(struct intel_dp *intel_dp) |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1554 | { |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1555 | struct intel_dp_desc *desc = &intel_dp->desc; |
| 1556 | bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & |
| 1557 | DP_OUI_SUPPORT; |
| 1558 | int dev_id_len; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1559 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1560 | if (!__intel_dp_read_desc(intel_dp, desc)) |
| 1561 | return false; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1562 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1563 | dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id)); |
| 1564 | DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n", |
| 1565 | drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink", |
| 1566 | (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)", |
| 1567 | dev_id_len, desc->device_id, |
| 1568 | desc->hw_rev >> 4, desc->hw_rev & 0xf, |
| 1569 | desc->sw_major_rev, desc->sw_minor_rev); |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1570 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 1571 | return true; |
Mika Kahola | 1a2724f | 2016-09-09 14:10:54 +0300 | [diff] [blame] | 1572 | } |
| 1573 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1574 | int |
| 1575 | intel_dp_max_link_rate(struct intel_dp *intel_dp) |
| 1576 | { |
| 1577 | int rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 1578 | int len; |
| 1579 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1580 | len = intel_dp_common_rates(intel_dp, rates); |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1581 | if (WARN_ON(len <= 0)) |
| 1582 | return 162000; |
| 1583 | |
Ville Syrjälä | 1354f73 | 2016-07-28 17:50:45 +0300 | [diff] [blame] | 1584 | return rates[len - 1]; |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1585 | } |
| 1586 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1587 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
| 1588 | { |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 1589 | int i = intel_dp_rate_index(intel_dp->sink_rates, |
| 1590 | intel_dp->num_sink_rates, rate); |
Jani Nikula | b5c72b2 | 2017-03-28 17:59:02 +0300 | [diff] [blame] | 1591 | |
| 1592 | if (WARN_ON(i < 0)) |
| 1593 | i = 0; |
| 1594 | |
| 1595 | return i; |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1596 | } |
| 1597 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 1598 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
| 1599 | uint8_t *link_bw, uint8_t *rate_select) |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1600 | { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 1601 | /* eDP 1.4 rate select method. */ |
| 1602 | if (intel_dp->use_rate_select) { |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1603 | *link_bw = 0; |
| 1604 | *rate_select = |
| 1605 | intel_dp_rate_select(intel_dp, port_clock); |
| 1606 | } else { |
| 1607 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); |
| 1608 | *rate_select = 0; |
| 1609 | } |
| 1610 | } |
| 1611 | |
Jani Nikula | f580bea | 2016-09-15 16:28:52 +0300 | [diff] [blame] | 1612 | static int intel_dp_compute_bpp(struct intel_dp *intel_dp, |
| 1613 | struct intel_crtc_state *pipe_config) |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1614 | { |
| 1615 | int bpp, bpc; |
| 1616 | |
| 1617 | bpp = pipe_config->pipe_bpp; |
| 1618 | bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports); |
| 1619 | |
| 1620 | if (bpc > 0) |
| 1621 | bpp = min(bpp, 3*bpc); |
| 1622 | |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 1623 | /* For DP Compliance we override the computed bpp for the pipe */ |
| 1624 | if (intel_dp->compliance.test_data.bpc != 0) { |
| 1625 | pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc; |
| 1626 | pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3; |
| 1627 | DRM_DEBUG_KMS("Setting pipe_bpp to %d\n", |
| 1628 | pipe_config->pipe_bpp); |
| 1629 | } |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1630 | return bpp; |
| 1631 | } |
| 1632 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1633 | bool |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1634 | intel_dp_compute_config(struct intel_encoder *encoder, |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 1635 | struct intel_crtc_state *pipe_config, |
| 1636 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1637 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1638 | 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] | 1639 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1640 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1641 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ander Conselvan de Oliveira | 84556d5 | 2015-03-20 16:18:10 +0200 | [diff] [blame] | 1642 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1643 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1644 | int lane_count, clock; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1645 | int min_lane_count = 1; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 1646 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
Todd Previte | 06ea66b | 2014-01-20 10:19:39 -0700 | [diff] [blame] | 1647 | /* Conveniently, the link BW constants become indices with a shift...*/ |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1648 | int min_clock = 0; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1649 | int max_clock; |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1650 | int link_rate_index; |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1651 | int bpp, mode_rate; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1652 | int link_avail, link_clock; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1653 | int common_rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 1654 | int common_len; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1655 | uint8_t link_bw, rate_select; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1656 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1657 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1658 | |
| 1659 | /* No common link rates between source and sink */ |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1660 | WARN_ON(common_len <= 0); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1661 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1662 | max_clock = common_len - 1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1663 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1664 | 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] | 1665 | pipe_config->has_pch_encoder = true; |
| 1666 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1667 | pipe_config->has_drrs = false; |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 1668 | pipe_config->has_audio = intel_dp->has_audio && port != PORT_A; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1669 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1670 | if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
| 1671 | intel_fixed_panel_mode(intel_connector->panel.fixed_mode, |
| 1672 | adjusted_mode); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1673 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1674 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1675 | int ret; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 1676 | ret = skl_update_scaler_crtc(pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1677 | if (ret) |
| 1678 | return ret; |
| 1679 | } |
| 1680 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 1681 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1682 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
| 1683 | intel_connector->panel.fitting_mode); |
| 1684 | else |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 1685 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
| 1686 | intel_connector->panel.fitting_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 1687 | } |
| 1688 | |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 1689 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 1690 | return false; |
| 1691 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1692 | /* Use values requested by Compliance Test Request */ |
| 1693 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 1694 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 1695 | common_rates, |
| 1696 | intel_dp->compliance.test_link_rate); |
| 1697 | if (link_rate_index >= 0) |
| 1698 | min_clock = max_clock = link_rate_index; |
| 1699 | min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count; |
| 1700 | } |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1701 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1702 | "max bw %d pixel clock %iKHz\n", |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1703 | max_lane_count, common_rates[max_clock], |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1704 | adjusted_mode->crtc_clock); |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1705 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1706 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
| 1707 | * bpc in between. */ |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1708 | bpp = intel_dp_compute_bpp(intel_dp, pipe_config); |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1709 | if (is_edp(intel_dp)) { |
Thulasimani,Sivakumar | 22ce562 | 2015-07-31 11:05:27 +0530 | [diff] [blame] | 1710 | |
| 1711 | /* Get bpp from vbt only for panels that dont have bpp in edid */ |
| 1712 | if (intel_connector->base.display_info.bpc == 0 && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1713 | (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) { |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1714 | 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] | 1715 | dev_priv->vbt.edp.bpp); |
| 1716 | bpp = dev_priv->vbt.edp.bpp; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1717 | } |
| 1718 | |
Jani Nikula | 344c5bb | 2014-09-09 11:25:13 +0300 | [diff] [blame] | 1719 | /* |
| 1720 | * Use the maximum clock and number of lanes the eDP panel |
| 1721 | * advertizes being capable of. The panels are generally |
| 1722 | * designed to support only a single clock and lane |
| 1723 | * configuration, and typically these values correspond to the |
| 1724 | * native resolution of the panel. |
| 1725 | */ |
| 1726 | min_lane_count = max_lane_count; |
| 1727 | min_clock = max_clock; |
Imre Deak | 7984211 | 2013-07-18 17:44:13 +0300 | [diff] [blame] | 1728 | } |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1729 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1730 | for (; bpp >= 6*3; bpp -= 2*3) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1731 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
| 1732 | bpp); |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1733 | |
Dave Airlie | c693099 | 2014-07-14 11:04:39 +1000 | [diff] [blame] | 1734 | for (clock = min_clock; clock <= max_clock; clock++) { |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1735 | for (lane_count = min_lane_count; |
| 1736 | lane_count <= max_lane_count; |
| 1737 | lane_count <<= 1) { |
| 1738 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1739 | link_clock = common_rates[clock]; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1740 | link_avail = intel_dp_max_data_rate(link_clock, |
| 1741 | lane_count); |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 1742 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1743 | if (mode_rate <= link_avail) { |
| 1744 | goto found; |
| 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | return false; |
| 1751 | |
| 1752 | found: |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1753 | if (intel_dp->color_range_auto) { |
| 1754 | /* |
| 1755 | * See: |
| 1756 | * CEA-861-E - 5.1 Default Encoding Parameters |
| 1757 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry |
| 1758 | */ |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1759 | pipe_config->limited_color_range = |
Ville Syrjälä | c8127cf0 | 2017-01-11 16:18:35 +0200 | [diff] [blame] | 1760 | bpp != 18 && |
| 1761 | drm_default_rgb_quant_range(adjusted_mode) == |
| 1762 | HDMI_QUANTIZATION_RANGE_LIMITED; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1763 | } else { |
| 1764 | pipe_config->limited_color_range = |
| 1765 | intel_dp->limited_color_range; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1766 | } |
| 1767 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1768 | pipe_config->lane_count = lane_count; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1769 | |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1770 | pipe_config->pipe_bpp = bpp; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1771 | pipe_config->port_clock = common_rates[clock]; |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1772 | |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1773 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
| 1774 | &link_bw, &rate_select); |
| 1775 | |
| 1776 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", |
| 1777 | link_bw, rate_select, pipe_config->lane_count, |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1778 | pipe_config->port_clock, bpp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1779 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
| 1780 | mode_rate, link_avail); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1781 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1782 | intel_link_compute_m_n(bpp, lane_count, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1783 | adjusted_mode->crtc_clock, |
| 1784 | pipe_config->port_clock, |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1785 | &pipe_config->dp_m_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1786 | |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1787 | if (intel_connector->panel.downclock_mode != NULL && |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 1788 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1789 | pipe_config->has_drrs = true; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1790 | intel_link_compute_m_n(bpp, lane_count, |
| 1791 | intel_connector->panel.downclock_mode->clock, |
| 1792 | pipe_config->port_clock, |
| 1793 | &pipe_config->dp_m2_n2); |
| 1794 | } |
| 1795 | |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1796 | /* |
| 1797 | * DPLL0 VCO may need to be adjusted to get the correct |
| 1798 | * clock for eDP. This will affect cdclk as well. |
| 1799 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 1800 | if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) { |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1801 | int vco; |
| 1802 | |
| 1803 | switch (pipe_config->port_clock / 2) { |
| 1804 | case 108000: |
| 1805 | case 216000: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1806 | vco = 8640000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1807 | break; |
| 1808 | default: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1809 | vco = 8100000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1810 | break; |
| 1811 | } |
| 1812 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 1813 | 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] | 1814 | } |
| 1815 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1816 | if (!HAS_DDI(dev_priv)) |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1817 | intel_dp_set_clock(encoder, pipe_config); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1818 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1819 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1822 | 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] | 1823 | int link_rate, uint8_t lane_count, |
| 1824 | bool link_mst) |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1825 | { |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1826 | intel_dp->link_rate = link_rate; |
| 1827 | intel_dp->lane_count = lane_count; |
| 1828 | intel_dp->link_mst = link_mst; |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1829 | } |
| 1830 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1831 | static void intel_dp_prepare(struct intel_encoder *encoder, |
| 1832 | struct intel_crtc_state *pipe_config) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1833 | { |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1834 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1835 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1836 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1837 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1838 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1839 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1840 | |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1841 | intel_dp_set_link_params(intel_dp, pipe_config->port_clock, |
| 1842 | pipe_config->lane_count, |
| 1843 | intel_crtc_has_type(pipe_config, |
| 1844 | INTEL_OUTPUT_DP_MST)); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1845 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1846 | /* |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1847 | * There are four kinds of DP registers: |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1848 | * |
| 1849 | * IBX PCH |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1850 | * SNB CPU |
| 1851 | * IVB CPU |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1852 | * CPT PCH |
| 1853 | * |
| 1854 | * IBX PCH and CPU are the same for almost everything, |
| 1855 | * except that the CPU DP PLL is configured in this |
| 1856 | * register |
| 1857 | * |
| 1858 | * CPT PCH is quite different, having many bits moved |
| 1859 | * to the TRANS_DP_CTL register instead. That |
| 1860 | * configuration happens (oddly) in ironlake_pch_enable |
| 1861 | */ |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 1862 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1863 | /* Preserve the BIOS-computed detected bit. This is |
| 1864 | * supposed to be read-only. |
| 1865 | */ |
| 1866 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1867 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1868 | /* Handle DP bits in common between all three register formats */ |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1869 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1870 | intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1871 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1872 | /* Split out the IBX/CPU vs CPT settings */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1873 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1874 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 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_CPT; |
| 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 | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1882 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1883 | |
Daniel Vetter | 7c62a16 | 2013-06-01 17:16:20 +0200 | [diff] [blame] | 1884 | intel_dp->DP |= crtc->pipe << 29; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1885 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1886 | u32 trans_dp; |
| 1887 | |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1888 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1889 | |
| 1890 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 1891 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 1892 | trans_dp |= TRANS_DP_ENH_FRAMING; |
| 1893 | else |
| 1894 | trans_dp &= ~TRANS_DP_ENH_FRAMING; |
| 1895 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1896 | } else { |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 1897 | if (IS_G4X(dev_priv) && pipe_config->limited_color_range) |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1898 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1899 | |
| 1900 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1901 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1902 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1903 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1904 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
| 1905 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1906 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1907 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1908 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1909 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1910 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1911 | else if (crtc->pipe == PIPE_B) |
| 1912 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1913 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1916 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
| 1917 | #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] | 1918 | |
Paulo Zanoni | 1a5ef5b | 2013-12-19 14:29:43 -0200 | [diff] [blame] | 1919 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
| 1920 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1921 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1922 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
| 1923 | #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] | 1924 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1925 | static void intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 1926 | struct intel_dp *intel_dp); |
| 1927 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1928 | static void wait_panel_status(struct intel_dp *intel_dp, |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1929 | u32 mask, |
| 1930 | u32 value) |
| 1931 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 1932 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1933 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1934 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1935 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1936 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1937 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1938 | intel_pps_verify_state(dev_priv, intel_dp); |
| 1939 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1940 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 1941 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1942 | |
| 1943 | DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1944 | mask, value, |
| 1945 | I915_READ(pp_stat_reg), |
| 1946 | I915_READ(pp_ctrl_reg)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1947 | |
Chris Wilson | 9036ff0 | 2016-06-30 15:33:09 +0100 | [diff] [blame] | 1948 | if (intel_wait_for_register(dev_priv, |
| 1949 | pp_stat_reg, mask, value, |
| 1950 | 5000)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1951 | DRM_ERROR("Panel status timeout: status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1952 | I915_READ(pp_stat_reg), |
| 1953 | I915_READ(pp_ctrl_reg)); |
Chris Wilson | 54c136d | 2013-12-02 09:57:16 +0000 | [diff] [blame] | 1954 | |
| 1955 | DRM_DEBUG_KMS("Wait complete\n"); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1958 | static void wait_panel_on(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1959 | { |
| 1960 | DRM_DEBUG_KMS("Wait for panel power on\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1961 | wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1964 | static void wait_panel_off(struct intel_dp *intel_dp) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1965 | { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1966 | DRM_DEBUG_KMS("Wait for panel power off time\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1967 | wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1968 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1969 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1970 | static void wait_panel_power_cycle(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1971 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1972 | ktime_t panel_power_on_time; |
| 1973 | s64 panel_power_off_duration; |
| 1974 | |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1975 | DRM_DEBUG_KMS("Wait for panel power cycle\n"); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1976 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1977 | /* take the difference of currrent time and panel power off time |
| 1978 | * and then make panel wait for t11_t12 if needed. */ |
| 1979 | panel_power_on_time = ktime_get_boottime(); |
| 1980 | panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time); |
| 1981 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1982 | /* When we disable the VDD override bit last we have to do the manual |
| 1983 | * wait. */ |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1984 | if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay) |
| 1985 | wait_remaining_ms_from_jiffies(jiffies, |
| 1986 | intel_dp->panel_power_cycle_delay - panel_power_off_duration); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1987 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1988 | wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1989 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1990 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1991 | static void wait_backlight_on(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1992 | { |
| 1993 | wait_remaining_ms_from_jiffies(intel_dp->last_power_on, |
| 1994 | intel_dp->backlight_on_delay); |
| 1995 | } |
| 1996 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1997 | static void edp_wait_backlight_off(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1998 | { |
| 1999 | wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off, |
| 2000 | intel_dp->backlight_off_delay); |
| 2001 | } |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2002 | |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2003 | /* Read the current pp_control value, unlocking the register if it |
| 2004 | * is locked |
| 2005 | */ |
| 2006 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2007 | static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2008 | { |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2009 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2010 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2011 | u32 control; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2012 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2013 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2014 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2015 | control = I915_READ(_pp_ctrl_reg(intel_dp)); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 2016 | if (WARN_ON(!HAS_DDI(dev_priv) && |
| 2017 | (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 2018 | control &= ~PANEL_UNLOCK_MASK; |
| 2019 | control |= PANEL_UNLOCK_REGS; |
| 2020 | } |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2021 | return control; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2024 | /* |
| 2025 | * Must be paired with edp_panel_vdd_off(). |
| 2026 | * Must hold pps_mutex around the whole on/off sequence. |
| 2027 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2028 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 2029 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2030 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2031 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2032 | 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] | 2033 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2034 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2035 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2036 | bool need_to_disable = !intel_dp->want_panel_vdd; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2037 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2038 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2039 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2040 | if (!is_edp(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2041 | return false; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2042 | |
Egbert Eich | 2c623c1 | 2014-11-25 12:54:57 +0100 | [diff] [blame] | 2043 | cancel_delayed_work(&intel_dp->panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2044 | intel_dp->want_panel_vdd = true; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2045 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2046 | if (edp_have_panel_vdd(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2047 | return need_to_disable; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2048 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2049 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2050 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2051 | DRM_DEBUG_KMS("Turning eDP port %c VDD on\n", |
| 2052 | port_name(intel_dig_port->port)); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2053 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2054 | if (!edp_have_panel_power(intel_dp)) |
| 2055 | wait_panel_power_cycle(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2056 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2057 | pp = ironlake_get_pp_control(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2058 | pp |= EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2059 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2060 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 2061 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2062 | |
| 2063 | I915_WRITE(pp_ctrl_reg, pp); |
| 2064 | POSTING_READ(pp_ctrl_reg); |
| 2065 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2066 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2067 | /* |
| 2068 | * If the panel wasn't on, delay before accessing aux channel |
| 2069 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2070 | if (!edp_have_panel_power(intel_dp)) { |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2071 | DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n", |
| 2072 | port_name(intel_dig_port->port)); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2073 | msleep(intel_dp->panel_power_up_delay); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2074 | } |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2075 | |
| 2076 | return need_to_disable; |
| 2077 | } |
| 2078 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2079 | /* |
| 2080 | * Must be paired with intel_edp_panel_vdd_off() or |
| 2081 | * intel_edp_panel_off(). |
| 2082 | * Nested calls to these functions are not allowed since |
| 2083 | * we drop the lock. Caller must use some higher level |
| 2084 | * locking to prevent nested calls from other threads. |
| 2085 | */ |
Daniel Vetter | b80d6c7 | 2014-03-19 15:54:37 +0100 | [diff] [blame] | 2086 | void intel_edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2087 | { |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2088 | bool vdd; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2089 | |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2090 | if (!is_edp(intel_dp)) |
| 2091 | return; |
| 2092 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2093 | pps_lock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2094 | vdd = edp_panel_vdd_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2095 | pps_unlock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2096 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2097 | 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] | 2098 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2099 | } |
| 2100 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2101 | static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2102 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2103 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2104 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2105 | struct intel_digital_port *intel_dig_port = |
| 2106 | dp_to_dig_port(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2107 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2108 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2109 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2110 | lockdep_assert_held(&dev_priv->pps_mutex); |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 2111 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2112 | WARN_ON(intel_dp->want_panel_vdd); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2113 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2114 | if (!edp_have_panel_vdd(intel_dp)) |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2115 | return; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2116 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2117 | DRM_DEBUG_KMS("Turning eDP port %c VDD off\n", |
| 2118 | port_name(intel_dig_port->port)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2119 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2120 | pp = ironlake_get_pp_control(intel_dp); |
| 2121 | pp &= ~EDP_FORCE_VDD; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2122 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2123 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
| 2124 | pp_stat_reg = _pp_stat_reg(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2125 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2126 | I915_WRITE(pp_ctrl_reg, pp); |
| 2127 | POSTING_READ(pp_ctrl_reg); |
Paulo Zanoni | 90791a5 | 2013-12-06 17:32:42 -0200 | [diff] [blame] | 2128 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2129 | /* Make sure sequencer is idle before allowing subsequent activity */ |
| 2130 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2131 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2132 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2133 | if ((pp & PANEL_POWER_ON) == 0) |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2134 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2135 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2136 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2139 | static void edp_panel_vdd_work(struct work_struct *__work) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2140 | { |
| 2141 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), |
| 2142 | struct intel_dp, panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2143 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2144 | pps_lock(intel_dp); |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2145 | if (!intel_dp->want_panel_vdd) |
| 2146 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2147 | pps_unlock(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2150 | static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) |
| 2151 | { |
| 2152 | unsigned long delay; |
| 2153 | |
| 2154 | /* |
| 2155 | * Queue the timer to fire a long time from now (relative to the power |
| 2156 | * down delay) to keep the panel power up across a sequence of |
| 2157 | * operations. |
| 2158 | */ |
| 2159 | delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5); |
| 2160 | schedule_delayed_work(&intel_dp->panel_vdd_work, delay); |
| 2161 | } |
| 2162 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2163 | /* |
| 2164 | * Must be paired with edp_panel_vdd_on(). |
| 2165 | * Must hold pps_mutex around the whole on/off sequence. |
| 2166 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2167 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2168 | 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] | 2169 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2170 | 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] | 2171 | |
| 2172 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2173 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2174 | if (!is_edp(intel_dp)) |
| 2175 | return; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2176 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2177 | 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] | 2178 | port_name(dp_to_dig_port(intel_dp)->port)); |
Keith Packard | f2e8b18 | 2011-11-01 20:01:35 -0700 | [diff] [blame] | 2179 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2180 | intel_dp->want_panel_vdd = false; |
| 2181 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2182 | if (sync) |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2183 | edp_panel_vdd_off_sync(intel_dp); |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2184 | else |
| 2185 | edp_panel_vdd_schedule_off(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2186 | } |
| 2187 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2188 | static void edp_panel_on(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2189 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2190 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2191 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2192 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2193 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2194 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2195 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2196 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2197 | if (!is_edp(intel_dp)) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2198 | return; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2199 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2200 | DRM_DEBUG_KMS("Turn eDP port %c panel power on\n", |
| 2201 | port_name(dp_to_dig_port(intel_dp)->port)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2202 | |
Ville Syrjälä | e7a89ac | 2014-10-16 21:30:07 +0300 | [diff] [blame] | 2203 | if (WARN(edp_have_panel_power(intel_dp), |
| 2204 | "eDP port %c panel power already on\n", |
| 2205 | port_name(dp_to_dig_port(intel_dp)->port))) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2206 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2207 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2208 | wait_panel_power_cycle(intel_dp); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2209 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2210 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2211 | pp = ironlake_get_pp_control(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2212 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2213 | /* ILK workaround: disable reset around power sequence */ |
| 2214 | pp &= ~PANEL_POWER_RESET; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2215 | I915_WRITE(pp_ctrl_reg, pp); |
| 2216 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2217 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2218 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2219 | pp |= PANEL_POWER_ON; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2220 | if (!IS_GEN5(dev_priv)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2221 | pp |= PANEL_POWER_RESET; |
| 2222 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2223 | I915_WRITE(pp_ctrl_reg, pp); |
| 2224 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2225 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2226 | wait_panel_on(intel_dp); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2227 | intel_dp->last_power_on = jiffies; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2228 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2229 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2230 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2231 | I915_WRITE(pp_ctrl_reg, pp); |
| 2232 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2233 | } |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2234 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2235 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2236 | void intel_edp_panel_on(struct intel_dp *intel_dp) |
| 2237 | { |
| 2238 | if (!is_edp(intel_dp)) |
| 2239 | return; |
| 2240 | |
| 2241 | pps_lock(intel_dp); |
| 2242 | edp_panel_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2243 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2246 | |
| 2247 | static void edp_panel_off(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2248 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2249 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2250 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2251 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2252 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2253 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2254 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2255 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2256 | if (!is_edp(intel_dp)) |
| 2257 | return; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2258 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2259 | DRM_DEBUG_KMS("Turn eDP port %c panel power off\n", |
| 2260 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2261 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2262 | WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n", |
| 2263 | port_name(dp_to_dig_port(intel_dp)->port)); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2264 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2265 | pp = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 35a3855 | 2012-08-12 22:17:14 +0200 | [diff] [blame] | 2266 | /* We need to switch off panel power _and_ force vdd, for otherwise some |
| 2267 | * panels get very unhappy and cease to work. */ |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2268 | pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | |
Patrik Jakobsson | b306415 | 2014-03-04 00:42:44 +0100 | [diff] [blame] | 2269 | EDP_BLC_ENABLE); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2270 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2271 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2272 | |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2273 | intel_dp->want_panel_vdd = false; |
| 2274 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2275 | I915_WRITE(pp_ctrl_reg, pp); |
| 2276 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2277 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2278 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2279 | wait_panel_off(intel_dp); |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2280 | |
| 2281 | /* We got a reference when we enabled the VDD. */ |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2282 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2283 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2284 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2285 | void intel_edp_panel_off(struct intel_dp *intel_dp) |
| 2286 | { |
| 2287 | if (!is_edp(intel_dp)) |
| 2288 | return; |
| 2289 | |
| 2290 | pps_lock(intel_dp); |
| 2291 | edp_panel_off(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2292 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2295 | /* Enable backlight in the panel power control. */ |
| 2296 | static void _intel_edp_backlight_on(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2297 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2298 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2299 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2300 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2301 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2302 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2303 | |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 2304 | /* |
| 2305 | * If we enable the backlight right away following a panel power |
| 2306 | * on, we may see slight flicker as the panel syncs with the eDP |
| 2307 | * link. So delay a bit to make sure the image is solid before |
| 2308 | * allowing it to appear. |
| 2309 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2310 | wait_backlight_on(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2311 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2312 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2313 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2314 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2315 | pp |= EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2316 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2317 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2318 | |
| 2319 | I915_WRITE(pp_ctrl_reg, pp); |
| 2320 | POSTING_READ(pp_ctrl_reg); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2321 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2322 | pps_unlock(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2323 | } |
| 2324 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2325 | /* Enable backlight PWM and backlight PP control. */ |
| 2326 | void intel_edp_backlight_on(struct intel_dp *intel_dp) |
| 2327 | { |
| 2328 | if (!is_edp(intel_dp)) |
| 2329 | return; |
| 2330 | |
| 2331 | DRM_DEBUG_KMS("\n"); |
| 2332 | |
| 2333 | intel_panel_enable_backlight(intel_dp->attached_connector); |
| 2334 | _intel_edp_backlight_on(intel_dp); |
| 2335 | } |
| 2336 | |
| 2337 | /* Disable backlight in the panel power control. */ |
| 2338 | static void _intel_edp_backlight_off(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2339 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2340 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2341 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2342 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2343 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2344 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2345 | if (!is_edp(intel_dp)) |
| 2346 | return; |
| 2347 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2348 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2349 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2350 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2351 | pp &= ~EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2352 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2353 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2354 | |
| 2355 | I915_WRITE(pp_ctrl_reg, pp); |
| 2356 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2357 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2358 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2359 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2360 | intel_dp->last_backlight_off = jiffies; |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2361 | edp_wait_backlight_off(intel_dp); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2362 | } |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2363 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2364 | /* Disable backlight PP control and backlight PWM. */ |
| 2365 | void intel_edp_backlight_off(struct intel_dp *intel_dp) |
| 2366 | { |
| 2367 | if (!is_edp(intel_dp)) |
| 2368 | return; |
| 2369 | |
| 2370 | DRM_DEBUG_KMS("\n"); |
| 2371 | |
| 2372 | _intel_edp_backlight_off(intel_dp); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2373 | intel_panel_disable_backlight(intel_dp->attached_connector); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2374 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2375 | |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2376 | /* |
| 2377 | * Hook for controlling the panel power control backlight through the bl_power |
| 2378 | * sysfs attribute. Take care to handle multiple calls. |
| 2379 | */ |
| 2380 | static void intel_edp_backlight_power(struct intel_connector *connector, |
| 2381 | bool enable) |
| 2382 | { |
| 2383 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2384 | bool is_enabled; |
| 2385 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2386 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2387 | is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2388 | pps_unlock(intel_dp); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2389 | |
| 2390 | if (is_enabled == enable) |
| 2391 | return; |
| 2392 | |
Jani Nikula | 23ba937 | 2014-08-27 14:08:43 +0300 | [diff] [blame] | 2393 | DRM_DEBUG_KMS("panel power control backlight %s\n", |
| 2394 | enable ? "enable" : "disable"); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2395 | |
| 2396 | if (enable) |
| 2397 | _intel_edp_backlight_on(intel_dp); |
| 2398 | else |
| 2399 | _intel_edp_backlight_off(intel_dp); |
| 2400 | } |
| 2401 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2402 | static void assert_dp_port(struct intel_dp *intel_dp, bool state) |
| 2403 | { |
| 2404 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 2405 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 2406 | bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN; |
| 2407 | |
| 2408 | I915_STATE_WARN(cur_state != state, |
| 2409 | "DP port %c state assertion failure (expected %s, current %s)\n", |
| 2410 | port_name(dig_port->port), |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2411 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2412 | } |
| 2413 | #define assert_dp_port_disabled(d) assert_dp_port((d), false) |
| 2414 | |
| 2415 | static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state) |
| 2416 | { |
| 2417 | bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE; |
| 2418 | |
| 2419 | I915_STATE_WARN(cur_state != state, |
| 2420 | "eDP PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2421 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2422 | } |
| 2423 | #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) |
| 2424 | #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) |
| 2425 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2426 | static void ironlake_edp_pll_on(struct intel_dp *intel_dp, |
| 2427 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2428 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2429 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2430 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2431 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2432 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2433 | assert_dp_port_disabled(intel_dp); |
| 2434 | assert_edp_pll_disabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2435 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2436 | DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n", |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2437 | pipe_config->port_clock); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2438 | |
| 2439 | intel_dp->DP &= ~DP_PLL_FREQ_MASK; |
| 2440 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2441 | if (pipe_config->port_clock == 162000) |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2442 | intel_dp->DP |= DP_PLL_FREQ_162MHZ; |
| 2443 | else |
| 2444 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
| 2445 | |
| 2446 | I915_WRITE(DP_A, intel_dp->DP); |
| 2447 | POSTING_READ(DP_A); |
| 2448 | udelay(500); |
| 2449 | |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2450 | /* |
| 2451 | * [DevILK] Work around required when enabling DP PLL |
| 2452 | * while a pipe is enabled going to FDI: |
| 2453 | * 1. Wait for the start of vertical blank on the enabled pipe going to FDI |
| 2454 | * 2. Program DP PLL enable |
| 2455 | */ |
| 2456 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 2457 | intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe); |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2458 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2459 | intel_dp->DP |= DP_PLL_ENABLE; |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2460 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2461 | I915_WRITE(DP_A, intel_dp->DP); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 2462 | POSTING_READ(DP_A); |
| 2463 | udelay(200); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2466 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2467 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2468 | 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] | 2469 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
| 2470 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2471 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2472 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2473 | assert_dp_port_disabled(intel_dp); |
| 2474 | assert_edp_pll_enabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2475 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2476 | DRM_DEBUG_KMS("disabling eDP PLL\n"); |
| 2477 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2478 | intel_dp->DP &= ~DP_PLL_ENABLE; |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2479 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2480 | I915_WRITE(DP_A, intel_dp->DP); |
Chris Wilson | 1af5fa1 | 2010-09-08 21:07:28 +0100 | [diff] [blame] | 2481 | POSTING_READ(DP_A); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2482 | udelay(200); |
| 2483 | } |
| 2484 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2485 | /* If the sink supports it, try to set the power state appropriately */ |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2486 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2487 | { |
| 2488 | int ret, i; |
| 2489 | |
| 2490 | /* Should have a valid DPCD by this point */ |
| 2491 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 2492 | return; |
| 2493 | |
| 2494 | if (mode != DRM_MODE_DPMS_ON) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2495 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2496 | DP_SET_POWER_D3); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2497 | } else { |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2498 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
| 2499 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2500 | /* |
| 2501 | * When turning on, we need to retry for 1ms to give the sink |
| 2502 | * time to wake up. |
| 2503 | */ |
| 2504 | for (i = 0; i < 3; i++) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2505 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2506 | DP_SET_POWER_D0); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2507 | if (ret == 1) |
| 2508 | break; |
| 2509 | msleep(1); |
| 2510 | } |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2511 | |
| 2512 | if (ret == 1 && lspcon->active) |
| 2513 | lspcon_wait_pcon_mode(lspcon); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2514 | } |
Jani Nikula | f9cac72 | 2014-09-02 16:33:52 +0300 | [diff] [blame] | 2515 | |
| 2516 | if (ret != 1) |
| 2517 | DRM_DEBUG_KMS("failed to %s sink power state\n", |
| 2518 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2521 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
| 2522 | enum pipe *pipe) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2523 | { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2524 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 2525 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2526 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2527 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2528 | u32 tmp; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2529 | bool ret; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2530 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2531 | if (!intel_display_power_get_if_enabled(dev_priv, |
| 2532 | encoder->power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2533 | return false; |
| 2534 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2535 | ret = false; |
| 2536 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2537 | tmp = I915_READ(intel_dp->output_reg); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2538 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2539 | if (!(tmp & DP_PORT_EN)) |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2540 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2541 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2542 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2543 | *pipe = PORT_TO_PIPE_CPT(tmp); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2544 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2545 | enum pipe p; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2546 | |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2547 | for_each_pipe(dev_priv, p) { |
| 2548 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); |
| 2549 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { |
| 2550 | *pipe = p; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2551 | ret = true; |
| 2552 | |
| 2553 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2554 | } |
| 2555 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2556 | |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2557 | 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] | 2558 | i915_mmio_reg_offset(intel_dp->output_reg)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2559 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2560 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); |
| 2561 | } else { |
| 2562 | *pipe = PORT_TO_PIPE(tmp); |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2563 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2564 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2565 | ret = true; |
| 2566 | |
| 2567 | out: |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2568 | intel_display_power_put(dev_priv, encoder->power_domain); |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2569 | |
| 2570 | return ret; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2571 | } |
| 2572 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2573 | static void intel_dp_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2574 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2575 | { |
| 2576 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2577 | u32 tmp, flags = 0; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2578 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2579 | struct drm_i915_private *dev_priv = to_i915(dev); |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2580 | enum port port = dp_to_dig_port(intel_dp)->port; |
| 2581 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2582 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2583 | tmp = I915_READ(intel_dp->output_reg); |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 2584 | |
| 2585 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2586 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2587 | if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2588 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 2589 | |
| 2590 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2591 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2592 | else |
| 2593 | flags |= DRM_MODE_FLAG_NHSYNC; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2594 | |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2595 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2596 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2597 | else |
| 2598 | flags |= DRM_MODE_FLAG_NVSYNC; |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2599 | } else { |
| 2600 | if (tmp & DP_SYNC_HS_HIGH) |
| 2601 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2602 | else |
| 2603 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2604 | |
| 2605 | if (tmp & DP_SYNC_VS_HIGH) |
| 2606 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2607 | else |
| 2608 | flags |= DRM_MODE_FLAG_NVSYNC; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2609 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2610 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2611 | pipe_config->base.adjusted_mode.flags |= flags; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2612 | |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 2613 | if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235) |
Ville Syrjälä | 8c875fc | 2014-09-12 15:46:29 +0300 | [diff] [blame] | 2614 | pipe_config->limited_color_range = true; |
| 2615 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2616 | pipe_config->lane_count = |
| 2617 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; |
| 2618 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2619 | intel_dp_get_m_n(crtc, pipe_config); |
| 2620 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2621 | if (port == PORT_A) { |
Ville Syrjälä | b377e0d | 2015-10-29 21:25:59 +0200 | [diff] [blame] | 2622 | 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] | 2623 | pipe_config->port_clock = 162000; |
| 2624 | else |
| 2625 | pipe_config->port_clock = 270000; |
| 2626 | } |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2627 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 2628 | pipe_config->base.adjusted_mode.crtc_clock = |
| 2629 | intel_dotclock_calculate(pipe_config->port_clock, |
| 2630 | &pipe_config->dp_m_n); |
Daniel Vetter | 7f16e5c | 2013-11-04 16:28:47 +0100 | [diff] [blame] | 2631 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2632 | if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp && |
| 2633 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2634 | /* |
| 2635 | * This is a big fat ugly hack. |
| 2636 | * |
| 2637 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2638 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2639 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2640 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2641 | * max, not what it tells us to use. |
| 2642 | * |
| 2643 | * Note: This will still be broken if the eDP panel is not lit |
| 2644 | * up by the BIOS, and thus we can't get the mode at module |
| 2645 | * load. |
| 2646 | */ |
| 2647 | 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] | 2648 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2649 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2650 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2653 | static void intel_disable_dp(struct intel_encoder *encoder, |
| 2654 | struct intel_crtc_state *old_crtc_state, |
| 2655 | struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2656 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2657 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2658 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2659 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2660 | if (old_crtc_state->has_audio) |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2661 | intel_audio_codec_disable(encoder); |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2662 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2663 | if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv)) |
Rodrigo Vivi | b32c6f4 | 2014-11-20 03:44:37 -0800 | [diff] [blame] | 2664 | intel_psr_disable(intel_dp); |
| 2665 | |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2666 | /* Make sure the panel is off before trying to change the mode. But also |
| 2667 | * ensure that we have vdd while we switch off the panel. */ |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2668 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2669 | intel_edp_backlight_off(intel_dp); |
Jani Nikula | fdbc3b1 | 2013-11-12 17:10:13 +0200 | [diff] [blame] | 2670 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2671 | intel_edp_panel_off(intel_dp); |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2672 | |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2673 | /* disable the port before the pipe on g4x */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2674 | if (INTEL_GEN(dev_priv) < 5) |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2675 | intel_dp_link_down(intel_dp); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2678 | static void ilk_post_disable_dp(struct intel_encoder *encoder, |
| 2679 | struct intel_crtc_state *old_crtc_state, |
| 2680 | struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2681 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2682 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | 982a386 | 2013-05-23 19:39:40 +0300 | [diff] [blame] | 2683 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2684 | |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2685 | intel_dp_link_down(intel_dp); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2686 | |
| 2687 | /* Only ilk+ has port A */ |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2688 | if (port == PORT_A) |
| 2689 | ironlake_edp_pll_off(intel_dp); |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2690 | } |
| 2691 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2692 | static void vlv_post_disable_dp(struct intel_encoder *encoder, |
| 2693 | struct intel_crtc_state *old_crtc_state, |
| 2694 | struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2695 | { |
| 2696 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2697 | |
| 2698 | intel_dp_link_down(intel_dp); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2699 | } |
| 2700 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2701 | static void chv_post_disable_dp(struct intel_encoder *encoder, |
| 2702 | struct intel_crtc_state *old_crtc_state, |
| 2703 | struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2704 | { |
| 2705 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2706 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2707 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2708 | |
| 2709 | intel_dp_link_down(intel_dp); |
| 2710 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2711 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2712 | |
Ville Syrjälä | a8f327f | 2015-07-09 20:14:11 +0300 | [diff] [blame] | 2713 | /* Assert data lane reset */ |
| 2714 | chv_data_lane_soft_reset(encoder, true); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2715 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2716 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2717 | } |
| 2718 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2719 | static void |
| 2720 | _intel_dp_set_link_train(struct intel_dp *intel_dp, |
| 2721 | uint32_t *DP, |
| 2722 | uint8_t dp_train_pat) |
| 2723 | { |
| 2724 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2725 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2726 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2727 | enum port port = intel_dig_port->port; |
| 2728 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2729 | if (dp_train_pat & DP_TRAINING_PATTERN_MASK) |
| 2730 | DRM_DEBUG_KMS("Using DP training pattern TPS%d\n", |
| 2731 | dp_train_pat & DP_TRAINING_PATTERN_MASK); |
| 2732 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 2733 | if (HAS_DDI(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2734 | uint32_t temp = I915_READ(DP_TP_CTL(port)); |
| 2735 | |
| 2736 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) |
| 2737 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2738 | else |
| 2739 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2740 | |
| 2741 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 2742 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2743 | case DP_TRAINING_PATTERN_DISABLE: |
| 2744 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; |
| 2745 | |
| 2746 | break; |
| 2747 | case DP_TRAINING_PATTERN_1: |
| 2748 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2749 | break; |
| 2750 | case DP_TRAINING_PATTERN_2: |
| 2751 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; |
| 2752 | break; |
| 2753 | case DP_TRAINING_PATTERN_3: |
| 2754 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; |
| 2755 | break; |
| 2756 | } |
| 2757 | I915_WRITE(DP_TP_CTL(port), temp); |
| 2758 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2759 | } else if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2760 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2761 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 2762 | |
| 2763 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2764 | case DP_TRAINING_PATTERN_DISABLE: |
| 2765 | *DP |= DP_LINK_TRAIN_OFF_CPT; |
| 2766 | break; |
| 2767 | case DP_TRAINING_PATTERN_1: |
| 2768 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; |
| 2769 | break; |
| 2770 | case DP_TRAINING_PATTERN_2: |
| 2771 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2772 | break; |
| 2773 | case DP_TRAINING_PATTERN_3: |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2774 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2775 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2776 | break; |
| 2777 | } |
| 2778 | |
| 2779 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2780 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2781 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 2782 | else |
| 2783 | *DP &= ~DP_LINK_TRAIN_MASK; |
| 2784 | |
| 2785 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2786 | case DP_TRAINING_PATTERN_DISABLE: |
| 2787 | *DP |= DP_LINK_TRAIN_OFF; |
| 2788 | break; |
| 2789 | case DP_TRAINING_PATTERN_1: |
| 2790 | *DP |= DP_LINK_TRAIN_PAT_1; |
| 2791 | break; |
| 2792 | case DP_TRAINING_PATTERN_2: |
| 2793 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2794 | break; |
| 2795 | case DP_TRAINING_PATTERN_3: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2796 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2797 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; |
| 2798 | } else { |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2799 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2800 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2801 | } |
| 2802 | break; |
| 2803 | } |
| 2804 | } |
| 2805 | } |
| 2806 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2807 | static void intel_dp_enable_port(struct intel_dp *intel_dp, |
| 2808 | struct intel_crtc_state *old_crtc_state) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2809 | { |
| 2810 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2811 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2812 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2813 | /* enable with pattern 1 (as per spec) */ |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2814 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2815 | 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] | 2816 | |
| 2817 | /* |
| 2818 | * Magic for VLV/CHV. We _must_ first set up the register |
| 2819 | * without actually enabling the port, and then do another |
| 2820 | * write to enable the port. Otherwise link training will |
| 2821 | * fail when the power sequencer is freshly used for this port. |
| 2822 | */ |
| 2823 | intel_dp->DP |= DP_PORT_EN; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2824 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2825 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2826 | |
| 2827 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 2828 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2829 | } |
| 2830 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2831 | static void intel_enable_dp(struct intel_encoder *encoder, |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2832 | struct intel_crtc_state *pipe_config, |
| 2833 | struct drm_connector_state *conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2834 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2835 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2836 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2837 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2838 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2839 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2840 | enum pipe pipe = crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2841 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 2842 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
| 2843 | return; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2844 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2845 | pps_lock(intel_dp); |
| 2846 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2847 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2848 | vlv_init_panel_power_sequencer(intel_dp); |
| 2849 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2850 | intel_dp_enable_port(intel_dp, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2851 | |
| 2852 | edp_panel_vdd_on(intel_dp); |
| 2853 | edp_panel_on(intel_dp); |
| 2854 | edp_panel_vdd_off(intel_dp, true); |
| 2855 | |
| 2856 | pps_unlock(intel_dp); |
| 2857 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2858 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2859 | unsigned int lane_mask = 0x0; |
| 2860 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2861 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2862 | lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2863 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 2864 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
| 2865 | lane_mask); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2866 | } |
Ville Syrjälä | 61234fa | 2014-10-16 21:27:34 +0300 | [diff] [blame] | 2867 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2868 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 2869 | intel_dp_start_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2870 | intel_dp_stop_link_train(intel_dp); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2871 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2872 | if (pipe_config->has_audio) { |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2873 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2874 | pipe_name(pipe)); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2875 | intel_audio_codec_enable(encoder, pipe_config, conn_state); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2876 | } |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2877 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2878 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2879 | static void g4x_enable_dp(struct intel_encoder *encoder, |
| 2880 | struct intel_crtc_state *pipe_config, |
| 2881 | struct drm_connector_state *conn_state) |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 2882 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2883 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2884 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2885 | intel_enable_dp(encoder, pipe_config, conn_state); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2886 | intel_edp_backlight_on(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2887 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2888 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2889 | static void vlv_enable_dp(struct intel_encoder *encoder, |
| 2890 | struct intel_crtc_state *pipe_config, |
| 2891 | struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2892 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2893 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2894 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2895 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | b32c6f4 | 2014-11-20 03:44:37 -0800 | [diff] [blame] | 2896 | intel_psr_enable(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2899 | static void g4x_pre_enable_dp(struct intel_encoder *encoder, |
| 2900 | struct intel_crtc_state *pipe_config, |
| 2901 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2902 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2903 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2904 | enum port port = dp_to_dig_port(intel_dp)->port; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2905 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2906 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 2907 | |
Daniel Vetter | d41f1ef | 2014-04-24 23:54:53 +0200 | [diff] [blame] | 2908 | /* Only ilk+ has port A */ |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2909 | if (port == PORT_A) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2910 | ironlake_edp_pll_on(intel_dp, pipe_config); |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2911 | } |
| 2912 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2913 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
| 2914 | { |
| 2915 | 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] | 2916 | 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] | 2917 | enum pipe pipe = intel_dp->pps_pipe; |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 2918 | i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2919 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2920 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 2921 | |
Ville Syrjälä | d158694 | 2017-02-08 19:52:54 +0200 | [diff] [blame] | 2922 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 2923 | return; |
| 2924 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2925 | edp_panel_vdd_off_sync(intel_dp); |
| 2926 | |
| 2927 | /* |
| 2928 | * VLV seems to get confused when multiple power seqeuencers |
| 2929 | * have the same port selected (even if only one has power/vdd |
| 2930 | * enabled). The failure manifests as vlv_wait_port_ready() failing |
| 2931 | * CHV on the other hand doesn't seem to mind having the same port |
| 2932 | * selected in multiple power seqeuencers, but let's clear the |
| 2933 | * port select always when logically disconnecting a power sequencer |
| 2934 | * from a port. |
| 2935 | */ |
| 2936 | DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n", |
| 2937 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 2938 | I915_WRITE(pp_on_reg, 0); |
| 2939 | POSTING_READ(pp_on_reg); |
| 2940 | |
| 2941 | intel_dp->pps_pipe = INVALID_PIPE; |
| 2942 | } |
| 2943 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2944 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 2945 | enum pipe pipe) |
| 2946 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2947 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2948 | struct intel_encoder *encoder; |
| 2949 | |
| 2950 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2951 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 2952 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2953 | struct intel_dp *intel_dp; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2954 | enum port port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2955 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2956 | if (encoder->type != INTEL_OUTPUT_DP && |
| 2957 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2958 | continue; |
| 2959 | |
| 2960 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2961 | port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2962 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2963 | WARN(intel_dp->active_pipe == pipe, |
| 2964 | "stealing pipe %c power sequencer from active (e)DP port %c\n", |
| 2965 | pipe_name(pipe), port_name(port)); |
| 2966 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2967 | if (intel_dp->pps_pipe != pipe) |
| 2968 | continue; |
| 2969 | |
| 2970 | 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] | 2971 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2972 | |
| 2973 | /* make sure vdd is off before we steal it */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2974 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp) |
| 2979 | { |
| 2980 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2981 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 2982 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2983 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2984 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2985 | |
| 2986 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2987 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2988 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2989 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2990 | if (intel_dp->pps_pipe != INVALID_PIPE && |
| 2991 | intel_dp->pps_pipe != crtc->pipe) { |
| 2992 | /* |
| 2993 | * If another power sequencer was being used on this |
| 2994 | * port previously make sure to turn off vdd there while |
| 2995 | * we still have control of it. |
| 2996 | */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2997 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2998 | } |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2999 | |
| 3000 | /* |
| 3001 | * We may be stealing the power |
| 3002 | * sequencer from another port. |
| 3003 | */ |
| 3004 | vlv_steal_power_sequencer(dev, crtc->pipe); |
| 3005 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3006 | intel_dp->active_pipe = crtc->pipe; |
| 3007 | |
| 3008 | if (!is_edp(intel_dp)) |
| 3009 | return; |
| 3010 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3011 | /* now it's all ours */ |
| 3012 | intel_dp->pps_pipe = crtc->pipe; |
| 3013 | |
| 3014 | DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n", |
| 3015 | pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port)); |
| 3016 | |
| 3017 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 3018 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 3019 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3020 | } |
| 3021 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3022 | static void vlv_pre_enable_dp(struct intel_encoder *encoder, |
| 3023 | struct intel_crtc_state *pipe_config, |
| 3024 | struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3025 | { |
Ander Conselvan de Oliveira | 5f68c27 | 2016-04-27 15:44:24 +0300 | [diff] [blame] | 3026 | vlv_phy_pre_encoder_enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3027 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3028 | intel_enable_dp(encoder, pipe_config, conn_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3031 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder, |
| 3032 | struct intel_crtc_state *pipe_config, |
| 3033 | struct drm_connector_state *conn_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3034 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3035 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 3036 | |
Ander Conselvan de Oliveira | 6da2e61 | 2016-04-27 15:44:23 +0300 | [diff] [blame] | 3037 | vlv_phy_pre_pll_enable(encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3040 | static void chv_pre_enable_dp(struct intel_encoder *encoder, |
| 3041 | struct intel_crtc_state *pipe_config, |
| 3042 | struct drm_connector_state *conn_state) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3043 | { |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3044 | chv_phy_pre_encoder_enable(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3045 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3046 | intel_enable_dp(encoder, pipe_config, conn_state); |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 3047 | |
| 3048 | /* Second common lane will stay alive on its own now */ |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3049 | chv_phy_release_cl2_override(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3050 | } |
| 3051 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3052 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder, |
| 3053 | struct intel_crtc_state *pipe_config, |
| 3054 | struct drm_connector_state *conn_state) |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3055 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3056 | intel_dp_prepare(encoder, pipe_config); |
Ville Syrjälä | 625695f | 2014-06-28 02:04:02 +0300 | [diff] [blame] | 3057 | |
Ander Conselvan de Oliveira | 419b1b7 | 2016-04-27 15:44:19 +0300 | [diff] [blame] | 3058 | chv_phy_pre_pll_enable(encoder); |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3059 | } |
| 3060 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3061 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder, |
| 3062 | struct intel_crtc_state *pipe_config, |
| 3063 | struct drm_connector_state *conn_state) |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3064 | { |
Ander Conselvan de Oliveira | 204970b | 2016-04-27 15:44:21 +0300 | [diff] [blame] | 3065 | chv_phy_post_pll_disable(encoder); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3066 | } |
| 3067 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3068 | /* |
| 3069 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 3070 | * link status information |
| 3071 | */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3072 | bool |
Keith Packard | 93f62da | 2011-11-01 19:45:03 -0700 | [diff] [blame] | 3073 | 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] | 3074 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3075 | return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status, |
| 3076 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3079 | static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp) |
| 3080 | { |
| 3081 | uint8_t psr_caps = 0; |
| 3082 | |
| 3083 | drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps); |
| 3084 | return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED; |
| 3085 | } |
| 3086 | |
| 3087 | static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) |
| 3088 | { |
| 3089 | uint8_t dprx = 0; |
| 3090 | |
| 3091 | drm_dp_dpcd_readb(&intel_dp->aux, |
| 3092 | DP_DPRX_FEATURE_ENUMERATION_LIST, |
| 3093 | &dprx); |
| 3094 | return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED; |
| 3095 | } |
| 3096 | |
Chris Wilson | a76f73d | 2017-01-14 10:51:13 +0000 | [diff] [blame] | 3097 | static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp) |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3098 | { |
| 3099 | uint8_t alpm_caps = 0; |
| 3100 | |
| 3101 | drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps); |
| 3102 | return alpm_caps & DP_ALPM_CAP; |
| 3103 | } |
| 3104 | |
Paulo Zanoni | 1100244 | 2014-06-13 18:45:41 -0300 | [diff] [blame] | 3105 | /* These are source-specific values. */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3106 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3107 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3108 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3109 | 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] | 3110 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3111 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 3112 | if (IS_GEN9_LP(dev_priv)) |
Vandana Kannan | 9314726 | 2014-11-18 15:45:29 +0530 | [diff] [blame] | 3113 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3114 | else if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | ffe5111 | 2017-02-23 19:49:01 +0200 | [diff] [blame] | 3115 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3116 | return intel_ddi_dp_voltage_max(encoder); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3117 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3118 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3119 | else if (IS_GEN7(dev_priv) && port == PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3120 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3121 | else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3122 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3123 | else |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3124 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3125 | } |
| 3126 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3127 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3128 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
| 3129 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3130 | 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] | 3131 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3132 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3133 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3134 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 3135 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3136 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3137 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3138 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3139 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3140 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3141 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
| 3142 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3143 | default: |
| 3144 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
| 3145 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3146 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3147 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3148 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3149 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3150 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3151 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3152 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3153 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3154 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3155 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3156 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3157 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3158 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3159 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3160 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3161 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3162 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3163 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3164 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3165 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3166 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3167 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3168 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3169 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3170 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3171 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3172 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3173 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3174 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3175 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3176 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3177 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3178 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3179 | } |
| 3180 | } else { |
| 3181 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3182 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3183 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3184 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3185 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3186 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3187 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3188 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3189 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3190 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3191 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3195 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3196 | { |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3197 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3198 | unsigned long demph_reg_value, preemph_reg_value, |
| 3199 | uniqtranscale_reg_value; |
| 3200 | uint8_t train_set = intel_dp->train_set[0]; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3201 | |
| 3202 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3203 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3204 | preemph_reg_value = 0x0004000; |
| 3205 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3206 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3207 | demph_reg_value = 0x2B405555; |
| 3208 | uniqtranscale_reg_value = 0x552AB83A; |
| 3209 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3210 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3211 | demph_reg_value = 0x2B404040; |
| 3212 | uniqtranscale_reg_value = 0x5548B83A; |
| 3213 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3214 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3215 | demph_reg_value = 0x2B245555; |
| 3216 | uniqtranscale_reg_value = 0x5560B83A; |
| 3217 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3218 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3219 | demph_reg_value = 0x2B405555; |
| 3220 | uniqtranscale_reg_value = 0x5598DA3A; |
| 3221 | break; |
| 3222 | default: |
| 3223 | return 0; |
| 3224 | } |
| 3225 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3226 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3227 | preemph_reg_value = 0x0002000; |
| 3228 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3229 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3230 | demph_reg_value = 0x2B404040; |
| 3231 | uniqtranscale_reg_value = 0x5552B83A; |
| 3232 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3233 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3234 | demph_reg_value = 0x2B404848; |
| 3235 | uniqtranscale_reg_value = 0x5580B83A; |
| 3236 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3237 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3238 | demph_reg_value = 0x2B404040; |
| 3239 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3240 | break; |
| 3241 | default: |
| 3242 | return 0; |
| 3243 | } |
| 3244 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3245 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3246 | preemph_reg_value = 0x0000000; |
| 3247 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3248 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3249 | demph_reg_value = 0x2B305555; |
| 3250 | uniqtranscale_reg_value = 0x5570B83A; |
| 3251 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3252 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3253 | demph_reg_value = 0x2B2B4040; |
| 3254 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3255 | break; |
| 3256 | default: |
| 3257 | return 0; |
| 3258 | } |
| 3259 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3260 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3261 | preemph_reg_value = 0x0006000; |
| 3262 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3263 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3264 | demph_reg_value = 0x1B405555; |
| 3265 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3266 | break; |
| 3267 | default: |
| 3268 | return 0; |
| 3269 | } |
| 3270 | break; |
| 3271 | default: |
| 3272 | return 0; |
| 3273 | } |
| 3274 | |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3275 | vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value, |
| 3276 | uniqtranscale_reg_value, 0); |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3277 | |
| 3278 | return 0; |
| 3279 | } |
| 3280 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3281 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3282 | { |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3283 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3284 | u32 deemph_reg_value, margin_reg_value; |
| 3285 | bool uniq_trans_scale = false; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3286 | uint8_t train_set = intel_dp->train_set[0]; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3287 | |
| 3288 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3289 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3290 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3291 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3292 | deemph_reg_value = 128; |
| 3293 | margin_reg_value = 52; |
| 3294 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3295 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3296 | deemph_reg_value = 128; |
| 3297 | margin_reg_value = 77; |
| 3298 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3299 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3300 | deemph_reg_value = 128; |
| 3301 | margin_reg_value = 102; |
| 3302 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3303 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3304 | deemph_reg_value = 128; |
| 3305 | margin_reg_value = 154; |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3306 | uniq_trans_scale = true; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3307 | break; |
| 3308 | default: |
| 3309 | return 0; |
| 3310 | } |
| 3311 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3312 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3313 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3314 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3315 | deemph_reg_value = 85; |
| 3316 | margin_reg_value = 78; |
| 3317 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3318 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3319 | deemph_reg_value = 85; |
| 3320 | margin_reg_value = 116; |
| 3321 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3322 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3323 | deemph_reg_value = 85; |
| 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_2: |
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 = 64; |
| 3334 | margin_reg_value = 104; |
| 3335 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3336 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3337 | deemph_reg_value = 64; |
| 3338 | margin_reg_value = 154; |
| 3339 | break; |
| 3340 | default: |
| 3341 | return 0; |
| 3342 | } |
| 3343 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3344 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3345 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3346 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3347 | deemph_reg_value = 43; |
| 3348 | margin_reg_value = 154; |
| 3349 | break; |
| 3350 | default: |
| 3351 | return 0; |
| 3352 | } |
| 3353 | break; |
| 3354 | default: |
| 3355 | return 0; |
| 3356 | } |
| 3357 | |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3358 | chv_set_phy_signal_level(encoder, deemph_reg_value, |
| 3359 | margin_reg_value, uniq_trans_scale); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3360 | |
| 3361 | return 0; |
| 3362 | } |
| 3363 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3364 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3365 | gen4_signal_levels(uint8_t train_set) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3366 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3367 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3368 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3369 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3370 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3371 | default: |
| 3372 | signal_levels |= DP_VOLTAGE_0_4; |
| 3373 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3374 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3375 | signal_levels |= DP_VOLTAGE_0_6; |
| 3376 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3377 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3378 | signal_levels |= DP_VOLTAGE_0_8; |
| 3379 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3380 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3381 | signal_levels |= DP_VOLTAGE_1_2; |
| 3382 | break; |
| 3383 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3384 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3385 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3386 | default: |
| 3387 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 3388 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3389 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3390 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 3391 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3392 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3393 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 3394 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3395 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3396 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 3397 | break; |
| 3398 | } |
| 3399 | return signal_levels; |
| 3400 | } |
| 3401 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3402 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 3403 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3404 | gen6_edp_signal_levels(uint8_t train_set) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3405 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3406 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3407 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3408 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3409 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3410 | 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] | 3411 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3412 | 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] | 3413 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3414 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 3415 | 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] | 3416 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3417 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 3418 | 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] | 3419 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3420 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3421 | 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] | 3422 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3423 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3424 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3425 | "0x%x\n", signal_levels); |
| 3426 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3427 | } |
| 3428 | } |
| 3429 | |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3430 | /* Gen7's DP voltage swing and pre-emphasis control */ |
| 3431 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3432 | gen7_edp_signal_levels(uint8_t train_set) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3433 | { |
| 3434 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3435 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3436 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3437 | 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] | 3438 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3439 | 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] | 3440 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3441 | 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] | 3442 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
| 3443 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3444 | 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] | 3445 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3446 | 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] | 3447 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
| 3448 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3449 | 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] | 3450 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3451 | 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] | 3452 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
| 3453 | |
| 3454 | default: |
| 3455 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3456 | "0x%x\n", signal_levels); |
| 3457 | return EDP_LINK_TRAIN_500MV_0DB_IVB; |
| 3458 | } |
| 3459 | } |
| 3460 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3461 | void |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3462 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3463 | { |
| 3464 | 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] | 3465 | enum port port = intel_dig_port->port; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3466 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3467 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3468 | uint32_t signal_levels, mask = 0; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3469 | uint8_t train_set = intel_dp->train_set[0]; |
| 3470 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3471 | if (HAS_DDI(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3472 | signal_levels = ddi_signal_levels(intel_dp); |
| 3473 | |
Michel Thierry | 254e093 | 2017-01-09 16:51:35 +0200 | [diff] [blame] | 3474 | if (IS_GEN9_LP(dev_priv)) |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3475 | signal_levels = 0; |
| 3476 | else |
| 3477 | mask = DDI_BUF_EMP_MASK; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3478 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3479 | signal_levels = chv_signal_levels(intel_dp); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 3480 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3481 | signal_levels = vlv_signal_levels(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3482 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3483 | signal_levels = gen7_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3484 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3485 | } else if (IS_GEN6(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3486 | signal_levels = gen6_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3487 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
| 3488 | } else { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3489 | signal_levels = gen4_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3490 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
| 3491 | } |
| 3492 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 3493 | if (mask) |
| 3494 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); |
| 3495 | |
| 3496 | DRM_DEBUG_KMS("Using vswing level %d\n", |
| 3497 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); |
| 3498 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", |
| 3499 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> |
| 3500 | DP_TRAIN_PRE_EMPHASIS_SHIFT); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3501 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3502 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3503 | |
| 3504 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 3505 | POSTING_READ(intel_dp->output_reg); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3506 | } |
| 3507 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3508 | void |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3509 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
| 3510 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3511 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 3512 | 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] | 3513 | struct drm_i915_private *dev_priv = |
| 3514 | to_i915(intel_dig_port->base.base.dev); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3515 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3516 | _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] | 3517 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3518 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3519 | POSTING_READ(intel_dp->output_reg); |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3520 | } |
| 3521 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3522 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3523 | { |
| 3524 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3525 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3526 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3527 | enum port port = intel_dig_port->port; |
| 3528 | uint32_t val; |
| 3529 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3530 | if (!HAS_DDI(dev_priv)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3531 | return; |
| 3532 | |
| 3533 | val = I915_READ(DP_TP_CTL(port)); |
| 3534 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 3535 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; |
| 3536 | I915_WRITE(DP_TP_CTL(port), val); |
| 3537 | |
| 3538 | /* |
| 3539 | * On PORT_A we can have only eDP in SST mode. There the only reason |
| 3540 | * we need to set idle transmission mode is to work around a HW issue |
| 3541 | * where we enable the pipe while not in idle link-training mode. |
| 3542 | * In this case there is requirement to wait for a minimum number of |
| 3543 | * idle patterns to be sent. |
| 3544 | */ |
| 3545 | if (port == PORT_A) |
| 3546 | return; |
| 3547 | |
Chris Wilson | a767017 | 2016-06-30 15:33:10 +0100 | [diff] [blame] | 3548 | if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port), |
| 3549 | DP_TP_STATUS_IDLE_DONE, |
| 3550 | DP_TP_STATUS_IDLE_DONE, |
| 3551 | 1)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3552 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); |
| 3553 | } |
| 3554 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3555 | static void |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3556 | intel_dp_link_down(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3557 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3558 | 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] | 3559 | 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] | 3560 | enum port port = intel_dig_port->port; |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3561 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3562 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3563 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3564 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3565 | if (WARN_ON(HAS_DDI(dev_priv))) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 3566 | return; |
| 3567 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 3568 | 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] | 3569 | return; |
| 3570 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3571 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3572 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3573 | if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3574 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3575 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3576 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3577 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3578 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | aad3d14 | 2014-06-28 02:04:25 +0300 | [diff] [blame] | 3579 | DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 3580 | else |
| 3581 | DP &= ~DP_LINK_TRAIN_MASK; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3582 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3583 | } |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3584 | I915_WRITE(intel_dp->output_reg, DP); |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 3585 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3586 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3587 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
| 3588 | I915_WRITE(intel_dp->output_reg, DP); |
| 3589 | POSTING_READ(intel_dp->output_reg); |
| 3590 | |
| 3591 | /* |
| 3592 | * HW workaround for IBX, we need to move the port |
| 3593 | * to transcoder A after disabling it to allow the |
| 3594 | * matching HDMI port to be enabled on transcoder A. |
| 3595 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3596 | 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] | 3597 | /* |
| 3598 | * We get CPU/PCH FIFO underruns on the other pipe when |
| 3599 | * doing the workaround. Sweep them under the rug. |
| 3600 | */ |
| 3601 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3602 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3603 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3604 | /* always enable with pattern 1 (as per spec) */ |
| 3605 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); |
| 3606 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; |
| 3607 | I915_WRITE(intel_dp->output_reg, DP); |
| 3608 | POSTING_READ(intel_dp->output_reg); |
| 3609 | |
| 3610 | DP &= ~DP_PORT_EN; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3611 | I915_WRITE(intel_dp->output_reg, DP); |
Daniel Vetter | 0ca0968 | 2014-11-24 16:54:11 +0100 | [diff] [blame] | 3612 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3613 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3614 | intel_wait_for_vblank_if_active(dev_priv, PIPE_A); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3615 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
| 3616 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3617 | } |
| 3618 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 3619 | msleep(intel_dp->panel_power_down_delay); |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 3620 | |
| 3621 | intel_dp->DP = DP; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3622 | |
| 3623 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 3624 | pps_lock(intel_dp); |
| 3625 | intel_dp->active_pipe = INVALID_PIPE; |
| 3626 | pps_unlock(intel_dp); |
| 3627 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Imre Deak | 24e807e | 2016-10-24 19:33:28 +0300 | [diff] [blame] | 3630 | bool |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3631 | intel_dp_read_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3632 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3633 | if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, |
| 3634 | sizeof(intel_dp->dpcd)) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3635 | return false; /* aux transfer failed */ |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3636 | |
Andy Shevchenko | a8e9815 | 2014-09-01 14:12:01 +0300 | [diff] [blame] | 3637 | 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] | 3638 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3639 | return intel_dp->dpcd[DP_DPCD_REV] != 0; |
| 3640 | } |
| 3641 | |
| 3642 | static bool |
| 3643 | intel_edp_init_dpcd(struct intel_dp *intel_dp) |
| 3644 | { |
| 3645 | struct drm_i915_private *dev_priv = |
| 3646 | to_i915(dp_to_dig_port(intel_dp)->base.base.dev); |
| 3647 | |
| 3648 | /* this function is meant to be called only once */ |
| 3649 | WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0); |
| 3650 | |
| 3651 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3652 | return false; |
| 3653 | |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 3654 | intel_dp_read_desc(intel_dp); |
| 3655 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3656 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 3657 | dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
| 3658 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 3659 | |
| 3660 | /* Check if the panel supports PSR */ |
| 3661 | drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT, |
| 3662 | intel_dp->psr_dpcd, |
| 3663 | sizeof(intel_dp->psr_dpcd)); |
| 3664 | if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) { |
| 3665 | dev_priv->psr.sink_support = true; |
| 3666 | DRM_DEBUG_KMS("Detected EDP PSR Panel.\n"); |
| 3667 | } |
| 3668 | |
| 3669 | if (INTEL_GEN(dev_priv) >= 9 && |
| 3670 | (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) { |
| 3671 | uint8_t frame_sync_cap; |
| 3672 | |
| 3673 | dev_priv->psr.sink_support = true; |
| 3674 | drm_dp_dpcd_read(&intel_dp->aux, |
| 3675 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP, |
| 3676 | &frame_sync_cap, 1); |
| 3677 | dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false; |
| 3678 | /* PSR2 needs frame sync as well */ |
| 3679 | dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync; |
| 3680 | DRM_DEBUG_KMS("PSR2 %s on sink", |
| 3681 | dev_priv->psr.psr2_support ? "supported" : "not supported"); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3682 | |
| 3683 | if (dev_priv->psr.psr2_support) { |
| 3684 | dev_priv->psr.y_cord_support = |
| 3685 | intel_dp_get_y_cord_status(intel_dp); |
| 3686 | dev_priv->psr.colorimetry_support = |
| 3687 | intel_dp_get_colorimetry_status(intel_dp); |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3688 | dev_priv->psr.alpm = |
| 3689 | intel_dp_get_alpm_status(intel_dp); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3690 | } |
| 3691 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | /* Read the eDP Display control capabilities registers */ |
| 3695 | if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) && |
| 3696 | drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, |
Dan Carpenter | f7170e2 | 2016-10-13 11:55:08 +0300 | [diff] [blame] | 3697 | intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == |
| 3698 | sizeof(intel_dp->edp_dpcd)) |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3699 | DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd), |
| 3700 | intel_dp->edp_dpcd); |
| 3701 | |
| 3702 | /* Intermediate frequency support */ |
| 3703 | if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */ |
| 3704 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
| 3705 | int i; |
| 3706 | |
| 3707 | drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES, |
| 3708 | sink_rates, sizeof(sink_rates)); |
| 3709 | |
| 3710 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
| 3711 | int val = le16_to_cpu(sink_rates[i]); |
| 3712 | |
| 3713 | if (val == 0) |
| 3714 | break; |
| 3715 | |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 3716 | /* Value read multiplied by 200kHz gives the per-lane |
| 3717 | * link rate in kHz. The source rates are, however, |
| 3718 | * stored in terms of LS_Clk kHz. The full conversion |
| 3719 | * back to symbols is |
| 3720 | * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) |
| 3721 | */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3722 | intel_dp->sink_rates[i] = (val * 200) / 10; |
| 3723 | } |
| 3724 | intel_dp->num_sink_rates = i; |
| 3725 | } |
| 3726 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 3727 | if (intel_dp->num_sink_rates) |
| 3728 | intel_dp->use_rate_select = true; |
| 3729 | else |
| 3730 | intel_dp_set_sink_rates(intel_dp); |
| 3731 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3732 | return true; |
| 3733 | } |
| 3734 | |
| 3735 | |
| 3736 | static bool |
| 3737 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
| 3738 | { |
| 3739 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3740 | return false; |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3741 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame^] | 3742 | /* Don't clobber cached eDP rates. */ |
| 3743 | if (!is_edp(intel_dp)) |
| 3744 | intel_dp_set_sink_rates(intel_dp); |
| 3745 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3746 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT, |
| 3747 | &intel_dp->sink_count, 1) < 0) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3748 | return false; |
| 3749 | |
| 3750 | /* |
| 3751 | * Sink count can change between short pulse hpd hence |
| 3752 | * a member variable in intel_dp will track any changes |
| 3753 | * between short pulse interrupts. |
| 3754 | */ |
| 3755 | intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count); |
| 3756 | |
| 3757 | /* |
| 3758 | * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that |
| 3759 | * a dongle is present but no display. Unless we require to know |
| 3760 | * if a dongle is present or not, we don't need to update |
| 3761 | * downstream port information. So, an early return here saves |
| 3762 | * time from performing other operations which are not required. |
| 3763 | */ |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 3764 | if (!is_edp(intel_dp) && !intel_dp->sink_count) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3765 | return false; |
| 3766 | |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 3767 | if (!drm_dp_is_branch(intel_dp->dpcd)) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3768 | return true; /* native DP sink */ |
| 3769 | |
| 3770 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) |
| 3771 | return true; /* no per-port downstream info */ |
| 3772 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3773 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
| 3774 | intel_dp->downstream_ports, |
| 3775 | DP_MAX_DOWNSTREAM_PORTS) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3776 | return false; /* downstream port status fetch failed */ |
| 3777 | |
| 3778 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3781 | static bool |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3782 | intel_dp_can_mst(struct intel_dp *intel_dp) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3783 | { |
| 3784 | u8 buf[1]; |
| 3785 | |
Nathan Schulte | 7cc9613 | 2016-03-15 10:14:05 -0500 | [diff] [blame] | 3786 | if (!i915.enable_dp_mst) |
| 3787 | return false; |
| 3788 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3789 | if (!intel_dp->can_mst) |
| 3790 | return false; |
| 3791 | |
| 3792 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) |
| 3793 | return false; |
| 3794 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3795 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1) |
| 3796 | return false; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3797 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3798 | return buf[0] & DP_MST_CAP; |
| 3799 | } |
| 3800 | |
| 3801 | static void |
| 3802 | intel_dp_configure_mst(struct intel_dp *intel_dp) |
| 3803 | { |
| 3804 | if (!i915.enable_dp_mst) |
| 3805 | return; |
| 3806 | |
| 3807 | if (!intel_dp->can_mst) |
| 3808 | return; |
| 3809 | |
| 3810 | intel_dp->is_mst = intel_dp_can_mst(intel_dp); |
| 3811 | |
| 3812 | if (intel_dp->is_mst) |
| 3813 | DRM_DEBUG_KMS("Sink is MST capable\n"); |
| 3814 | else |
| 3815 | DRM_DEBUG_KMS("Sink is not MST capable\n"); |
| 3816 | |
| 3817 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 3818 | intel_dp->is_mst); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3819 | } |
| 3820 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3821 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp) |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3822 | { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3823 | 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] | 3824 | 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] | 3825 | 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] | 3826 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3827 | int ret = 0; |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3828 | int count = 0; |
| 3829 | int attempts = 10; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3830 | |
| 3831 | 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] | 3832 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3833 | ret = -EIO; |
| 3834 | goto out; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3835 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3836 | |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3837 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3838 | buf & ~DP_TEST_SINK_START) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3839 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3840 | ret = -EIO; |
| 3841 | goto out; |
| 3842 | } |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3843 | |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3844 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3845 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3846 | |
| 3847 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3848 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3849 | ret = -EIO; |
| 3850 | goto out; |
| 3851 | } |
| 3852 | count = buf & DP_TEST_COUNT_MASK; |
| 3853 | } while (--attempts && count); |
| 3854 | |
| 3855 | if (attempts == 0) { |
Rodrigo Vivi | dc5a903 | 2016-01-29 14:44:59 -0800 | [diff] [blame] | 3856 | 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] | 3857 | ret = -ETIMEDOUT; |
| 3858 | } |
| 3859 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3860 | out: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3861 | hsw_enable_ips(intel_crtc); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3862 | return ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp) |
| 3866 | { |
| 3867 | 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] | 3868 | 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] | 3869 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3870 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3871 | int ret; |
| 3872 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3873 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0) |
| 3874 | return -EIO; |
| 3875 | |
| 3876 | if (!(buf & DP_TEST_CRC_SUPPORTED)) |
| 3877 | return -ENOTTY; |
| 3878 | |
| 3879 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) |
| 3880 | return -EIO; |
| 3881 | |
Rodrigo Vivi | 6d8175d | 2015-11-05 10:50:22 -0800 | [diff] [blame] | 3882 | if (buf & DP_TEST_SINK_START) { |
| 3883 | ret = intel_dp_sink_crc_stop(intel_dp); |
| 3884 | if (ret) |
| 3885 | return ret; |
| 3886 | } |
| 3887 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3888 | hsw_disable_ips(intel_crtc); |
| 3889 | |
| 3890 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
| 3891 | buf | DP_TEST_SINK_START) < 0) { |
| 3892 | hsw_enable_ips(intel_crtc); |
| 3893 | return -EIO; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3894 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3895 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3896 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3897 | return 0; |
| 3898 | } |
| 3899 | |
| 3900 | int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc) |
| 3901 | { |
| 3902 | 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] | 3903 | 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] | 3904 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3905 | u8 buf; |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3906 | int count, ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3907 | int attempts = 6; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3908 | |
| 3909 | ret = intel_dp_sink_crc_start(intel_dp); |
| 3910 | if (ret) |
| 3911 | return ret; |
| 3912 | |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3913 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3914 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3915 | |
Rodrigo Vivi | 1dda5f9 | 2014-10-01 07:32:37 -0700 | [diff] [blame] | 3916 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3917 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3918 | ret = -EIO; |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3919 | goto stop; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3920 | } |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3921 | count = buf & DP_TEST_COUNT_MASK; |
Rodrigo Vivi | aabc95d | 2015-07-23 16:35:50 -0700 | [diff] [blame] | 3922 | |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3923 | } while (--attempts && count == 0); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3924 | |
| 3925 | if (attempts == 0) { |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3926 | DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n"); |
| 3927 | ret = -ETIMEDOUT; |
| 3928 | goto stop; |
| 3929 | } |
| 3930 | |
| 3931 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) { |
| 3932 | ret = -EIO; |
| 3933 | goto stop; |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3934 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3935 | |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3936 | stop: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3937 | intel_dp_sink_crc_stop(intel_dp); |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3938 | return ret; |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3939 | } |
| 3940 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3941 | static bool |
| 3942 | intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3943 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3944 | return drm_dp_dpcd_read(&intel_dp->aux, |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 3945 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 3946 | sink_irq_vector, 1) == 1; |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3949 | static bool |
| 3950 | intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3951 | { |
| 3952 | int ret; |
| 3953 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3954 | ret = drm_dp_dpcd_read(&intel_dp->aux, |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3955 | DP_SINK_COUNT_ESI, |
| 3956 | sink_irq_vector, 14); |
| 3957 | if (ret != 14) |
| 3958 | return false; |
| 3959 | |
| 3960 | return true; |
| 3961 | } |
| 3962 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 3963 | 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] | 3964 | { |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 3965 | int status = 0; |
| 3966 | int min_lane_count = 1; |
| 3967 | int common_rates[DP_MAX_SUPPORTED_RATES] = {}; |
| 3968 | int link_rate_index, test_link_rate; |
| 3969 | uint8_t test_lane_count, test_link_bw; |
| 3970 | /* (DP CTS 1.2) |
| 3971 | * 4.3.1.11 |
| 3972 | */ |
| 3973 | /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */ |
| 3974 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT, |
| 3975 | &test_lane_count); |
| 3976 | |
| 3977 | if (status <= 0) { |
| 3978 | DRM_DEBUG_KMS("Lane count read failed\n"); |
| 3979 | return DP_TEST_NAK; |
| 3980 | } |
| 3981 | test_lane_count &= DP_MAX_LANE_COUNT_MASK; |
| 3982 | /* Validate the requested lane count */ |
| 3983 | if (test_lane_count < min_lane_count || |
| 3984 | test_lane_count > intel_dp->max_sink_lane_count) |
| 3985 | return DP_TEST_NAK; |
| 3986 | |
| 3987 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE, |
| 3988 | &test_link_bw); |
| 3989 | if (status <= 0) { |
| 3990 | DRM_DEBUG_KMS("Link Rate read failed\n"); |
| 3991 | return DP_TEST_NAK; |
| 3992 | } |
| 3993 | /* Validate the requested link rate */ |
| 3994 | test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw); |
| 3995 | link_rate_index = intel_dp_link_rate_index(intel_dp, |
| 3996 | common_rates, |
| 3997 | test_link_rate); |
| 3998 | if (link_rate_index < 0) |
| 3999 | return DP_TEST_NAK; |
| 4000 | |
| 4001 | intel_dp->compliance.test_lane_count = test_lane_count; |
| 4002 | intel_dp->compliance.test_link_rate = test_link_rate; |
| 4003 | |
| 4004 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp) |
| 4008 | { |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4009 | uint8_t test_pattern; |
| 4010 | uint16_t test_misc; |
| 4011 | __be16 h_width, v_height; |
| 4012 | int status = 0; |
| 4013 | |
| 4014 | /* Read the TEST_PATTERN (DP CTS 3.1.5) */ |
| 4015 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN, |
| 4016 | &test_pattern, 1); |
| 4017 | if (status <= 0) { |
| 4018 | DRM_DEBUG_KMS("Test pattern read failed\n"); |
| 4019 | return DP_TEST_NAK; |
| 4020 | } |
| 4021 | if (test_pattern != DP_COLOR_RAMP) |
| 4022 | return DP_TEST_NAK; |
| 4023 | |
| 4024 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI, |
| 4025 | &h_width, 2); |
| 4026 | if (status <= 0) { |
| 4027 | DRM_DEBUG_KMS("H Width read failed\n"); |
| 4028 | return DP_TEST_NAK; |
| 4029 | } |
| 4030 | |
| 4031 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI, |
| 4032 | &v_height, 2); |
| 4033 | if (status <= 0) { |
| 4034 | DRM_DEBUG_KMS("V Height read failed\n"); |
| 4035 | return DP_TEST_NAK; |
| 4036 | } |
| 4037 | |
| 4038 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0, |
| 4039 | &test_misc, 1); |
| 4040 | if (status <= 0) { |
| 4041 | DRM_DEBUG_KMS("TEST MISC read failed\n"); |
| 4042 | return DP_TEST_NAK; |
| 4043 | } |
| 4044 | if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB) |
| 4045 | return DP_TEST_NAK; |
| 4046 | if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA) |
| 4047 | return DP_TEST_NAK; |
| 4048 | switch (test_misc & DP_TEST_BIT_DEPTH_MASK) { |
| 4049 | case DP_TEST_BIT_DEPTH_6: |
| 4050 | intel_dp->compliance.test_data.bpc = 6; |
| 4051 | break; |
| 4052 | case DP_TEST_BIT_DEPTH_8: |
| 4053 | intel_dp->compliance.test_data.bpc = 8; |
| 4054 | break; |
| 4055 | default: |
| 4056 | return DP_TEST_NAK; |
| 4057 | } |
| 4058 | |
| 4059 | intel_dp->compliance.test_data.video_pattern = test_pattern; |
| 4060 | intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width); |
| 4061 | intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height); |
| 4062 | /* Set test active flag here so userspace doesn't interrupt things */ |
| 4063 | intel_dp->compliance.test_active = 1; |
| 4064 | |
| 4065 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp) |
| 4069 | { |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4070 | uint8_t test_result = DP_TEST_ACK; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4071 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4072 | struct drm_connector *connector = &intel_connector->base; |
| 4073 | |
| 4074 | if (intel_connector->detect_edid == NULL || |
Daniel Vetter | ac6f2e2 | 2015-05-08 16:15:41 +0200 | [diff] [blame] | 4075 | connector->edid_corrupt || |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4076 | intel_dp->aux.i2c_defer_count > 6) { |
| 4077 | /* Check EDID read for NACKs, DEFERs and corruption |
| 4078 | * (DP CTS 1.2 Core r1.1) |
| 4079 | * 4.2.2.4 : Failed EDID read, I2C_NAK |
| 4080 | * 4.2.2.5 : Failed EDID read, I2C_DEFER |
| 4081 | * 4.2.2.6 : EDID corruption detected |
| 4082 | * Use failsafe mode for all cases |
| 4083 | */ |
| 4084 | if (intel_dp->aux.i2c_nack_count > 0 || |
| 4085 | intel_dp->aux.i2c_defer_count > 0) |
| 4086 | DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n", |
| 4087 | intel_dp->aux.i2c_nack_count, |
| 4088 | intel_dp->aux.i2c_defer_count); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4089 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4090 | } else { |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 4091 | struct edid *block = intel_connector->detect_edid; |
| 4092 | |
| 4093 | /* We have to write the checksum |
| 4094 | * of the last block read |
| 4095 | */ |
| 4096 | block += intel_connector->detect_edid->extensions; |
| 4097 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4098 | if (!drm_dp_dpcd_write(&intel_dp->aux, |
| 4099 | DP_TEST_EDID_CHECKSUM, |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 4100 | &block->checksum, |
Dan Carpenter | 5a1cc65 | 2015-05-12 21:07:37 +0300 | [diff] [blame] | 4101 | 1)) |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4102 | DRM_DEBUG_KMS("Failed to write EDID checksum\n"); |
| 4103 | |
| 4104 | test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE; |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4105 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | /* Set test active flag here so userspace doesn't interrupt things */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4109 | intel_dp->compliance.test_active = 1; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4110 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4111 | return test_result; |
| 4112 | } |
| 4113 | |
| 4114 | static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp) |
| 4115 | { |
| 4116 | uint8_t test_result = DP_TEST_NAK; |
| 4117 | return test_result; |
| 4118 | } |
| 4119 | |
| 4120 | static void intel_dp_handle_test_request(struct intel_dp *intel_dp) |
| 4121 | { |
| 4122 | uint8_t response = DP_TEST_NAK; |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4123 | uint8_t request = 0; |
| 4124 | int status; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4125 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4126 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4127 | if (status <= 0) { |
| 4128 | DRM_DEBUG_KMS("Could not read test request from sink\n"); |
| 4129 | goto update_status; |
| 4130 | } |
| 4131 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4132 | switch (request) { |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4133 | case DP_TEST_LINK_TRAINING: |
| 4134 | DRM_DEBUG_KMS("LINK_TRAINING test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4135 | response = intel_dp_autotest_link_training(intel_dp); |
| 4136 | break; |
| 4137 | case DP_TEST_LINK_VIDEO_PATTERN: |
| 4138 | DRM_DEBUG_KMS("TEST_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4139 | response = intel_dp_autotest_video_pattern(intel_dp); |
| 4140 | break; |
| 4141 | case DP_TEST_LINK_EDID_READ: |
| 4142 | DRM_DEBUG_KMS("EDID test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4143 | response = intel_dp_autotest_edid(intel_dp); |
| 4144 | break; |
| 4145 | case DP_TEST_LINK_PHY_TEST_PATTERN: |
| 4146 | DRM_DEBUG_KMS("PHY_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4147 | response = intel_dp_autotest_phy_pattern(intel_dp); |
| 4148 | break; |
| 4149 | default: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4150 | DRM_DEBUG_KMS("Invalid test request '%02x'\n", request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4151 | break; |
| 4152 | } |
| 4153 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4154 | if (response & DP_TEST_ACK) |
| 4155 | intel_dp->compliance.test_type = request; |
| 4156 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4157 | update_status: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4158 | status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4159 | if (status <= 0) |
| 4160 | DRM_DEBUG_KMS("Could not write test response to sink\n"); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4161 | } |
| 4162 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4163 | static int |
| 4164 | intel_dp_check_mst_status(struct intel_dp *intel_dp) |
| 4165 | { |
| 4166 | bool bret; |
| 4167 | |
| 4168 | if (intel_dp->is_mst) { |
| 4169 | u8 esi[16] = { 0 }; |
| 4170 | int ret = 0; |
| 4171 | int retry; |
| 4172 | bool handled; |
| 4173 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4174 | go_again: |
| 4175 | if (bret == true) { |
| 4176 | |
| 4177 | /* check link status - esi[10] = 0x200c */ |
Ville Syrjälä | 19e0b4c | 2016-08-05 19:05:42 +0300 | [diff] [blame] | 4178 | if (intel_dp->active_mst_links && |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 4179 | !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4180 | DRM_DEBUG_KMS("channel EQ not ok, retraining\n"); |
| 4181 | intel_dp_start_link_train(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4182 | intel_dp_stop_link_train(intel_dp); |
| 4183 | } |
| 4184 | |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4185 | DRM_DEBUG_KMS("got esi %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4186 | ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); |
| 4187 | |
| 4188 | if (handled) { |
| 4189 | for (retry = 0; retry < 3; retry++) { |
| 4190 | int wret; |
| 4191 | wret = drm_dp_dpcd_write(&intel_dp->aux, |
| 4192 | DP_SINK_COUNT_ESI+1, |
| 4193 | &esi[1], 3); |
| 4194 | if (wret == 3) { |
| 4195 | break; |
| 4196 | } |
| 4197 | } |
| 4198 | |
| 4199 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4200 | if (bret == true) { |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4201 | DRM_DEBUG_KMS("got esi2 %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4202 | goto go_again; |
| 4203 | } |
| 4204 | } else |
| 4205 | ret = 0; |
| 4206 | |
| 4207 | return ret; |
| 4208 | } else { |
| 4209 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4210 | DRM_DEBUG_KMS("failed to get ESI - device may have failed\n"); |
| 4211 | intel_dp->is_mst = false; |
| 4212 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); |
| 4213 | /* send a hotplug event */ |
| 4214 | drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev); |
| 4215 | } |
| 4216 | } |
| 4217 | return -EINVAL; |
| 4218 | } |
| 4219 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4220 | static void |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4221 | intel_dp_retrain_link(struct intel_dp *intel_dp) |
| 4222 | { |
| 4223 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 4224 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4225 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 4226 | |
| 4227 | /* Suppress underruns caused by re-training */ |
| 4228 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
| 4229 | if (crtc->config->has_pch_encoder) |
| 4230 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4231 | intel_crtc_pch_transcoder(crtc), false); |
| 4232 | |
| 4233 | intel_dp_start_link_train(intel_dp); |
| 4234 | intel_dp_stop_link_train(intel_dp); |
| 4235 | |
| 4236 | /* Keep underrun reporting disabled until things are stable */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4237 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4238 | |
| 4239 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 4240 | if (crtc->config->has_pch_encoder) |
| 4241 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4242 | intel_crtc_pch_transcoder(crtc), true); |
| 4243 | } |
| 4244 | |
| 4245 | static void |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4246 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
| 4247 | { |
| 4248 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
| 4249 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
| 4250 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 4251 | |
| 4252 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 4253 | |
| 4254 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
| 4255 | DRM_ERROR("Failed to get link status\n"); |
| 4256 | return; |
| 4257 | } |
| 4258 | |
| 4259 | if (!intel_encoder->base.crtc) |
| 4260 | return; |
| 4261 | |
| 4262 | if (!to_intel_crtc(intel_encoder->base.crtc)->active) |
| 4263 | return; |
| 4264 | |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4265 | /* FIXME: we need to synchronize this sort of stuff with hardware |
Daniel Vetter | 2dd85ae | 2016-12-13 20:54:14 +0100 | [diff] [blame] | 4266 | * readout. Currently fast link training doesn't work on boot-up. */ |
| 4267 | if (!intel_dp->lane_count) |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4268 | return; |
| 4269 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4270 | /* Retrain if Channel EQ or CR not ok */ |
| 4271 | if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) { |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4272 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
| 4273 | intel_encoder->base.name); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4274 | |
| 4275 | intel_dp_retrain_link(intel_dp); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4276 | } |
| 4277 | } |
| 4278 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4279 | /* |
| 4280 | * According to DP spec |
| 4281 | * 5.1.2: |
| 4282 | * 1. Read DPCD |
| 4283 | * 2. Configure link according to Receiver Capabilities |
| 4284 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 4285 | * 4. Check link status on receipt of hot-plug interrupt |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4286 | * |
| 4287 | * intel_dp_short_pulse - handles short pulse interrupts |
| 4288 | * when full detection is not required. |
| 4289 | * Returns %true if short pulse is handled and full detection |
| 4290 | * is NOT required and %false otherwise. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4291 | */ |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4292 | static bool |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4293 | intel_dp_short_pulse(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4294 | { |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4295 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4296 | 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] | 4297 | u8 sink_irq_vector = 0; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4298 | u8 old_sink_count = intel_dp->sink_count; |
| 4299 | bool ret; |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4300 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4301 | /* |
| 4302 | * Clearing compliance test variables to allow capturing |
| 4303 | * of values for next automated test request. |
| 4304 | */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4305 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4306 | |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4307 | /* |
| 4308 | * Now read the DPCD to see if it's actually running |
| 4309 | * If the current value of sink count doesn't match with |
| 4310 | * the value that was stored earlier or dpcd read failed |
| 4311 | * we need to do full detection |
| 4312 | */ |
| 4313 | ret = intel_dp_get_dpcd(intel_dp); |
| 4314 | |
| 4315 | if ((old_sink_count != intel_dp->sink_count) || !ret) { |
| 4316 | /* No need to proceed if we are going to do full detect */ |
| 4317 | return false; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4320 | /* Try to read the source of the interrupt */ |
| 4321 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4322 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4323 | sink_irq_vector != 0) { |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4324 | /* Clear interrupt source */ |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4325 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4326 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4327 | sink_irq_vector); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4328 | |
| 4329 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4330 | intel_dp_handle_test_request(intel_dp); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4331 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4332 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4333 | } |
| 4334 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4335 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4336 | intel_dp_check_link_status(intel_dp); |
| 4337 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4338 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 4339 | DRM_DEBUG_KMS("Link Training Compliance Test requested\n"); |
| 4340 | /* Send a Hotplug Uevent to userspace to start modeset */ |
| 4341 | drm_kms_helper_hotplug_event(intel_encoder->base.dev); |
| 4342 | } |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4343 | |
| 4344 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4345 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4346 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4347 | /* XXX this is probably wrong for multiple downstream ports */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4348 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4349 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4350 | { |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4351 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4352 | uint8_t *dpcd = intel_dp->dpcd; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4353 | uint8_t type; |
| 4354 | |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4355 | if (lspcon->active) |
| 4356 | lspcon_resume(lspcon); |
| 4357 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4358 | if (!intel_dp_get_dpcd(intel_dp)) |
| 4359 | return connector_status_disconnected; |
| 4360 | |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 4361 | if (is_edp(intel_dp)) |
| 4362 | return connector_status_connected; |
| 4363 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4364 | /* if there's no downstream port, we're done */ |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 4365 | if (!drm_dp_is_branch(dpcd)) |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4366 | return connector_status_connected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4367 | |
| 4368 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4369 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 4370 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4371 | |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 4372 | return intel_dp->sink_count ? |
| 4373 | connector_status_connected : connector_status_disconnected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4374 | } |
| 4375 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4376 | if (intel_dp_can_mst(intel_dp)) |
| 4377 | return connector_status_connected; |
| 4378 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4379 | /* If no HPD, poke DDC gently */ |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 4380 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4381 | return connector_status_connected; |
| 4382 | |
| 4383 | /* Well we tried, say unknown for unreliable port types */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4384 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 4385 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 4386 | if (type == DP_DS_PORT_TYPE_VGA || |
| 4387 | type == DP_DS_PORT_TYPE_NON_EDID) |
| 4388 | return connector_status_unknown; |
| 4389 | } else { |
| 4390 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
| 4391 | DP_DWN_STRM_PORT_TYPE_MASK; |
| 4392 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || |
| 4393 | type == DP_DWN_STRM_PORT_TYPE_OTHER) |
| 4394 | return connector_status_unknown; |
| 4395 | } |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4396 | |
| 4397 | /* Anything else is out of spec, warn and ignore */ |
| 4398 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4399 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | static enum drm_connector_status |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4403 | edp_detect(struct intel_dp *intel_dp) |
| 4404 | { |
| 4405 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4406 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4407 | enum drm_connector_status status; |
| 4408 | |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4409 | status = intel_panel_detect(dev_priv); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4410 | if (status == connector_status_unknown) |
| 4411 | status = connector_status_connected; |
| 4412 | |
| 4413 | return status; |
| 4414 | } |
| 4415 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4416 | static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4417 | struct intel_digital_port *port) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4418 | { |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4419 | u32 bit; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 4420 | |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4421 | switch (port->port) { |
| 4422 | case PORT_A: |
| 4423 | return true; |
| 4424 | case PORT_B: |
| 4425 | bit = SDE_PORTB_HOTPLUG; |
| 4426 | break; |
| 4427 | case PORT_C: |
| 4428 | bit = SDE_PORTC_HOTPLUG; |
| 4429 | break; |
| 4430 | case PORT_D: |
| 4431 | bit = SDE_PORTD_HOTPLUG; |
| 4432 | break; |
| 4433 | default: |
| 4434 | MISSING_CASE(port->port); |
| 4435 | return false; |
| 4436 | } |
| 4437 | |
| 4438 | return I915_READ(SDEISR) & bit; |
| 4439 | } |
| 4440 | |
| 4441 | static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4442 | struct intel_digital_port *port) |
| 4443 | { |
| 4444 | u32 bit; |
| 4445 | |
| 4446 | switch (port->port) { |
| 4447 | case PORT_A: |
| 4448 | return true; |
| 4449 | case PORT_B: |
| 4450 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 4451 | break; |
| 4452 | case PORT_C: |
| 4453 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 4454 | break; |
| 4455 | case PORT_D: |
| 4456 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 4457 | break; |
Jani Nikula | a78695d | 2015-09-18 15:54:50 +0300 | [diff] [blame] | 4458 | case PORT_E: |
| 4459 | bit = SDE_PORTE_HOTPLUG_SPT; |
| 4460 | break; |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4461 | default: |
| 4462 | MISSING_CASE(port->port); |
| 4463 | return false; |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4464 | } |
Damien Lespiau | 1b46963 | 2012-12-13 16:09:01 +0000 | [diff] [blame] | 4465 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4466 | return I915_READ(SDEISR) & bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4467 | } |
| 4468 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4469 | static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv, |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4470 | struct intel_digital_port *port) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4471 | { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4472 | u32 bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4473 | |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4474 | switch (port->port) { |
| 4475 | case PORT_B: |
| 4476 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; |
| 4477 | break; |
| 4478 | case PORT_C: |
| 4479 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; |
| 4480 | break; |
| 4481 | case PORT_D: |
| 4482 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; |
| 4483 | break; |
| 4484 | default: |
| 4485 | MISSING_CASE(port->port); |
| 4486 | return false; |
| 4487 | } |
| 4488 | |
| 4489 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 4490 | } |
| 4491 | |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4492 | static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4493 | struct intel_digital_port *port) |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4494 | { |
| 4495 | u32 bit; |
| 4496 | |
| 4497 | switch (port->port) { |
| 4498 | case PORT_B: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4499 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4500 | break; |
| 4501 | case PORT_C: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4502 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4503 | break; |
| 4504 | case PORT_D: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4505 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4506 | break; |
| 4507 | default: |
| 4508 | MISSING_CASE(port->port); |
| 4509 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4510 | } |
| 4511 | |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4512 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
Dave Airlie | 2a592be | 2014-09-01 16:58:12 +1000 | [diff] [blame] | 4513 | } |
| 4514 | |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4515 | static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv, |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4516 | struct intel_digital_port *intel_dig_port) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4517 | { |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4518 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 4519 | enum port port; |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4520 | u32 bit; |
| 4521 | |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4522 | intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port); |
| 4523 | switch (port) { |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4524 | case PORT_A: |
| 4525 | bit = BXT_DE_PORT_HP_DDIA; |
| 4526 | break; |
| 4527 | case PORT_B: |
| 4528 | bit = BXT_DE_PORT_HP_DDIB; |
| 4529 | break; |
| 4530 | case PORT_C: |
| 4531 | bit = BXT_DE_PORT_HP_DDIC; |
| 4532 | break; |
| 4533 | default: |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4534 | MISSING_CASE(port); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4535 | return false; |
| 4536 | } |
| 4537 | |
| 4538 | return I915_READ(GEN8_DE_PORT_ISR) & bit; |
| 4539 | } |
| 4540 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4541 | /* |
| 4542 | * intel_digital_port_connected - is the specified port connected? |
| 4543 | * @dev_priv: i915 private structure |
| 4544 | * @port: the port to test |
| 4545 | * |
| 4546 | * Return %true if @port is connected, %false otherwise. |
| 4547 | */ |
Imre Deak | 390b4e0 | 2017-01-27 11:39:19 +0200 | [diff] [blame] | 4548 | bool intel_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4549 | struct intel_digital_port *port) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4550 | { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4551 | if (HAS_PCH_IBX(dev_priv)) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4552 | return ibx_digital_port_connected(dev_priv, port); |
Ville Syrjälä | 22824fa | 2016-02-11 16:44:28 +0200 | [diff] [blame] | 4553 | else if (HAS_PCH_SPLIT(dev_priv)) |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4554 | return cpt_digital_port_connected(dev_priv, port); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4555 | else if (IS_GEN9_LP(dev_priv)) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4556 | return bxt_digital_port_connected(dev_priv, port); |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4557 | else if (IS_GM45(dev_priv)) |
| 4558 | return gm45_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4559 | else |
| 4560 | return g4x_digital_port_connected(dev_priv, port); |
| 4561 | } |
| 4562 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4563 | static struct edid * |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4564 | intel_dp_get_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4565 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4566 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4567 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4568 | /* use cached edid if we have one */ |
| 4569 | if (intel_connector->edid) { |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4570 | /* invalid edid */ |
| 4571 | if (IS_ERR(intel_connector->edid)) |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4572 | return NULL; |
| 4573 | |
Jani Nikula | 55e9ede | 2013-10-01 10:38:54 +0300 | [diff] [blame] | 4574 | return drm_edid_duplicate(intel_connector->edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4575 | } else |
| 4576 | return drm_get_edid(&intel_connector->base, |
| 4577 | &intel_dp->aux.ddc); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4580 | static void |
| 4581 | intel_dp_set_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4582 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4583 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4584 | struct edid *edid; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4585 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4586 | intel_dp_unset_edid(intel_dp); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4587 | edid = intel_dp_get_edid(intel_dp); |
| 4588 | intel_connector->detect_edid = edid; |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4589 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4590 | if (intel_dp->force_audio != HDMI_AUDIO_AUTO) |
| 4591 | intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON; |
| 4592 | else |
| 4593 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
| 4594 | } |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4595 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4596 | static void |
| 4597 | intel_dp_unset_edid(struct intel_dp *intel_dp) |
| 4598 | { |
| 4599 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4600 | |
| 4601 | kfree(intel_connector->detect_edid); |
| 4602 | intel_connector->detect_edid = NULL; |
| 4603 | |
| 4604 | intel_dp->has_audio = false; |
| 4605 | } |
| 4606 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4607 | static enum drm_connector_status |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4608 | intel_dp_long_pulse(struct intel_connector *intel_connector) |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4609 | { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4610 | struct drm_connector *connector = &intel_connector->base; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4611 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Paulo Zanoni | d63885d | 2012-10-26 19:05:49 -0200 | [diff] [blame] | 4612 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4613 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 4614 | struct drm_device *dev = connector->dev; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4615 | enum drm_connector_status status; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4616 | u8 sink_irq_vector = 0; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4617 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4618 | intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4619 | |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4620 | /* Can't disconnect eDP, but you can close the lid... */ |
| 4621 | if (is_edp(intel_dp)) |
| 4622 | status = edp_detect(intel_dp); |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4623 | else if (intel_digital_port_connected(to_i915(dev), |
| 4624 | dp_to_dig_port(intel_dp))) |
| 4625 | status = intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4626 | else |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4627 | status = connector_status_disconnected; |
| 4628 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4629 | if (status == connector_status_disconnected) { |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4630 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4631 | |
jim.bride@linux.intel.com | 0e505a0 | 2016-04-11 10:11:24 -0700 | [diff] [blame] | 4632 | if (intel_dp->is_mst) { |
| 4633 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4634 | intel_dp->is_mst, |
| 4635 | intel_dp->mst_mgr.mst_state); |
| 4636 | intel_dp->is_mst = false; |
| 4637 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4638 | intel_dp->is_mst); |
| 4639 | } |
| 4640 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4641 | goto out; |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4642 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4643 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4644 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4645 | intel_encoder->type = INTEL_OUTPUT_DP; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4646 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4647 | DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n", |
| 4648 | yesno(intel_dp_source_supports_hbr2(intel_dp)), |
| 4649 | yesno(drm_dp_tps3_supported(intel_dp->dpcd))); |
| 4650 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4651 | if (intel_dp->reset_link_params) { |
| 4652 | /* Set the max lane count for sink */ |
| 4653 | 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] | 4654 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4655 | /* Set the max link BW for sink */ |
| 4656 | intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp); |
| 4657 | |
| 4658 | intel_dp->reset_link_params = false; |
| 4659 | } |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4660 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4661 | intel_dp_print_rates(intel_dp); |
| 4662 | |
Imre Deak | 7b3fc17 | 2016-10-25 16:12:39 +0300 | [diff] [blame] | 4663 | intel_dp_read_desc(intel_dp); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 4664 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4665 | intel_dp_configure_mst(intel_dp); |
| 4666 | |
| 4667 | if (intel_dp->is_mst) { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4668 | /* |
| 4669 | * If we are in MST mode then this connector |
| 4670 | * won't appear connected or have anything |
| 4671 | * with EDID on it |
| 4672 | */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4673 | status = connector_status_disconnected; |
| 4674 | goto out; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4675 | } else if (connector->status == connector_status_connected) { |
| 4676 | /* |
| 4677 | * If display was connected already and is still connected |
| 4678 | * check links status, there has been known issues of |
| 4679 | * link loss triggerring long pulse!!!! |
| 4680 | */ |
| 4681 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4682 | intel_dp_check_link_status(intel_dp); |
| 4683 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 4684 | goto out; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4685 | } |
| 4686 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4687 | /* |
| 4688 | * Clearing NACK and defer counts to get their exact values |
| 4689 | * while reading EDID which are required by Compliance tests |
| 4690 | * 4.2.2.4 and 4.2.2.5 |
| 4691 | */ |
| 4692 | intel_dp->aux.i2c_nack_count = 0; |
| 4693 | intel_dp->aux.i2c_defer_count = 0; |
| 4694 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4695 | intel_dp_set_edid(intel_dp); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4696 | if (is_edp(intel_dp) || intel_connector->detect_edid) |
| 4697 | status = connector_status_connected; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4698 | intel_dp->detect_done = true; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4699 | |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4700 | /* Try to read the source of the interrupt */ |
| 4701 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4702 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4703 | sink_irq_vector != 0) { |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4704 | /* Clear interrupt source */ |
| 4705 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4706 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4707 | sink_irq_vector); |
| 4708 | |
| 4709 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
| 4710 | intel_dp_handle_test_request(intel_dp); |
| 4711 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4712 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4713 | } |
| 4714 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4715 | out: |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4716 | if (status != connector_status_connected && !intel_dp->is_mst) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4717 | intel_dp_unset_edid(intel_dp); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4718 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4719 | intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4720 | return status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | static enum drm_connector_status |
| 4724 | intel_dp_detect(struct drm_connector *connector, bool force) |
| 4725 | { |
| 4726 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4727 | enum drm_connector_status status = connector->status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4728 | |
| 4729 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4730 | connector->base.id, connector->name); |
| 4731 | |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4732 | /* If full detect is not performed yet, do a full detect */ |
| 4733 | if (!intel_dp->detect_done) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4734 | status = intel_dp_long_pulse(intel_dp->attached_connector); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4735 | |
| 4736 | intel_dp->detect_done = false; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4737 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4738 | return status; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4741 | static void |
| 4742 | intel_dp_force(struct drm_connector *connector) |
| 4743 | { |
| 4744 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 4745 | 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] | 4746 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4747 | |
| 4748 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4749 | connector->base.id, connector->name); |
| 4750 | intel_dp_unset_edid(intel_dp); |
| 4751 | |
| 4752 | if (connector->status != connector_status_connected) |
| 4753 | return; |
| 4754 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4755 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4756 | |
| 4757 | intel_dp_set_edid(intel_dp); |
| 4758 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4759 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4760 | |
| 4761 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4762 | intel_encoder->type = INTEL_OUTPUT_DP; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4765 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 4766 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4767 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4768 | struct edid *edid; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4769 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4770 | edid = intel_connector->detect_edid; |
| 4771 | if (edid) { |
| 4772 | int ret = intel_connector_update_modes(connector, edid); |
| 4773 | if (ret) |
| 4774 | return ret; |
| 4775 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4776 | |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4777 | /* if eDP has no EDID, fall back to fixed mode */ |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4778 | if (is_edp(intel_attached_dp(connector)) && |
| 4779 | intel_connector->panel.fixed_mode) { |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4780 | struct drm_display_mode *mode; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4781 | |
| 4782 | mode = drm_mode_duplicate(connector->dev, |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4783 | intel_connector->panel.fixed_mode); |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4784 | if (mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4785 | drm_mode_probed_add(connector, mode); |
| 4786 | return 1; |
| 4787 | } |
| 4788 | } |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4789 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4790 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4793 | static bool |
| 4794 | intel_dp_detect_audio(struct drm_connector *connector) |
| 4795 | { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4796 | bool has_audio = false; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4797 | struct edid *edid; |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4798 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4799 | edid = to_intel_connector(connector)->detect_edid; |
| 4800 | if (edid) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4801 | has_audio = drm_detect_monitor_audio(edid); |
Imre Deak | 671dedd | 2014-03-05 16:20:53 +0200 | [diff] [blame] | 4802 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4803 | return has_audio; |
| 4804 | } |
| 4805 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4806 | static int |
| 4807 | intel_dp_set_property(struct drm_connector *connector, |
| 4808 | struct drm_property *property, |
| 4809 | uint64_t val) |
| 4810 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4811 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4812 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4813 | struct intel_encoder *intel_encoder = intel_attached_encoder(connector); |
| 4814 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4815 | int ret; |
| 4816 | |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 4817 | ret = drm_object_property_set_value(&connector->base, property, val); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4818 | if (ret) |
| 4819 | return ret; |
| 4820 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 4821 | if (property == dev_priv->force_audio_property) { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4822 | int i = val; |
| 4823 | bool has_audio; |
| 4824 | |
| 4825 | if (i == intel_dp->force_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4826 | return 0; |
| 4827 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4828 | intel_dp->force_audio = i; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4829 | |
Daniel Vetter | c3e5f67 | 2012-02-23 17:14:47 +0100 | [diff] [blame] | 4830 | if (i == HDMI_AUDIO_AUTO) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4831 | has_audio = intel_dp_detect_audio(connector); |
| 4832 | else |
Daniel Vetter | c3e5f67 | 2012-02-23 17:14:47 +0100 | [diff] [blame] | 4833 | has_audio = (i == HDMI_AUDIO_ON); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4834 | |
| 4835 | if (has_audio == intel_dp->has_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4836 | return 0; |
| 4837 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 4838 | intel_dp->has_audio = has_audio; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4839 | goto done; |
| 4840 | } |
| 4841 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4842 | if (property == dev_priv->broadcast_rgb_property) { |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4843 | bool old_auto = intel_dp->color_range_auto; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4844 | bool old_range = intel_dp->limited_color_range; |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4845 | |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4846 | switch (val) { |
| 4847 | case INTEL_BROADCAST_RGB_AUTO: |
| 4848 | intel_dp->color_range_auto = true; |
| 4849 | break; |
| 4850 | case INTEL_BROADCAST_RGB_FULL: |
| 4851 | intel_dp->color_range_auto = false; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4852 | intel_dp->limited_color_range = false; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4853 | break; |
| 4854 | case INTEL_BROADCAST_RGB_LIMITED: |
| 4855 | intel_dp->color_range_auto = false; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4856 | intel_dp->limited_color_range = true; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 4857 | break; |
| 4858 | default: |
| 4859 | return -EINVAL; |
| 4860 | } |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4861 | |
| 4862 | if (old_auto == intel_dp->color_range_auto && |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 4863 | old_range == intel_dp->limited_color_range) |
Daniel Vetter | ae4edb8 | 2013-04-22 17:07:23 +0200 | [diff] [blame] | 4864 | return 0; |
| 4865 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 4866 | goto done; |
| 4867 | } |
| 4868 | |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4869 | if (is_edp(intel_dp) && |
| 4870 | property == connector->dev->mode_config.scaling_mode_property) { |
| 4871 | if (val == DRM_MODE_SCALE_NONE) { |
| 4872 | DRM_DEBUG_KMS("no scaling not supported\n"); |
| 4873 | return -EINVAL; |
| 4874 | } |
Ville Syrjälä | 234126c | 2016-04-12 22:14:38 +0300 | [diff] [blame] | 4875 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 4876 | val == DRM_MODE_SCALE_CENTER) { |
| 4877 | DRM_DEBUG_KMS("centering not supported\n"); |
| 4878 | return -EINVAL; |
| 4879 | } |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 4880 | |
| 4881 | if (intel_connector->panel.fitting_mode == val) { |
| 4882 | /* the eDP scaling property is not changed */ |
| 4883 | return 0; |
| 4884 | } |
| 4885 | intel_connector->panel.fitting_mode = val; |
| 4886 | |
| 4887 | goto done; |
| 4888 | } |
| 4889 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4890 | return -EINVAL; |
| 4891 | |
| 4892 | done: |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 4893 | if (intel_encoder->base.crtc) |
| 4894 | intel_crtc_restore_mode(intel_encoder->base.crtc); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4895 | |
| 4896 | return 0; |
| 4897 | } |
| 4898 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4899 | static int |
| 4900 | intel_dp_connector_register(struct drm_connector *connector) |
| 4901 | { |
| 4902 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 4903 | int ret; |
| 4904 | |
| 4905 | ret = intel_connector_register(connector); |
| 4906 | if (ret) |
| 4907 | return ret; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4908 | |
| 4909 | i915_debugfs_connector_add(connector); |
| 4910 | |
| 4911 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
| 4912 | intel_dp->aux.name, connector->kdev->kobj.name); |
| 4913 | |
| 4914 | intel_dp->aux.dev = connector->kdev; |
| 4915 | return drm_dp_aux_register(&intel_dp->aux); |
| 4916 | } |
| 4917 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4918 | static void |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4919 | intel_dp_connector_unregister(struct drm_connector *connector) |
| 4920 | { |
| 4921 | drm_dp_aux_unregister(&intel_attached_dp(connector)->aux); |
| 4922 | intel_connector_unregister(connector); |
| 4923 | } |
| 4924 | |
| 4925 | static void |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 4926 | intel_dp_connector_destroy(struct drm_connector *connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4927 | { |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4928 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4929 | |
Chris Wilson | 10e972d | 2014-09-04 21:43:45 +0100 | [diff] [blame] | 4930 | kfree(intel_connector->detect_edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4931 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4932 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 4933 | kfree(intel_connector->edid); |
| 4934 | |
Paulo Zanoni | acd8db10 | 2013-06-12 17:27:23 -0300 | [diff] [blame] | 4935 | /* Can't call is_edp() since the encoder may have been destroyed |
| 4936 | * already. */ |
| 4937 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4938 | intel_panel_fini(&intel_connector->panel); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4939 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4940 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 4941 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 4944 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4945 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4946 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 4947 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4948 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4949 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4950 | if (is_edp(intel_dp)) { |
| 4951 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4952 | /* |
| 4953 | * vdd might still be enabled do to the delayed vdd off. |
| 4954 | * Make sure vdd is actually turned off here. |
| 4955 | */ |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4956 | pps_lock(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 4957 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4958 | pps_unlock(intel_dp); |
| 4959 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 4960 | if (intel_dp->edp_notifier.notifier_call) { |
| 4961 | unregister_reboot_notifier(&intel_dp->edp_notifier); |
| 4962 | intel_dp->edp_notifier.notifier_call = NULL; |
| 4963 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4964 | } |
Chris Wilson | 9968188 | 2016-06-20 09:29:17 +0100 | [diff] [blame] | 4965 | |
| 4966 | intel_dp_aux_fini(intel_dp); |
| 4967 | |
Imre Deak | c8bd0e4 | 2014-12-12 17:57:38 +0200 | [diff] [blame] | 4968 | drm_encoder_cleanup(encoder); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4969 | kfree(intel_dig_port); |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4970 | } |
| 4971 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 4972 | void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4973 | { |
| 4974 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 4975 | |
| 4976 | if (!is_edp(intel_dp)) |
| 4977 | return; |
| 4978 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4979 | /* |
| 4980 | * vdd might still be enabled do to the delayed vdd off. |
| 4981 | * Make sure vdd is actually turned off here. |
| 4982 | */ |
Ville Syrjälä | afa4e53 | 2014-11-25 15:43:48 +0200 | [diff] [blame] | 4983 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4984 | pps_lock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4985 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4986 | pps_unlock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4987 | } |
| 4988 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4989 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
| 4990 | { |
| 4991 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4992 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4993 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4994 | |
| 4995 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 4996 | |
| 4997 | if (!edp_have_panel_vdd(intel_dp)) |
| 4998 | return; |
| 4999 | |
| 5000 | /* |
| 5001 | * The VDD bit needs a power domain reference, so if the bit is |
| 5002 | * already enabled when we boot or resume, grab this reference and |
| 5003 | * schedule a vdd off, so we don't hold on to the reference |
| 5004 | * indefinitely. |
| 5005 | */ |
| 5006 | DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n"); |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5007 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5008 | |
| 5009 | edp_panel_vdd_schedule_off(intel_dp); |
| 5010 | } |
| 5011 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5012 | static enum pipe vlv_active_pipe(struct intel_dp *intel_dp) |
| 5013 | { |
| 5014 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 5015 | |
| 5016 | if ((intel_dp->DP & DP_PORT_EN) == 0) |
| 5017 | return INVALID_PIPE; |
| 5018 | |
| 5019 | if (IS_CHERRYVIEW(dev_priv)) |
| 5020 | return DP_PORT_TO_PIPE_CHV(intel_dp->DP); |
| 5021 | else |
| 5022 | return PORT_TO_PIPE(intel_dp->DP); |
| 5023 | } |
| 5024 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 5025 | void intel_dp_encoder_reset(struct drm_encoder *encoder) |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5026 | { |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5027 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5028 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 5029 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5030 | |
| 5031 | if (!HAS_DDI(dev_priv)) |
| 5032 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5033 | |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5034 | if (lspcon->active) |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 5035 | lspcon_resume(lspcon); |
| 5036 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5037 | intel_dp->reset_link_params = true; |
| 5038 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5039 | pps_lock(intel_dp); |
| 5040 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5041 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5042 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 5043 | |
| 5044 | if (is_edp(intel_dp)) { |
| 5045 | /* Reinit the power sequencer, in case BIOS did something with it. */ |
| 5046 | intel_dp_pps_init(encoder->dev, intel_dp); |
| 5047 | intel_edp_panel_vdd_sanitize(intel_dp); |
| 5048 | } |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5049 | |
| 5050 | pps_unlock(intel_dp); |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5051 | } |
| 5052 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5053 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 5054 | .dpms = drm_atomic_helper_connector_dpms, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5055 | .detect = intel_dp_detect, |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 5056 | .force = intel_dp_force, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5057 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5058 | .set_property = intel_dp_set_property, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 5059 | .atomic_get_property = intel_connector_atomic_get_property, |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5060 | .late_register = intel_dp_connector_register, |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 5061 | .early_unregister = intel_dp_connector_unregister, |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 5062 | .destroy = intel_dp_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 5063 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Ander Conselvan de Oliveira | 9896972 | 2015-03-20 16:18:06 +0200 | [diff] [blame] | 5064 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5065 | }; |
| 5066 | |
| 5067 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
| 5068 | .get_modes = intel_dp_get_modes, |
| 5069 | .mode_valid = intel_dp_mode_valid, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5070 | }; |
| 5071 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5072 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5073 | .reset = intel_dp_encoder_reset, |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5074 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5075 | }; |
| 5076 | |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5077 | enum irqreturn |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5078 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
| 5079 | { |
| 5080 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5081 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5082 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5083 | enum irqreturn ret = IRQ_NONE; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5084 | |
Takashi Iwai | 2540058 | 2015-11-19 12:09:56 +0100 | [diff] [blame] | 5085 | if (intel_dig_port->base.type != INTEL_OUTPUT_EDP && |
| 5086 | intel_dig_port->base.type != INTEL_OUTPUT_HDMI) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 5087 | intel_dig_port->base.type = INTEL_OUTPUT_DP; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5088 | |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5089 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
| 5090 | /* |
| 5091 | * vdd off can generate a long pulse on eDP which |
| 5092 | * would require vdd on to handle it, and thus we |
| 5093 | * would end up in an endless cycle of |
| 5094 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." |
| 5095 | */ |
| 5096 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", |
| 5097 | port_name(intel_dig_port->port)); |
Ville Syrjälä | a8b3d52f8 | 2015-02-10 14:11:46 +0200 | [diff] [blame] | 5098 | return IRQ_HANDLED; |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5099 | } |
| 5100 | |
Ville Syrjälä | 26fbb77 | 2014-08-11 18:37:37 +0300 | [diff] [blame] | 5101 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
| 5102 | port_name(intel_dig_port->port), |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5103 | long_hpd ? "long" : "short"); |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5104 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5105 | if (long_hpd) { |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5106 | intel_dp->reset_link_params = true; |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5107 | intel_dp->detect_done = false; |
| 5108 | return IRQ_NONE; |
| 5109 | } |
| 5110 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5111 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5112 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5113 | if (intel_dp->is_mst) { |
| 5114 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) { |
| 5115 | /* |
| 5116 | * If we were in MST mode, and device is not |
| 5117 | * there, get out of MST mode |
| 5118 | */ |
| 5119 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 5120 | intel_dp->is_mst, intel_dp->mst_mgr.mst_state); |
| 5121 | intel_dp->is_mst = false; |
| 5122 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 5123 | intel_dp->is_mst); |
| 5124 | intel_dp->detect_done = false; |
| 5125 | goto put_power; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5126 | } |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5127 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5128 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5129 | if (!intel_dp->is_mst) { |
| 5130 | if (!intel_dp_short_pulse(intel_dp)) { |
| 5131 | intel_dp->detect_done = false; |
| 5132 | goto put_power; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 5133 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5134 | } |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5135 | |
| 5136 | ret = IRQ_HANDLED; |
| 5137 | |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5138 | put_power: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5139 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5140 | |
| 5141 | return ret; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5142 | } |
| 5143 | |
Rodrigo Vivi | 477ec32 | 2015-08-06 15:51:39 +0800 | [diff] [blame] | 5144 | /* check the VBT to see whether the eDP is on another port */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5145 | 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] | 5146 | { |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5147 | /* |
| 5148 | * eDP not supported on g4x. so bail out early just |
| 5149 | * for a bit extra safety in case the VBT is bonkers. |
| 5150 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5151 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5152 | return false; |
| 5153 | |
Imre Deak | a98d9c1 | 2016-12-21 12:17:24 +0200 | [diff] [blame] | 5154 | if (INTEL_GEN(dev_priv) < 9 && port == PORT_A) |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5155 | return true; |
| 5156 | |
Jani Nikula | 951d9ef | 2016-03-16 12:43:31 +0200 | [diff] [blame] | 5157 | return intel_bios_is_port_edp(dev_priv, port); |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 5158 | } |
| 5159 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5160 | void |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5161 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 5162 | { |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5163 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 5164 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 5165 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 5166 | intel_attach_broadcast_rgb_property(connector); |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 5167 | intel_dp->color_range_auto = true; |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5168 | |
| 5169 | if (is_edp(intel_dp)) { |
| 5170 | drm_mode_create_scaling_mode_property(connector->dev); |
Rob Clark | 6de6d84 | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 5171 | drm_object_attach_property( |
| 5172 | &connector->base, |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5173 | connector->dev->mode_config.scaling_mode_property, |
Yuly Novikov | 8e740cd | 2012-10-26 12:04:01 +0300 | [diff] [blame] | 5174 | DRM_MODE_SCALE_ASPECT); |
| 5175 | intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT; |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5176 | } |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5177 | } |
| 5178 | |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5179 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
| 5180 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 5181 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5182 | intel_dp->last_power_on = jiffies; |
| 5183 | intel_dp->last_backlight_off = jiffies; |
| 5184 | } |
| 5185 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5186 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5187 | intel_pps_readout_hw_state(struct drm_i915_private *dev_priv, |
| 5188 | struct intel_dp *intel_dp, struct edp_power_seq *seq) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5189 | { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5190 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5191 | struct pps_registers regs; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5192 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5193 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5194 | |
| 5195 | /* Workaround: Need to write PP_CONTROL with the unlock key as |
| 5196 | * the very first thing. */ |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5197 | pp_ctl = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5198 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5199 | pp_on = I915_READ(regs.pp_on); |
| 5200 | pp_off = I915_READ(regs.pp_off); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5201 | if (!IS_GEN9_LP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5202 | I915_WRITE(regs.pp_ctrl, pp_ctl); |
| 5203 | pp_div = I915_READ(regs.pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5204 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5205 | |
| 5206 | /* Pull timing values out of registers */ |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5207 | seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 5208 | PANEL_POWER_UP_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5209 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5210 | seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 5211 | PANEL_LIGHT_ON_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5212 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5213 | seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 5214 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5215 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5216 | seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 5217 | PANEL_POWER_DOWN_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5218 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5219 | if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5220 | u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> |
| 5221 | BXT_POWER_CYCLE_DELAY_SHIFT; |
| 5222 | if (tmp > 0) |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5223 | seq->t11_t12 = (tmp - 1) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5224 | else |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5225 | seq->t11_t12 = 0; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5226 | } else { |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5227 | seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5228 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5229 | } |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | static void |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5233 | intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq) |
| 5234 | { |
| 5235 | DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 5236 | state_name, |
| 5237 | seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12); |
| 5238 | } |
| 5239 | |
| 5240 | static void |
| 5241 | intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 5242 | struct intel_dp *intel_dp) |
| 5243 | { |
| 5244 | struct edp_power_seq hw; |
| 5245 | struct edp_power_seq *sw = &intel_dp->pps_delays; |
| 5246 | |
| 5247 | intel_pps_readout_hw_state(dev_priv, intel_dp, &hw); |
| 5248 | |
| 5249 | if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 || |
| 5250 | hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) { |
| 5251 | DRM_ERROR("PPS state mismatch\n"); |
| 5252 | intel_pps_dump_state("sw", sw); |
| 5253 | intel_pps_dump_state("hw", &hw); |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5258 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
| 5259 | struct intel_dp *intel_dp) |
| 5260 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5261 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5262 | struct edp_power_seq cur, vbt, spec, |
| 5263 | *final = &intel_dp->pps_delays; |
| 5264 | |
| 5265 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5266 | |
| 5267 | /* already initialized? */ |
| 5268 | if (final->t11_t12 != 0) |
| 5269 | return; |
| 5270 | |
| 5271 | intel_pps_readout_hw_state(dev_priv, intel_dp, &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5272 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5273 | intel_pps_dump_state("cur", &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5274 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 5275 | vbt = dev_priv->vbt.edp.pps; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5276 | |
| 5277 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of |
| 5278 | * our hw here, which are all in 100usec. */ |
| 5279 | spec.t1_t3 = 210 * 10; |
| 5280 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ |
| 5281 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ |
| 5282 | spec.t10 = 500 * 10; |
| 5283 | /* This one is special and actually in units of 100ms, but zero |
| 5284 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5285 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5286 | * too. */ |
| 5287 | spec.t11_t12 = (510 + 100) * 10; |
| 5288 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5289 | intel_pps_dump_state("vbt", &vbt); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5290 | |
| 5291 | /* Use the max of the register settings and vbt. If both are |
| 5292 | * unset, fall back to the spec limits. */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5293 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5294 | spec.field : \ |
| 5295 | max(cur.field, vbt.field)) |
| 5296 | assign_final(t1_t3); |
| 5297 | assign_final(t8); |
| 5298 | assign_final(t9); |
| 5299 | assign_final(t10); |
| 5300 | assign_final(t11_t12); |
| 5301 | #undef assign_final |
| 5302 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5303 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5304 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 5305 | intel_dp->backlight_on_delay = get_delay(t8); |
| 5306 | intel_dp->backlight_off_delay = get_delay(t9); |
| 5307 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 5308 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 5309 | #undef get_delay |
| 5310 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5311 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 5312 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 5313 | intel_dp->panel_power_cycle_delay); |
| 5314 | |
| 5315 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 5316 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5317 | |
| 5318 | /* |
| 5319 | * We override the HW backlight delays to 1 because we do manual waits |
| 5320 | * on them. For T8, even BSpec recommends doing it. For T9, if we |
| 5321 | * don't do this, we'll end up waiting for the backlight off delay |
| 5322 | * twice: once when we do the manual sleep, and once when we disable |
| 5323 | * the panel and wait for the PP_STATUS bit to become zero. |
| 5324 | */ |
| 5325 | final->t8 = 1; |
| 5326 | final->t9 = 1; |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5327 | } |
| 5328 | |
| 5329 | static void |
| 5330 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5331 | struct intel_dp *intel_dp, |
| 5332 | bool force_disable_vdd) |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5333 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5334 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5335 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 5336 | int div = dev_priv->rawclk_freq / 1000; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5337 | struct pps_registers regs; |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5338 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5339 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5340 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 5341 | lockdep_assert_held(&dev_priv->pps_mutex); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5342 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5343 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5344 | |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5345 | /* |
| 5346 | * On some VLV machines the BIOS can leave the VDD |
| 5347 | * enabled even on power seqeuencers which aren't |
| 5348 | * hooked up to any port. This would mess up the |
| 5349 | * power domain tracking the first time we pick |
| 5350 | * one of these power sequencers for use since |
| 5351 | * edp_panel_vdd_on() would notice that the VDD was |
| 5352 | * already on and therefore wouldn't grab the power |
| 5353 | * domain reference. Disable VDD first to avoid this. |
| 5354 | * This also avoids spuriously turning the VDD on as |
| 5355 | * soon as the new power seqeuencer gets initialized. |
| 5356 | */ |
| 5357 | if (force_disable_vdd) { |
| 5358 | u32 pp = ironlake_get_pp_control(intel_dp); |
| 5359 | |
| 5360 | WARN(pp & PANEL_POWER_ON, "Panel power already on\n"); |
| 5361 | |
| 5362 | if (pp & EDP_FORCE_VDD) |
| 5363 | DRM_DEBUG_KMS("VDD already on, disabling first\n"); |
| 5364 | |
| 5365 | pp &= ~EDP_FORCE_VDD; |
| 5366 | |
| 5367 | I915_WRITE(regs.pp_ctrl, pp); |
| 5368 | } |
| 5369 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5370 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5371 | (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT); |
| 5372 | pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5373 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5374 | /* Compute the divisor for the pp clock, simply match the Bspec |
| 5375 | * formula. */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5376 | if (IS_GEN9_LP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5377 | pp_div = I915_READ(regs.pp_ctrl); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5378 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; |
| 5379 | pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000) |
| 5380 | << BXT_POWER_CYCLE_DELAY_SHIFT); |
| 5381 | } else { |
| 5382 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 5383 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
| 5384 | << PANEL_POWER_CYCLE_DELAY_SHIFT); |
| 5385 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5386 | |
| 5387 | /* Haswell doesn't have any port selection bits for the panel |
| 5388 | * power sequencer any more. */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5389 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5390 | port_sel = PANEL_PORT_SELECT_VLV(port); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5391 | } 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] | 5392 | if (port == PORT_A) |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5393 | port_sel = PANEL_PORT_SELECT_DPA; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5394 | else |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5395 | port_sel = PANEL_PORT_SELECT_DPD; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5396 | } |
| 5397 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5398 | pp_on |= port_sel; |
| 5399 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5400 | I915_WRITE(regs.pp_on, pp_on); |
| 5401 | I915_WRITE(regs.pp_off, pp_off); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5402 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5403 | I915_WRITE(regs.pp_ctrl, pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5404 | else |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5405 | I915_WRITE(regs.pp_div, pp_div); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5406 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5407 | 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] | 5408 | I915_READ(regs.pp_on), |
| 5409 | I915_READ(regs.pp_off), |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 5410 | IS_GEN9_LP(dev_priv) ? |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5411 | (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) : |
| 5412 | I915_READ(regs.pp_div)); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 5413 | } |
| 5414 | |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5415 | static void intel_dp_pps_init(struct drm_device *dev, |
| 5416 | struct intel_dp *intel_dp) |
| 5417 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5418 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5419 | |
| 5420 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5421 | vlv_initial_power_sequencer_setup(intel_dp); |
| 5422 | } else { |
| 5423 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5424 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5428 | /** |
| 5429 | * 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] | 5430 | * @dev_priv: i915 device |
Maarten Lankhorst | e896402 | 2016-08-25 11:07:02 +0200 | [diff] [blame] | 5431 | * @crtc_state: a pointer to the active intel_crtc_state |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5432 | * @refresh_rate: RR to be programmed |
| 5433 | * |
| 5434 | * This function gets called when refresh rate (RR) has to be changed from |
| 5435 | * one frequency to another. Switches can be between high and low RR |
| 5436 | * supported by the panel or to any other RR based on media playback (in |
| 5437 | * this case, RR value needs to be passed from user space). |
| 5438 | * |
| 5439 | * The caller of this function needs to take a lock on dev_priv->drrs. |
| 5440 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5441 | static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv, |
| 5442 | struct intel_crtc_state *crtc_state, |
| 5443 | int refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5444 | { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5445 | struct intel_encoder *encoder; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5446 | struct intel_digital_port *dig_port = NULL; |
| 5447 | struct intel_dp *intel_dp = dev_priv->drrs.dp; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5448 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5449 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5450 | |
| 5451 | if (refresh_rate <= 0) { |
| 5452 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); |
| 5453 | return; |
| 5454 | } |
| 5455 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5456 | if (intel_dp == NULL) { |
| 5457 | DRM_DEBUG_KMS("DRRS not supported.\n"); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5458 | return; |
| 5459 | } |
| 5460 | |
Daniel Vetter | 1fcc9d1 | 2014-07-11 10:30:10 -0700 | [diff] [blame] | 5461 | /* |
Rodrigo Vivi | e4d59f6 | 2014-11-20 02:22:08 -0800 | [diff] [blame] | 5462 | * FIXME: This needs proper synchronization with psr state for some |
| 5463 | * platforms that cannot have PSR and DRRS enabled at the same time. |
Daniel Vetter | 1fcc9d1 | 2014-07-11 10:30:10 -0700 | [diff] [blame] | 5464 | */ |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5465 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5466 | dig_port = dp_to_dig_port(intel_dp); |
| 5467 | encoder = &dig_port->base; |
Ander Conselvan de Oliveira | 723f9aa | 2015-03-20 16:18:18 +0200 | [diff] [blame] | 5468 | intel_crtc = to_intel_crtc(encoder->base.crtc); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5469 | |
| 5470 | if (!intel_crtc) { |
| 5471 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); |
| 5472 | return; |
| 5473 | } |
| 5474 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5475 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5476 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
| 5477 | return; |
| 5478 | } |
| 5479 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5480 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
| 5481 | refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5482 | index = DRRS_LOW_RR; |
| 5483 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5484 | if (index == dev_priv->drrs.refresh_rate_type) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5485 | DRM_DEBUG_KMS( |
| 5486 | "DRRS requested for previously set RR...ignoring\n"); |
| 5487 | return; |
| 5488 | } |
| 5489 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5490 | if (!crtc_state->base.active) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5491 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); |
| 5492 | return; |
| 5493 | } |
| 5494 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5495 | if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) { |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5496 | switch (index) { |
| 5497 | case DRRS_HIGH_RR: |
| 5498 | intel_dp_set_m_n(intel_crtc, M1_N1); |
| 5499 | break; |
| 5500 | case DRRS_LOW_RR: |
| 5501 | intel_dp_set_m_n(intel_crtc, M2_N2); |
| 5502 | break; |
| 5503 | case DRRS_MAX_RR: |
| 5504 | default: |
| 5505 | DRM_ERROR("Unsupported refreshrate type\n"); |
| 5506 | } |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5507 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 5508 | i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5509 | u32 val; |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5510 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5511 | val = I915_READ(reg); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5512 | if (index > DRRS_HIGH_RR) { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5513 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5514 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5515 | else |
| 5516 | val |= PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5517 | } else { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5518 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5519 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5520 | else |
| 5521 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5522 | } |
| 5523 | I915_WRITE(reg, val); |
| 5524 | } |
| 5525 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5526 | dev_priv->drrs.refresh_rate_type = index; |
| 5527 | |
| 5528 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); |
| 5529 | } |
| 5530 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5531 | /** |
| 5532 | * intel_edp_drrs_enable - init drrs struct if supported |
| 5533 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5534 | * @crtc_state: A pointer to the active crtc state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5535 | * |
| 5536 | * Initializes frontbuffer_bits and drrs.dp |
| 5537 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5538 | void intel_edp_drrs_enable(struct intel_dp *intel_dp, |
| 5539 | struct intel_crtc_state *crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5540 | { |
| 5541 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5542 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5543 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5544 | if (!crtc_state->has_drrs) { |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5545 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); |
| 5546 | return; |
| 5547 | } |
| 5548 | |
| 5549 | mutex_lock(&dev_priv->drrs.mutex); |
| 5550 | if (WARN_ON(dev_priv->drrs.dp)) { |
| 5551 | DRM_ERROR("DRRS already enabled\n"); |
| 5552 | goto unlock; |
| 5553 | } |
| 5554 | |
| 5555 | dev_priv->drrs.busy_frontbuffer_bits = 0; |
| 5556 | |
| 5557 | dev_priv->drrs.dp = intel_dp; |
| 5558 | |
| 5559 | unlock: |
| 5560 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5561 | } |
| 5562 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5563 | /** |
| 5564 | * intel_edp_drrs_disable - Disable DRRS |
| 5565 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5566 | * @old_crtc_state: Pointer to old crtc_state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5567 | * |
| 5568 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5569 | void intel_edp_drrs_disable(struct intel_dp *intel_dp, |
| 5570 | struct intel_crtc_state *old_crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5571 | { |
| 5572 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5573 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5574 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5575 | if (!old_crtc_state->has_drrs) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5576 | return; |
| 5577 | |
| 5578 | mutex_lock(&dev_priv->drrs.mutex); |
| 5579 | if (!dev_priv->drrs.dp) { |
| 5580 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5581 | return; |
| 5582 | } |
| 5583 | |
| 5584 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5585 | intel_dp_set_drrs_state(dev_priv, old_crtc_state, |
| 5586 | intel_dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5587 | |
| 5588 | dev_priv->drrs.dp = NULL; |
| 5589 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5590 | |
| 5591 | cancel_delayed_work_sync(&dev_priv->drrs.work); |
| 5592 | } |
| 5593 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5594 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
| 5595 | { |
| 5596 | struct drm_i915_private *dev_priv = |
| 5597 | container_of(work, typeof(*dev_priv), drrs.work.work); |
| 5598 | struct intel_dp *intel_dp; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5599 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5600 | mutex_lock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5601 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5602 | intel_dp = dev_priv->drrs.dp; |
| 5603 | |
| 5604 | if (!intel_dp) |
| 5605 | goto unlock; |
| 5606 | |
| 5607 | /* |
| 5608 | * The delayed work can race with an invalidate hence we need to |
| 5609 | * recheck. |
| 5610 | */ |
| 5611 | |
| 5612 | if (dev_priv->drrs.busy_frontbuffer_bits) |
| 5613 | goto unlock; |
| 5614 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5615 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) { |
| 5616 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 5617 | |
| 5618 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5619 | intel_dp->attached_connector->panel.downclock_mode->vrefresh); |
| 5620 | } |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5621 | |
| 5622 | unlock: |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5623 | mutex_unlock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5624 | } |
| 5625 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5626 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5627 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5628 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5629 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5630 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5631 | * This function gets called everytime rendering on the given planes start. |
| 5632 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5633 | * |
| 5634 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5635 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5636 | void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv, |
| 5637 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5638 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5639 | struct drm_crtc *crtc; |
| 5640 | enum pipe pipe; |
| 5641 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5642 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5643 | return; |
| 5644 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5645 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5646 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5647 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5648 | if (!dev_priv->drrs.dp) { |
| 5649 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5650 | return; |
| 5651 | } |
| 5652 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5653 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5654 | pipe = to_intel_crtc(crtc)->pipe; |
| 5655 | |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5656 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 5657 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; |
| 5658 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5659 | /* invalidate means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5660 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5661 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5662 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
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 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5665 | } |
| 5666 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5667 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5668 | * intel_edp_drrs_flush - Restart Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5669 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5670 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5671 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5672 | * This function gets called every time rendering on the given planes has |
| 5673 | * completed or flip on a crtc is completed. So DRRS should be upclocked |
| 5674 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, |
| 5675 | * if no other planes are dirty. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5676 | * |
| 5677 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5678 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5679 | void intel_edp_drrs_flush(struct drm_i915_private *dev_priv, |
| 5680 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5681 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5682 | struct drm_crtc *crtc; |
| 5683 | enum pipe pipe; |
| 5684 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5685 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5686 | return; |
| 5687 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5688 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5689 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5690 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5691 | if (!dev_priv->drrs.dp) { |
| 5692 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5693 | return; |
| 5694 | } |
| 5695 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5696 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5697 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5698 | |
| 5699 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5700 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 5701 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5702 | /* flush means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5703 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5704 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5705 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5706 | |
| 5707 | /* |
| 5708 | * flush also means no more activity hence schedule downclock, if all |
| 5709 | * other fbs are quiescent too |
| 5710 | */ |
| 5711 | if (!dev_priv->drrs.busy_frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5712 | schedule_delayed_work(&dev_priv->drrs.work, |
| 5713 | msecs_to_jiffies(1000)); |
| 5714 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5715 | } |
| 5716 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5717 | /** |
| 5718 | * DOC: Display Refresh Rate Switching (DRRS) |
| 5719 | * |
| 5720 | * Display Refresh Rate Switching (DRRS) is a power conservation feature |
| 5721 | * which enables swtching between low and high refresh rates, |
| 5722 | * dynamically, based on the usage scenario. This feature is applicable |
| 5723 | * for internal panels. |
| 5724 | * |
| 5725 | * Indication that the panel supports DRRS is given by the panel EDID, which |
| 5726 | * would list multiple refresh rates for one resolution. |
| 5727 | * |
| 5728 | * DRRS is of 2 types - static and seamless. |
| 5729 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset |
| 5730 | * (may appear as a blink on screen) and is used in dock-undock scenario. |
| 5731 | * Seamless DRRS involves changing RR without any visual effect to the user |
| 5732 | * and can be used during normal system usage. This is done by programming |
| 5733 | * certain registers. |
| 5734 | * |
| 5735 | * Support for static/seamless DRRS may be indicated in the VBT based on |
| 5736 | * inputs from the panel spec. |
| 5737 | * |
| 5738 | * DRRS saves power by switching to low RR based on usage scenarios. |
| 5739 | * |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 5740 | * The implementation is based on frontbuffer tracking implementation. When |
| 5741 | * there is a disturbance on the screen triggered by user activity or a periodic |
| 5742 | * system activity, DRRS is disabled (RR is changed to high RR). When there is |
| 5743 | * no movement on screen, after a timeout of 1 second, a switch to low RR is |
| 5744 | * made. |
| 5745 | * |
| 5746 | * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate() |
| 5747 | * and intel_edp_drrs_flush() are called. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5748 | * |
| 5749 | * DRRS can be further extended to support other internal panels and also |
| 5750 | * the scenario of video playback wherein RR is set based on the rate |
| 5751 | * requested by userspace. |
| 5752 | */ |
| 5753 | |
| 5754 | /** |
| 5755 | * intel_dp_drrs_init - Init basic DRRS work and mutex. |
| 5756 | * @intel_connector: eDP connector |
| 5757 | * @fixed_mode: preferred mode of panel |
| 5758 | * |
| 5759 | * This function is called only once at driver load to initialize basic |
| 5760 | * DRRS stuff. |
| 5761 | * |
| 5762 | * Returns: |
| 5763 | * Downclock mode if panel supports it, else return NULL. |
| 5764 | * DRRS support is determined by the presence of downclock mode (apart |
| 5765 | * from VBT setting). |
| 5766 | */ |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5767 | static struct drm_display_mode * |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5768 | intel_dp_drrs_init(struct intel_connector *intel_connector, |
| 5769 | struct drm_display_mode *fixed_mode) |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5770 | { |
| 5771 | struct drm_connector *connector = &intel_connector->base; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5772 | struct drm_device *dev = connector->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5773 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5774 | struct drm_display_mode *downclock_mode = NULL; |
| 5775 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5776 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
| 5777 | mutex_init(&dev_priv->drrs.mutex); |
| 5778 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5779 | if (INTEL_GEN(dev_priv) <= 6) { |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5780 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); |
| 5781 | return NULL; |
| 5782 | } |
| 5783 | |
| 5784 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5785 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5786 | return NULL; |
| 5787 | } |
| 5788 | |
| 5789 | downclock_mode = intel_find_panel_downclock |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 5790 | (dev_priv, fixed_mode, connector); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5791 | |
| 5792 | if (!downclock_mode) { |
Ramalingam C | a1d2634 | 2015-02-23 17:38:33 +0530 | [diff] [blame] | 5793 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5794 | return NULL; |
| 5795 | } |
| 5796 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5797 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5798 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5799 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5800 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5801 | return downclock_mode; |
| 5802 | } |
| 5803 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5804 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5805 | struct intel_connector *intel_connector) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5806 | { |
| 5807 | struct drm_connector *connector = &intel_connector->base; |
| 5808 | 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] | 5809 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5810 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5811 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5812 | struct drm_display_mode *fixed_mode = NULL; |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5813 | struct drm_display_mode *downclock_mode = NULL; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5814 | bool has_dpcd; |
| 5815 | struct drm_display_mode *scan; |
| 5816 | struct edid *edid; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5817 | enum pipe pipe = INVALID_PIPE; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5818 | |
| 5819 | if (!is_edp(intel_dp)) |
| 5820 | return true; |
| 5821 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 5822 | /* |
| 5823 | * On IBX/CPT we may get here with LVDS already registered. Since the |
| 5824 | * driver uses the only internal power sequencer available for both |
| 5825 | * eDP and LVDS bail out early in this case to prevent interfering |
| 5826 | * with an already powered-on LVDS power sequencer. |
| 5827 | */ |
| 5828 | if (intel_get_lvds_encoder(dev)) { |
| 5829 | WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))); |
| 5830 | DRM_INFO("LVDS was detected, not registering eDP\n"); |
| 5831 | |
| 5832 | return false; |
| 5833 | } |
| 5834 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5835 | pps_lock(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5836 | |
| 5837 | intel_dp_init_panel_power_timestamps(intel_dp); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5838 | intel_dp_pps_init(dev, intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5839 | intel_edp_panel_vdd_sanitize(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5840 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5841 | pps_unlock(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5842 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5843 | /* Cache DPCD and EDID for edp. */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5844 | has_dpcd = intel_edp_init_dpcd(intel_dp); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5845 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5846 | if (!has_dpcd) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5847 | /* if this fails, presume the device is a ghost */ |
| 5848 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5849 | goto out_vdd_off; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5850 | } |
| 5851 | |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5852 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 5853 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5854 | if (edid) { |
| 5855 | if (drm_add_edid_modes(connector, edid)) { |
| 5856 | drm_mode_connector_update_edid_property(connector, |
| 5857 | edid); |
| 5858 | drm_edid_to_eld(connector, edid); |
| 5859 | } else { |
| 5860 | kfree(edid); |
| 5861 | edid = ERR_PTR(-EINVAL); |
| 5862 | } |
| 5863 | } else { |
| 5864 | edid = ERR_PTR(-ENOENT); |
| 5865 | } |
| 5866 | intel_connector->edid = edid; |
| 5867 | |
| 5868 | /* prefer fixed mode from EDID if available */ |
| 5869 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 5870 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 5871 | fixed_mode = drm_mode_duplicate(dev, scan); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5872 | downclock_mode = intel_dp_drrs_init( |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5873 | intel_connector, fixed_mode); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5874 | break; |
| 5875 | } |
| 5876 | } |
| 5877 | |
| 5878 | /* fallback to VBT if available for eDP */ |
| 5879 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { |
| 5880 | fixed_mode = drm_mode_duplicate(dev, |
| 5881 | dev_priv->vbt.lfp_lvds_vbt_mode); |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5882 | if (fixed_mode) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5883 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5884 | connector->display_info.width_mm = fixed_mode->width_mm; |
| 5885 | connector->display_info.height_mm = fixed_mode->height_mm; |
| 5886 | } |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5887 | } |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5888 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5889 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5890 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5891 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
| 5892 | register_reboot_notifier(&intel_dp->edp_notifier); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5893 | |
| 5894 | /* |
| 5895 | * Figure out the current pipe for the initial backlight setup. |
| 5896 | * If the current pipe isn't valid, try the PPS pipe, and if that |
| 5897 | * fails just assume pipe A. |
| 5898 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5899 | pipe = vlv_active_pipe(intel_dp); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5900 | |
| 5901 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5902 | pipe = intel_dp->pps_pipe; |
| 5903 | |
| 5904 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5905 | pipe = PIPE_A; |
| 5906 | |
| 5907 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", |
| 5908 | pipe_name(pipe)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5911 | intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 5912 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5913 | intel_panel_setup_backlight(connector, pipe); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5914 | |
| 5915 | return true; |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5916 | |
| 5917 | out_vdd_off: |
| 5918 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 5919 | /* |
| 5920 | * vdd might still be enabled do to the delayed vdd off. |
| 5921 | * Make sure vdd is actually turned off here. |
| 5922 | */ |
| 5923 | pps_lock(intel_dp); |
| 5924 | edp_panel_vdd_off_sync(intel_dp); |
| 5925 | pps_unlock(intel_dp); |
| 5926 | |
| 5927 | return false; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5928 | } |
| 5929 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5930 | /* Set up the hotplug pin and aux power domain. */ |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5931 | static void |
| 5932 | intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port) |
| 5933 | { |
| 5934 | struct intel_encoder *encoder = &intel_dig_port->base; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5935 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5936 | |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5937 | switch (intel_dig_port->port) { |
| 5938 | case PORT_A: |
| 5939 | encoder->hpd_pin = HPD_PORT_A; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5940 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5941 | break; |
| 5942 | case PORT_B: |
| 5943 | encoder->hpd_pin = HPD_PORT_B; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5944 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5945 | break; |
| 5946 | case PORT_C: |
| 5947 | encoder->hpd_pin = HPD_PORT_C; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5948 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5949 | break; |
| 5950 | case PORT_D: |
| 5951 | encoder->hpd_pin = HPD_PORT_D; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5952 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5953 | break; |
| 5954 | case PORT_E: |
| 5955 | encoder->hpd_pin = HPD_PORT_E; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5956 | |
| 5957 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5958 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5959 | break; |
| 5960 | default: |
| 5961 | MISSING_CASE(intel_dig_port->port); |
| 5962 | } |
| 5963 | } |
| 5964 | |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 5965 | bool |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5966 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
| 5967 | struct intel_connector *intel_connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5968 | { |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5969 | struct drm_connector *connector = &intel_connector->base; |
| 5970 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 5971 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5972 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5973 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 5974 | enum port port = intel_dig_port->port; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5975 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5976 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 5977 | if (WARN(intel_dig_port->max_lanes < 1, |
| 5978 | "Not enough lanes (%d) for DP on port %c\n", |
| 5979 | intel_dig_port->max_lanes, port_name(port))) |
| 5980 | return false; |
| 5981 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 5982 | intel_dp_set_source_rates(intel_dp); |
| 5983 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5984 | intel_dp->reset_link_params = true; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 5985 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5986 | intel_dp->active_pipe = INVALID_PIPE; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 5987 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5988 | /* intel_dp vfuncs */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5989 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 5990 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5991 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5992 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5993 | else if (HAS_PCH_SPLIT(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5994 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; |
| 5995 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 5996 | intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider; |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 5997 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5998 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 5999 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; |
| 6000 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 6001 | intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl; |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 6002 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6003 | if (HAS_DDI(dev_priv)) |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 6004 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; |
| 6005 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 6006 | /* Preserve the current hw state. */ |
| 6007 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 6008 | intel_dp->attached_connector = intel_connector; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 6009 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6010 | if (intel_dp_is_edp(dev_priv, port)) |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 6011 | type = DRM_MODE_CONNECTOR_eDP; |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 6012 | else |
| 6013 | type = DRM_MODE_CONNECTOR_DisplayPort; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6014 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6015 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 6016 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 6017 | |
Imre Deak | f7d2490 | 2013-05-08 13:14:05 +0300 | [diff] [blame] | 6018 | /* |
| 6019 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but |
| 6020 | * for DP the encoder type can be set by the caller to |
| 6021 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. |
| 6022 | */ |
| 6023 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 6024 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 6025 | |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6026 | /* eDP only on port B and/or C on vlv/chv */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6027 | if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 6028 | is_edp(intel_dp) && port != PORT_B && port != PORT_C)) |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6029 | return false; |
| 6030 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 6031 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
| 6032 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", |
| 6033 | port_name(port)); |
| 6034 | |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6035 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6036 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 6037 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6038 | connector->interlace_allowed = true; |
| 6039 | connector->doublescan_allowed = 0; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 6040 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 6041 | intel_dp_init_connector_port_info(intel_dig_port); |
| 6042 | |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 6043 | intel_dp_aux_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6044 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 6045 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 6046 | edp_panel_vdd_work); |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 6047 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6048 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6049 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6050 | if (HAS_DDI(dev_priv)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 6051 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 6052 | else |
| 6053 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
| 6054 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6055 | /* init MST on ports that can support it */ |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 6056 | if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) && |
Jani Nikula | 0c9b371 | 2015-05-18 17:10:01 +0300 | [diff] [blame] | 6057 | (port == PORT_B || port == PORT_C || port == PORT_D)) |
| 6058 | intel_dp_mst_encoder_init(intel_dig_port, |
| 6059 | intel_connector->base.base.id); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6060 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 6061 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6062 | intel_dp_aux_fini(intel_dp); |
| 6063 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
| 6064 | goto fail; |
Paulo Zanoni | b2f246a | 2013-06-12 17:27:26 -0300 | [diff] [blame] | 6065 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 6066 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 6067 | intel_dp_add_properties(intel_dp, connector); |
| 6068 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6069 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 6070 | * 0xd. Failure to do so will result in spurious interrupts being |
| 6071 | * generated on the port when a cable is not attached. |
| 6072 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6073 | if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6074 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 6075 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 6076 | } |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6077 | |
| 6078 | return true; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6079 | |
| 6080 | fail: |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6081 | drm_connector_cleanup(connector); |
| 6082 | |
| 6083 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6084 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6085 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6086 | bool intel_dp_init(struct drm_i915_private *dev_priv, |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6087 | i915_reg_t output_reg, |
| 6088 | enum port port) |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6089 | { |
| 6090 | struct intel_digital_port *intel_dig_port; |
| 6091 | struct intel_encoder *intel_encoder; |
| 6092 | struct drm_encoder *encoder; |
| 6093 | struct intel_connector *intel_connector; |
| 6094 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 6095 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6096 | if (!intel_dig_port) |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6097 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6098 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6099 | intel_connector = intel_connector_alloc(); |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6100 | if (!intel_connector) |
| 6101 | goto err_connector_alloc; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6102 | |
| 6103 | intel_encoder = &intel_dig_port->base; |
| 6104 | encoder = &intel_encoder->base; |
| 6105 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6106 | if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, |
| 6107 | &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, |
| 6108 | "DP %c", port_name(port))) |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6109 | goto err_encoder_init; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6110 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 6111 | intel_encoder->compute_config = intel_dp_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6112 | intel_encoder->disable = intel_disable_dp; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6113 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 6114 | intel_encoder->get_config = intel_dp_get_config; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 6115 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6116 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 6117 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 6118 | intel_encoder->pre_enable = chv_pre_enable_dp; |
| 6119 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 6120 | intel_encoder->post_disable = chv_post_disable_dp; |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6121 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6122 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6123 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6124 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
| 6125 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 6126 | intel_encoder->post_disable = vlv_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6127 | } else { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6128 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6129 | intel_encoder->enable = g4x_enable_dp; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6130 | if (INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 6131 | intel_encoder->post_disable = ilk_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6132 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6133 | |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 6134 | intel_dig_port->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6135 | intel_dig_port->dp.output_reg = output_reg; |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6136 | intel_dig_port->max_lanes = 4; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6137 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 6138 | intel_encoder->type = INTEL_OUTPUT_DP; |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6139 | intel_encoder->power_domain = intel_port_to_power_domain(port); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6140 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 882ec38 | 2014-04-28 14:07:43 +0300 | [diff] [blame] | 6141 | if (port == PORT_D) |
| 6142 | intel_encoder->crtc_mask = 1 << 2; |
| 6143 | else |
| 6144 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
| 6145 | } else { |
| 6146 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 6147 | } |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 6148 | intel_encoder->cloneable = 0; |
Pandiyan, Dhinakaran | 03cdc1d | 2016-09-19 18:24:38 -0700 | [diff] [blame] | 6149 | intel_encoder->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6150 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6151 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6152 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6153 | |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6154 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
| 6155 | goto err_init_connector; |
| 6156 | |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6157 | return true; |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6158 | |
| 6159 | err_init_connector: |
| 6160 | drm_encoder_cleanup(encoder); |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6161 | err_encoder_init: |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6162 | kfree(intel_connector); |
| 6163 | err_connector_alloc: |
| 6164 | kfree(intel_dig_port); |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6165 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6166 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6167 | |
| 6168 | void intel_dp_mst_suspend(struct drm_device *dev) |
| 6169 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6170 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6171 | int i; |
| 6172 | |
| 6173 | /* disable MST */ |
| 6174 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6175 | 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] | 6176 | |
| 6177 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6178 | continue; |
| 6179 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6180 | if (intel_dig_port->dp.is_mst) |
| 6181 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | void intel_dp_mst_resume(struct drm_device *dev) |
| 6186 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6187 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6188 | int i; |
| 6189 | |
| 6190 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6191 | 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] | 6192 | int ret; |
| 6193 | |
| 6194 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6195 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6196 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6197 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); |
| 6198 | if (ret) |
| 6199 | intel_dp_check_mst_status(&intel_dig_port->dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6200 | } |
| 6201 | } |