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> |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 39 | #include <drm/drm_dp_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 40 | #include <drm/drm_edid.h> |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 41 | #include <drm/drm_hdcp.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 42 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 43 | #include <drm/i915_drm.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 44 | #include "i915_drv.h" |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 45 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 46 | #define DP_LINK_CHECK_TIMEOUT (10 * 1000) |
Pandiyan, Dhinakaran | e8b2577 | 2017-09-18 15:21:39 -0700 | [diff] [blame] | 47 | #define DP_DPRX_ESI_LEN 14 |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 48 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 49 | /* Compliance test status bits */ |
| 50 | #define INTEL_DP_RESOLUTION_SHIFT_MASK 0 |
| 51 | #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 52 | #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 53 | #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 54 | |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 55 | struct dp_link_dpll { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 56 | int clock; |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 57 | struct dpll dpll; |
| 58 | }; |
| 59 | |
| 60 | static const struct dp_link_dpll gen4_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 61 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 62 | { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 63 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 64 | { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } } |
| 65 | }; |
| 66 | |
| 67 | static const struct dp_link_dpll pch_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 68 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 69 | { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 70 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 71 | { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } } |
| 72 | }; |
| 73 | |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 74 | static const struct dp_link_dpll vlv_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 75 | { 162000, |
Chon Ming Lee | 58f6e63 | 2013-09-25 15:47:51 +0800 | [diff] [blame] | 76 | { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 77 | { 270000, |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 78 | { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } } |
| 79 | }; |
| 80 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 81 | /* |
| 82 | * CHV supports eDP 1.4 that have more link rates. |
| 83 | * Below only provides the fixed rate but exclude variable rate. |
| 84 | */ |
| 85 | static const struct dp_link_dpll chv_dpll[] = { |
| 86 | /* |
| 87 | * CHV requires to program fractional division for m2. |
| 88 | * m2 is stored in fixed point format using formula below |
| 89 | * (m2_int << 22) | m2_fraction |
| 90 | */ |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 91 | { 162000, /* m2_int = 32, m2_fraction = 1677722 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 92 | { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 93 | { 270000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 94 | { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 95 | { 540000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 96 | { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } } |
| 97 | }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 98 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 99 | /** |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 100 | * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH) |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 101 | * @intel_dp: DP struct |
| 102 | * |
| 103 | * If a CPU or PCH DP output is attached to an eDP panel, this function |
| 104 | * will return true, and false otherwise. |
| 105 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 106 | bool intel_dp_is_edp(struct intel_dp *intel_dp) |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 107 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 108 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 109 | |
| 110 | return intel_dig_port->base.type == INTEL_OUTPUT_EDP; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 113 | 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] | 114 | { |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 115 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 116 | |
| 117 | return intel_dig_port->base.base.dev; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 120 | static struct intel_dp *intel_attached_dp(struct drm_connector *connector) |
| 121 | { |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 122 | return enc_to_intel_dp(&intel_attached_encoder(connector)->base); |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 125 | static void intel_dp_link_down(struct intel_encoder *encoder, |
| 126 | const struct intel_crtc_state *old_crtc_state); |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 127 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 128 | static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 129 | static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder, |
| 130 | const struct intel_crtc_state *crtc_state); |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 131 | static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv, |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 132 | enum pipe pipe); |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 133 | static void intel_dp_unset_edid(struct intel_dp *intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 134 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 135 | /* update sink rates from dpcd */ |
| 136 | static void intel_dp_set_sink_rates(struct intel_dp *intel_dp) |
| 137 | { |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 138 | static const int dp_rates[] = { |
Manasi Navare | c71b53c | 2018-02-28 14:31:50 -0800 | [diff] [blame] | 139 | 162000, 270000, 540000, 810000 |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 140 | }; |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 141 | int i, max_rate; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 142 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 143 | max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]); |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 144 | |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 145 | for (i = 0; i < ARRAY_SIZE(dp_rates); i++) { |
| 146 | if (dp_rates[i] > max_rate) |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 147 | break; |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 148 | intel_dp->sink_rates[i] = dp_rates[i]; |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 149 | } |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 150 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 151 | intel_dp->num_sink_rates = i; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 152 | } |
| 153 | |
Jani Nikula | 10ebb73 | 2018-02-01 13:03:41 +0200 | [diff] [blame] | 154 | /* Get length of rates array potentially limited by max_rate. */ |
| 155 | static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate) |
| 156 | { |
| 157 | int i; |
| 158 | |
| 159 | /* Limit results by potentially reduced max rate */ |
| 160 | for (i = 0; i < len; i++) { |
| 161 | if (rates[len - i - 1] <= max_rate) |
| 162 | return len - i; |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | /* Get length of common rates array potentially limited by max_rate. */ |
| 169 | static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp, |
| 170 | int max_rate) |
| 171 | { |
| 172 | return intel_dp_rate_limit_len(intel_dp->common_rates, |
| 173 | intel_dp->num_common_rates, max_rate); |
| 174 | } |
| 175 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 176 | /* Theoretical max between source and sink */ |
| 177 | static int intel_dp_max_common_rate(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 178 | { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 179 | return intel_dp->common_rates[intel_dp->num_common_rates - 1]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 182 | /* Theoretical max between source and sink */ |
| 183 | static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp) |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 184 | { |
| 185 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 186 | int source_max = intel_dig_port->max_lanes; |
| 187 | int sink_max = drm_dp_max_lane_count(intel_dp->dpcd); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 188 | |
| 189 | return min(source_max, sink_max); |
| 190 | } |
| 191 | |
Jani Nikula | 3d65a73 | 2017-04-06 16:44:14 +0300 | [diff] [blame] | 192 | int intel_dp_max_lane_count(struct intel_dp *intel_dp) |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 193 | { |
| 194 | return intel_dp->max_link_lane_count; |
| 195 | } |
| 196 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 197 | int |
Keith Packard | c898261 | 2012-01-25 08:16:25 -0800 | [diff] [blame] | 198 | intel_dp_link_required(int pixel_clock, int bpp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 199 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 200 | /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */ |
| 201 | return DIV_ROUND_UP(pixel_clock * bpp, 8); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 204 | int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 205 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 206 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 207 | /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the |
| 208 | * link rate that is generally expressed in Gbps. Since, 8 bits of data |
| 209 | * is transmitted every LS_Clk per lane, there is no need to account for |
| 210 | * the channel encoding that is done in the PHY layer here. |
| 211 | */ |
| 212 | |
| 213 | return max_link_clock * max_lanes; |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 214 | } |
| 215 | |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 216 | static int |
| 217 | intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp) |
| 218 | { |
| 219 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 220 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 221 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 222 | int max_dotclk = dev_priv->max_dotclk_freq; |
| 223 | int ds_max_dotclk; |
| 224 | |
| 225 | int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 226 | |
| 227 | if (type != DP_DS_PORT_TYPE_VGA) |
| 228 | return max_dotclk; |
| 229 | |
| 230 | ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd, |
| 231 | intel_dp->downstream_ports); |
| 232 | |
| 233 | if (ds_max_dotclk != 0) |
| 234 | max_dotclk = min(max_dotclk, ds_max_dotclk); |
| 235 | |
| 236 | return max_dotclk; |
| 237 | } |
| 238 | |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 239 | static int cnl_max_source_rate(struct intel_dp *intel_dp) |
Rodrigo Vivi | 53ddb3c | 2018-01-29 15:22:23 -0800 | [diff] [blame] | 240 | { |
| 241 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 242 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 243 | enum port port = dig_port->base.port; |
| 244 | |
| 245 | u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; |
| 246 | |
| 247 | /* Low voltage SKUs are limited to max of 5.4G */ |
| 248 | if (voltage == VOLTAGE_INFO_0_85V) |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 249 | return 540000; |
Rodrigo Vivi | 53ddb3c | 2018-01-29 15:22:23 -0800 | [diff] [blame] | 250 | |
| 251 | /* For this SKU 8.1G is supported in all ports */ |
| 252 | if (IS_CNL_WITH_PORT_F(dev_priv)) |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 253 | return 810000; |
Rodrigo Vivi | 53ddb3c | 2018-01-29 15:22:23 -0800 | [diff] [blame] | 254 | |
David Weinehall | 3758d96 | 2018-02-09 15:07:55 +0200 | [diff] [blame] | 255 | /* For other SKUs, max rate on ports A and D is 5.4G */ |
Rodrigo Vivi | 53ddb3c | 2018-01-29 15:22:23 -0800 | [diff] [blame] | 256 | if (port == PORT_A || port == PORT_D) |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 257 | return 540000; |
Rodrigo Vivi | 53ddb3c | 2018-01-29 15:22:23 -0800 | [diff] [blame] | 258 | |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 259 | return 810000; |
Rodrigo Vivi | 53ddb3c | 2018-01-29 15:22:23 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 262 | static void |
| 263 | intel_dp_set_source_rates(struct intel_dp *intel_dp) |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 264 | { |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 265 | /* The values must be in increasing order */ |
| 266 | static const int cnl_rates[] = { |
| 267 | 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000 |
| 268 | }; |
| 269 | static const int bxt_rates[] = { |
| 270 | 162000, 216000, 243000, 270000, 324000, 432000, 540000 |
| 271 | }; |
| 272 | static const int skl_rates[] = { |
| 273 | 162000, 216000, 270000, 324000, 432000, 540000 |
| 274 | }; |
| 275 | static const int hsw_rates[] = { |
| 276 | 162000, 270000, 540000 |
| 277 | }; |
| 278 | static const int g4x_rates[] = { |
| 279 | 162000, 270000 |
| 280 | }; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 281 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 282 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Jani Nikula | 99b91bd | 2018-02-01 13:03:43 +0200 | [diff] [blame] | 283 | const struct ddi_vbt_port_info *info = |
| 284 | &dev_priv->vbt.ddi_port_info[dig_port->base.port]; |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 285 | const int *source_rates; |
Jani Nikula | 99b91bd | 2018-02-01 13:03:43 +0200 | [diff] [blame] | 286 | int size, max_rate = 0, vbt_max_rate = info->dp_max_link_rate; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 287 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 288 | /* This should only be done once */ |
| 289 | WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates); |
| 290 | |
Manasi Navare | ba1c06a | 2018-02-26 19:11:15 -0800 | [diff] [blame] | 291 | if (IS_CANNONLAKE(dev_priv)) { |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 292 | source_rates = cnl_rates; |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 293 | size = ARRAY_SIZE(cnl_rates); |
| 294 | max_rate = cnl_max_source_rate(intel_dp); |
Manasi Navare | ba1c06a | 2018-02-26 19:11:15 -0800 | [diff] [blame] | 295 | } else if (IS_GEN9_LP(dev_priv)) { |
| 296 | source_rates = bxt_rates; |
| 297 | size = ARRAY_SIZE(bxt_rates); |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 298 | } else if (IS_GEN9_BC(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 299 | source_rates = skl_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 300 | size = ARRAY_SIZE(skl_rates); |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 301 | } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) || |
| 302 | IS_BROADWELL(dev_priv)) { |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 303 | source_rates = hsw_rates; |
| 304 | size = ARRAY_SIZE(hsw_rates); |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 305 | } else { |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 306 | source_rates = g4x_rates; |
| 307 | size = ARRAY_SIZE(g4x_rates); |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Jani Nikula | 99b91bd | 2018-02-01 13:03:43 +0200 | [diff] [blame] | 310 | if (max_rate && vbt_max_rate) |
| 311 | max_rate = min(max_rate, vbt_max_rate); |
| 312 | else if (vbt_max_rate) |
| 313 | max_rate = vbt_max_rate; |
| 314 | |
Jani Nikula | 4ba285d | 2018-02-01 13:03:42 +0200 | [diff] [blame] | 315 | if (max_rate) |
| 316 | size = intel_dp_rate_limit_len(source_rates, size, max_rate); |
| 317 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 318 | intel_dp->source_rates = source_rates; |
| 319 | intel_dp->num_source_rates = size; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static int intersect_rates(const int *source_rates, int source_len, |
| 323 | const int *sink_rates, int sink_len, |
| 324 | int *common_rates) |
| 325 | { |
| 326 | int i = 0, j = 0, k = 0; |
| 327 | |
| 328 | while (i < source_len && j < sink_len) { |
| 329 | if (source_rates[i] == sink_rates[j]) { |
| 330 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
| 331 | return k; |
| 332 | common_rates[k] = source_rates[i]; |
| 333 | ++k; |
| 334 | ++i; |
| 335 | ++j; |
| 336 | } else if (source_rates[i] < sink_rates[j]) { |
| 337 | ++i; |
| 338 | } else { |
| 339 | ++j; |
| 340 | } |
| 341 | } |
| 342 | return k; |
| 343 | } |
| 344 | |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 345 | /* return index of rate in rates array, or -1 if not found */ |
| 346 | static int intel_dp_rate_index(const int *rates, int len, int rate) |
| 347 | { |
| 348 | int i; |
| 349 | |
| 350 | for (i = 0; i < len; i++) |
| 351 | if (rate == rates[i]) |
| 352 | return i; |
| 353 | |
| 354 | return -1; |
| 355 | } |
| 356 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 357 | static void intel_dp_set_common_rates(struct intel_dp *intel_dp) |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 358 | { |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 359 | WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates); |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 360 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 361 | intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates, |
| 362 | intel_dp->num_source_rates, |
| 363 | intel_dp->sink_rates, |
| 364 | intel_dp->num_sink_rates, |
| 365 | intel_dp->common_rates); |
| 366 | |
| 367 | /* Paranoia, there should always be something in common. */ |
| 368 | if (WARN_ON(intel_dp->num_common_rates == 0)) { |
Jani Nikula | 229675d | 2018-02-27 12:59:11 +0200 | [diff] [blame] | 369 | intel_dp->common_rates[0] = 162000; |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 370 | intel_dp->num_common_rates = 1; |
| 371 | } |
| 372 | } |
| 373 | |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 374 | static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate, |
| 375 | uint8_t lane_count) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 376 | { |
| 377 | /* |
| 378 | * FIXME: we need to synchronize the current link parameters with |
| 379 | * hardware readout. Currently fast link training doesn't work on |
| 380 | * boot-up. |
| 381 | */ |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 382 | if (link_rate == 0 || |
| 383 | link_rate > intel_dp->max_link_rate) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 384 | return false; |
| 385 | |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 386 | if (lane_count == 0 || |
| 387 | lane_count > intel_dp_max_lane_count(intel_dp)) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 388 | return false; |
| 389 | |
| 390 | return true; |
| 391 | } |
| 392 | |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 393 | int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, |
| 394 | int link_rate, uint8_t lane_count) |
| 395 | { |
Jani Nikula | b1810a7 | 2017-04-06 16:44:11 +0300 | [diff] [blame] | 396 | int index; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 397 | |
Jani Nikula | b1810a7 | 2017-04-06 16:44:11 +0300 | [diff] [blame] | 398 | index = intel_dp_rate_index(intel_dp->common_rates, |
| 399 | intel_dp->num_common_rates, |
| 400 | link_rate); |
| 401 | if (index > 0) { |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 402 | intel_dp->max_link_rate = intel_dp->common_rates[index - 1]; |
| 403 | intel_dp->max_link_lane_count = lane_count; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 404 | } else if (lane_count > 1) { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 405 | intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp); |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 406 | intel_dp->max_link_lane_count = lane_count >> 1; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 407 | } else { |
| 408 | DRM_ERROR("Link Training Unsuccessful\n"); |
| 409 | return -1; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 415 | static enum drm_mode_status |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 416 | intel_dp_mode_valid(struct drm_connector *connector, |
| 417 | struct drm_display_mode *mode) |
| 418 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 419 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 420 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 421 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 422 | int target_clock = mode->clock; |
| 423 | int max_rate, mode_rate, max_lanes, max_link_clock; |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 424 | int max_dotclk; |
| 425 | |
| 426 | max_dotclk = intel_dp_downstream_max_dotclock(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 427 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 428 | if (intel_dp_is_edp(intel_dp) && fixed_mode) { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 429 | if (mode->hdisplay > fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 430 | return MODE_PANEL; |
| 431 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 432 | if (mode->vdisplay > fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 433 | return MODE_PANEL; |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 434 | |
| 435 | target_clock = fixed_mode->clock; |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 438 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 439 | max_lanes = intel_dp_max_lane_count(intel_dp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 440 | |
| 441 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); |
| 442 | mode_rate = intel_dp_link_required(target_clock, 18); |
| 443 | |
Mika Kahola | 799487f | 2016-02-02 15:16:38 +0200 | [diff] [blame] | 444 | if (mode_rate > max_rate || target_clock > max_dotclk) |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 445 | return MODE_CLOCK_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 446 | |
| 447 | if (mode->clock < 10000) |
| 448 | return MODE_CLOCK_LOW; |
| 449 | |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 450 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 451 | return MODE_H_ILLEGAL; |
| 452 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 453 | return MODE_OK; |
| 454 | } |
| 455 | |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 456 | 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] | 457 | { |
| 458 | int i; |
| 459 | uint32_t v = 0; |
| 460 | |
| 461 | if (src_bytes > 4) |
| 462 | src_bytes = 4; |
| 463 | for (i = 0; i < src_bytes; i++) |
| 464 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 465 | return v; |
| 466 | } |
| 467 | |
Damien Lespiau | c2af70e | 2015-02-10 19:32:23 +0000 | [diff] [blame] | 468 | 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] | 469 | { |
| 470 | int i; |
| 471 | if (dst_bytes > 4) |
| 472 | dst_bytes = 4; |
| 473 | for (i = 0; i < dst_bytes; i++) |
| 474 | dst[i] = src >> ((3-i) * 8); |
| 475 | } |
| 476 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 477 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 478 | intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 479 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 480 | intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 481 | bool force_disable_vdd); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 482 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 483 | intel_dp_pps_init(struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 484 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 485 | static void pps_lock(struct intel_dp *intel_dp) |
| 486 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 487 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 488 | |
| 489 | /* |
Lucas De Marchi | 40c7ae4 | 2017-11-13 16:46:38 -0800 | [diff] [blame] | 490 | * See intel_power_sequencer_reset() why we need |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 491 | * a power domain reference here. |
| 492 | */ |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 493 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 494 | |
| 495 | mutex_lock(&dev_priv->pps_mutex); |
| 496 | } |
| 497 | |
| 498 | static void pps_unlock(struct intel_dp *intel_dp) |
| 499 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 500 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 501 | |
| 502 | mutex_unlock(&dev_priv->pps_mutex); |
| 503 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 504 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 505 | } |
| 506 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 507 | static void |
| 508 | vlv_power_sequencer_kick(struct intel_dp *intel_dp) |
| 509 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 510 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 511 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 512 | enum pipe pipe = intel_dp->pps_pipe; |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 513 | bool pll_enabled, release_cl_override = false; |
| 514 | enum dpio_phy phy = DPIO_PHY(pipe); |
| 515 | enum dpio_channel ch = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 516 | uint32_t DP; |
| 517 | |
| 518 | if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN, |
| 519 | "skipping pipe %c power seqeuncer kick due to port %c being active\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 520 | pipe_name(pipe), port_name(intel_dig_port->base.port))) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 521 | return; |
| 522 | |
| 523 | DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 524 | pipe_name(pipe), port_name(intel_dig_port->base.port)); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 525 | |
| 526 | /* Preserve the BIOS-computed detected bit. This is |
| 527 | * supposed to be read-only. |
| 528 | */ |
| 529 | DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
| 530 | DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
| 531 | DP |= DP_PORT_WIDTH(1); |
| 532 | DP |= DP_LINK_TRAIN_PAT_1; |
| 533 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 534 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 535 | DP |= DP_PIPE_SELECT_CHV(pipe); |
| 536 | else if (pipe == PIPE_B) |
| 537 | DP |= DP_PIPEB_SELECT; |
| 538 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 539 | pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE; |
| 540 | |
| 541 | /* |
| 542 | * The DPLL for the pipe must be enabled for this to work. |
| 543 | * So enable temporarily it if it's not already enabled. |
| 544 | */ |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 545 | if (!pll_enabled) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 546 | release_cl_override = IS_CHERRYVIEW(dev_priv) && |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 547 | !chv_phy_powergate_ch(dev_priv, phy, ch, true); |
| 548 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 549 | if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ? |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 550 | &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) { |
| 551 | DRM_ERROR("Failed to force on pll for pipe %c!\n", |
| 552 | pipe_name(pipe)); |
| 553 | return; |
| 554 | } |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 555 | } |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 556 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 557 | /* |
| 558 | * Similar magic as in intel_dp_enable_port(). |
| 559 | * We _must_ do this port enable + disable trick |
| 560 | * to make this power seqeuencer lock onto the port. |
| 561 | * Otherwise even VDD force bit won't work. |
| 562 | */ |
| 563 | I915_WRITE(intel_dp->output_reg, DP); |
| 564 | POSTING_READ(intel_dp->output_reg); |
| 565 | |
| 566 | I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN); |
| 567 | POSTING_READ(intel_dp->output_reg); |
| 568 | |
| 569 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
| 570 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 571 | |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 572 | if (!pll_enabled) { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 573 | vlv_force_pll_off(dev_priv, pipe); |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 574 | |
| 575 | if (release_cl_override) |
| 576 | chv_phy_powergate_ch(dev_priv, phy, ch, false); |
| 577 | } |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 578 | } |
| 579 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 580 | static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv) |
| 581 | { |
| 582 | struct intel_encoder *encoder; |
| 583 | unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); |
| 584 | |
| 585 | /* |
| 586 | * We don't have power sequencer currently. |
| 587 | * Pick one that's not used by other ports. |
| 588 | */ |
| 589 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 590 | struct intel_dp *intel_dp; |
| 591 | |
| 592 | if (encoder->type != INTEL_OUTPUT_DP && |
| 593 | encoder->type != INTEL_OUTPUT_EDP) |
| 594 | continue; |
| 595 | |
| 596 | intel_dp = enc_to_intel_dp(&encoder->base); |
| 597 | |
| 598 | if (encoder->type == INTEL_OUTPUT_EDP) { |
| 599 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 600 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 601 | |
| 602 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 603 | pipes &= ~(1 << intel_dp->pps_pipe); |
| 604 | } else { |
| 605 | WARN_ON(intel_dp->pps_pipe != INVALID_PIPE); |
| 606 | |
| 607 | if (intel_dp->active_pipe != INVALID_PIPE) |
| 608 | pipes &= ~(1 << intel_dp->active_pipe); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (pipes == 0) |
| 613 | return INVALID_PIPE; |
| 614 | |
| 615 | return ffs(pipes) - 1; |
| 616 | } |
| 617 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 618 | static enum pipe |
| 619 | vlv_power_sequencer_pipe(struct intel_dp *intel_dp) |
| 620 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 621 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 622 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 623 | enum pipe pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 624 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 625 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 626 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 627 | /* We should never land here with regular DP ports */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 628 | WARN_ON(!intel_dp_is_edp(intel_dp)); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 629 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 630 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 631 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 632 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 633 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 634 | return intel_dp->pps_pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 635 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 636 | pipe = vlv_find_free_pps(dev_priv); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 637 | |
| 638 | /* |
| 639 | * Didn't find one. This should not happen since there |
| 640 | * are two power sequencers and up to two eDP ports. |
| 641 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 642 | if (WARN_ON(pipe == INVALID_PIPE)) |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 643 | pipe = PIPE_A; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 644 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 645 | vlv_steal_power_sequencer(dev_priv, pipe); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 646 | intel_dp->pps_pipe = pipe; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 647 | |
| 648 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", |
| 649 | pipe_name(intel_dp->pps_pipe), |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 650 | port_name(intel_dig_port->base.port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 651 | |
| 652 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 653 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 654 | intel_dp_init_panel_power_sequencer_registers(intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 655 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 656 | /* |
| 657 | * Even vdd force doesn't work until we've made |
| 658 | * the power sequencer lock in on the port. |
| 659 | */ |
| 660 | vlv_power_sequencer_kick(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 661 | |
| 662 | return intel_dp->pps_pipe; |
| 663 | } |
| 664 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 665 | static int |
| 666 | bxt_power_sequencer_idx(struct intel_dp *intel_dp) |
| 667 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 668 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Mustamin B Mustaffa | 73c0fca | 2018-02-27 11:07:34 +0800 | [diff] [blame] | 669 | int backlight_controller = dev_priv->vbt.backlight.controller; |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 670 | |
| 671 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 672 | |
| 673 | /* We should never land here with regular DP ports */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 674 | WARN_ON(!intel_dp_is_edp(intel_dp)); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 675 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 676 | if (!intel_dp->pps_reset) |
Mustamin B Mustaffa | 73c0fca | 2018-02-27 11:07:34 +0800 | [diff] [blame] | 677 | return backlight_controller; |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 678 | |
| 679 | intel_dp->pps_reset = false; |
| 680 | |
| 681 | /* |
| 682 | * Only the HW needs to be reprogrammed, the SW state is fixed and |
| 683 | * has been setup during connector init. |
| 684 | */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 685 | intel_dp_init_panel_power_sequencer_registers(intel_dp, false); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 686 | |
Mustamin B Mustaffa | 73c0fca | 2018-02-27 11:07:34 +0800 | [diff] [blame] | 687 | return backlight_controller; |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 688 | } |
| 689 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 690 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
| 691 | enum pipe pipe); |
| 692 | |
| 693 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, |
| 694 | enum pipe pipe) |
| 695 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 696 | return I915_READ(PP_STATUS(pipe)) & PP_ON; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, |
| 700 | enum pipe pipe) |
| 701 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 702 | return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, |
| 706 | enum pipe pipe) |
| 707 | { |
| 708 | return true; |
| 709 | } |
| 710 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 711 | static enum pipe |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 712 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
| 713 | enum port port, |
| 714 | vlv_pipe_check pipe_check) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 715 | { |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 716 | enum pipe pipe; |
| 717 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 718 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 719 | u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) & |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 720 | PANEL_PORT_SELECT_MASK; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 721 | |
| 722 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) |
| 723 | continue; |
| 724 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 725 | if (!pipe_check(dev_priv, pipe)) |
| 726 | continue; |
| 727 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 728 | return pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 729 | } |
| 730 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 731 | return INVALID_PIPE; |
| 732 | } |
| 733 | |
| 734 | static void |
| 735 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) |
| 736 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 737 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 738 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 739 | enum port port = intel_dig_port->base.port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 740 | |
| 741 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 742 | |
| 743 | /* try to find a pipe with this port selected */ |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 744 | /* first pick one where the panel is on */ |
| 745 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 746 | vlv_pipe_has_pp_on); |
| 747 | /* didn't find one? pick one where vdd is on */ |
| 748 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 749 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 750 | vlv_pipe_has_vdd_on); |
| 751 | /* didn't find one? pick one with just the correct port */ |
| 752 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 753 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 754 | vlv_pipe_any); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 755 | |
| 756 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ |
| 757 | if (intel_dp->pps_pipe == INVALID_PIPE) { |
| 758 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", |
| 759 | port_name(port)); |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
| 764 | port_name(port), pipe_name(intel_dp->pps_pipe)); |
| 765 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 766 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 767 | intel_dp_init_panel_power_sequencer_registers(intel_dp, false); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 768 | } |
| 769 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 770 | void intel_power_sequencer_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 771 | { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 772 | struct intel_encoder *encoder; |
| 773 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 774 | 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] | 775 | !IS_GEN9_LP(dev_priv))) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 776 | return; |
| 777 | |
| 778 | /* |
| 779 | * We can't grab pps_mutex here due to deadlock with power_domain |
| 780 | * mutex when power_domain functions are called while holding pps_mutex. |
| 781 | * That also means that in order to use pps_pipe the code needs to |
| 782 | * hold both a power domain reference and pps_mutex, and the power domain |
| 783 | * reference get/put must be done while _not_ holding pps_mutex. |
| 784 | * pps_{lock,unlock}() do these steps in the correct order, so one |
| 785 | * should use them always. |
| 786 | */ |
| 787 | |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 788 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 789 | struct intel_dp *intel_dp; |
| 790 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 791 | if (encoder->type != INTEL_OUTPUT_DP && |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 792 | encoder->type != INTEL_OUTPUT_EDP && |
| 793 | encoder->type != INTEL_OUTPUT_DDI) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 794 | continue; |
| 795 | |
| 796 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 797 | |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 798 | /* Skip pure DVI/HDMI DDI encoders */ |
| 799 | if (!i915_mmio_reg_valid(intel_dp->output_reg)) |
| 800 | continue; |
| 801 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 802 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 803 | |
| 804 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 805 | continue; |
| 806 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 807 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 808 | intel_dp->pps_reset = true; |
| 809 | else |
| 810 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 811 | } |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 812 | } |
| 813 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 814 | struct pps_registers { |
| 815 | i915_reg_t pp_ctrl; |
| 816 | i915_reg_t pp_stat; |
| 817 | i915_reg_t pp_on; |
| 818 | i915_reg_t pp_off; |
| 819 | i915_reg_t pp_div; |
| 820 | }; |
| 821 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 822 | static void intel_pps_get_registers(struct intel_dp *intel_dp, |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 823 | struct pps_registers *regs) |
| 824 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 825 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 826 | int pps_idx = 0; |
| 827 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 828 | memset(regs, 0, sizeof(*regs)); |
| 829 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 830 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 831 | pps_idx = bxt_power_sequencer_idx(intel_dp); |
| 832 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 833 | pps_idx = vlv_power_sequencer_pipe(intel_dp); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 834 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 835 | regs->pp_ctrl = PP_CONTROL(pps_idx); |
| 836 | regs->pp_stat = PP_STATUS(pps_idx); |
| 837 | regs->pp_on = PP_ON_DELAYS(pps_idx); |
| 838 | regs->pp_off = PP_OFF_DELAYS(pps_idx); |
Anusha Srivatsa | b0d6a0f | 2018-01-11 16:00:07 -0200 | [diff] [blame] | 839 | if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) && |
| 840 | !HAS_PCH_ICP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 841 | regs->pp_div = PP_DIVISOR(pps_idx); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 842 | } |
| 843 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 844 | static i915_reg_t |
| 845 | _pp_ctrl_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 846 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 847 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 848 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 849 | intel_pps_get_registers(intel_dp, ®s); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 850 | |
| 851 | return regs.pp_ctrl; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 852 | } |
| 853 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 854 | static i915_reg_t |
| 855 | _pp_stat_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 856 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 857 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 858 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 859 | intel_pps_get_registers(intel_dp, ®s); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 860 | |
| 861 | return regs.pp_stat; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 862 | } |
| 863 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 864 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
| 865 | This function only applicable when panel PM state is not to be tracked */ |
| 866 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, |
| 867 | void *unused) |
| 868 | { |
| 869 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), |
| 870 | edp_notifier); |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 871 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 872 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 873 | if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART) |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 874 | return 0; |
| 875 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 876 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 877 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 878 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 879 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 880 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 881 | u32 pp_div; |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 882 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 883 | pp_ctrl_reg = PP_CONTROL(pipe); |
| 884 | pp_div_reg = PP_DIVISOR(pipe); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 885 | pp_div = I915_READ(pp_div_reg); |
| 886 | pp_div &= PP_REFERENCE_DIVIDER_MASK; |
| 887 | |
| 888 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ |
| 889 | I915_WRITE(pp_div_reg, pp_div | 0x1F); |
| 890 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 891 | msleep(intel_dp->panel_power_cycle_delay); |
| 892 | } |
| 893 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 894 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 895 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 896 | return 0; |
| 897 | } |
| 898 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 899 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 900 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 901 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 902 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 903 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 904 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 905 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 906 | intel_dp->pps_pipe == INVALID_PIPE) |
| 907 | return false; |
| 908 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 909 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 912 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 913 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 914 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 915 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 916 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 917 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 918 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 919 | intel_dp->pps_pipe == INVALID_PIPE) |
| 920 | return false; |
| 921 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 922 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 925 | static void |
| 926 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 927 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 928 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 929 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 930 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 931 | return; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 932 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 933 | 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] | 934 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 935 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 936 | I915_READ(_pp_stat_reg(intel_dp)), |
| 937 | I915_READ(_pp_ctrl_reg(intel_dp))); |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 941 | static uint32_t |
| 942 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) |
| 943 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 944 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 945 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 946 | uint32_t status; |
| 947 | bool done; |
| 948 | |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 949 | #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] | 950 | if (has_aux_irq) |
Paulo Zanoni | b18ac46 | 2013-02-18 19:00:24 -0300 | [diff] [blame] | 951 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
Imre Deak | 3598706 | 2013-05-21 20:03:20 +0300 | [diff] [blame] | 952 | msecs_to_jiffies_timeout(10)); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 953 | else |
Imre Deak | 713a6b66 | 2016-06-28 13:37:33 +0300 | [diff] [blame] | 954 | done = wait_for(C, 10) == 0; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 955 | if (!done) |
| 956 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", |
| 957 | has_aux_irq); |
| 958 | #undef C |
| 959 | |
| 960 | return status; |
| 961 | } |
| 962 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 963 | 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] | 964 | { |
Ville Syrjälä | 449059a | 2018-02-22 20:10:33 +0200 | [diff] [blame] | 965 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 966 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 967 | if (index) |
| 968 | return 0; |
| 969 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 970 | /* |
| 971 | * 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] | 972 | * 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] | 973 | */ |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 974 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 978 | { |
Ville Syrjälä | 449059a | 2018-02-22 20:10:33 +0200 | [diff] [blame] | 979 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 980 | |
| 981 | if (index) |
| 982 | return 0; |
| 983 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 984 | /* |
| 985 | * The clock divider is based off the cdclk or PCH rawclk, and would |
| 986 | * like to run at 2MHz. So, take the cdclk or PCH rawclk value and |
| 987 | * divide by 2000 and use that |
| 988 | */ |
Ville Syrjälä | 449059a | 2018-02-22 20:10:33 +0200 | [diff] [blame] | 989 | if (intel_dp->aux_ch == AUX_CH_A) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 990 | return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 991 | else |
| 992 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | 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] | 996 | { |
Ville Syrjälä | 449059a | 2018-02-22 20:10:33 +0200 | [diff] [blame] | 997 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 998 | |
Ville Syrjälä | 449059a | 2018-02-22 20:10:33 +0200 | [diff] [blame] | 999 | if (intel_dp->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) { |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 1000 | /* Workaround for non-ULT HSW */ |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1001 | switch (index) { |
| 1002 | case 0: return 63; |
| 1003 | case 1: return 72; |
| 1004 | default: return 0; |
| 1005 | } |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 1006 | } |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 1007 | |
| 1008 | return ilk_get_aux_clock_divider(intel_dp, index); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 1009 | } |
| 1010 | |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 1011 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 1012 | { |
| 1013 | /* |
| 1014 | * SKL doesn't need us to program the AUX clock divider (Hardware will |
| 1015 | * derive the clock from CDCLK automatically). We still implement the |
| 1016 | * get_aux_clock_divider vfunc to plug-in into the existing code. |
| 1017 | */ |
| 1018 | return index ? 0 : 1; |
| 1019 | } |
| 1020 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 1021 | static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 1022 | bool has_aux_irq, |
| 1023 | int send_bytes, |
| 1024 | uint32_t aux_clock_divider) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1025 | { |
| 1026 | 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] | 1027 | struct drm_i915_private *dev_priv = |
| 1028 | to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1029 | uint32_t precharge, timeout; |
| 1030 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 1031 | if (IS_GEN6(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1032 | precharge = 3; |
| 1033 | else |
| 1034 | precharge = 5; |
| 1035 | |
James Ausmus | 8f5f63d | 2017-10-12 14:30:37 -0700 | [diff] [blame] | 1036 | if (IS_BROADWELL(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1037 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
| 1038 | else |
| 1039 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; |
| 1040 | |
| 1041 | return DP_AUX_CH_CTL_SEND_BUSY | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1042 | DP_AUX_CH_CTL_DONE | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1043 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1044 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1045 | timeout | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1046 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1047 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 1048 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1049 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1052 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 1053 | bool has_aux_irq, |
| 1054 | int send_bytes, |
| 1055 | uint32_t unused) |
| 1056 | { |
| 1057 | return DP_AUX_CH_CTL_SEND_BUSY | |
| 1058 | DP_AUX_CH_CTL_DONE | |
| 1059 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
| 1060 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
James Ausmus | 6fa228b | 2017-10-12 14:30:36 -0700 | [diff] [blame] | 1061 | DP_AUX_CH_CTL_TIME_OUT_MAX | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1062 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
| 1063 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 1064 | DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1065 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); |
| 1066 | } |
| 1067 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1068 | static int |
Ville Syrjälä | f760626 | 2018-02-22 20:10:34 +0200 | [diff] [blame] | 1069 | intel_dp_aux_xfer(struct intel_dp *intel_dp, |
| 1070 | const uint8_t *send, int send_bytes, |
Ville Syrjälä | 8159c79 | 2018-02-22 23:27:32 +0200 | [diff] [blame] | 1071 | uint8_t *recv, int recv_size, |
| 1072 | u32 aux_send_ctl_flags) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1073 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1074 | 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] | 1075 | struct drm_i915_private *dev_priv = |
| 1076 | to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1077 | i915_reg_t ch_ctl, ch_data[5]; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1078 | uint32_t aux_clock_divider; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1079 | int i, ret, recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1080 | uint32_t status; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1081 | int try, clock = 0; |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 1082 | bool has_aux_irq = HAS_AUX_IRQ(dev_priv); |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1083 | bool vdd; |
| 1084 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1085 | ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp); |
| 1086 | for (i = 0; i < ARRAY_SIZE(ch_data); i++) |
| 1087 | ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i); |
| 1088 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1089 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1090 | |
Ville Syrjälä | 72c3500 | 2014-08-18 22:16:00 +0300 | [diff] [blame] | 1091 | /* |
| 1092 | * We will be called with VDD already enabled for dpcd/edid/oui reads. |
| 1093 | * In such cases we want to leave VDD enabled and it's up to upper layers |
| 1094 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off |
| 1095 | * ourselves. |
| 1096 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 1097 | vdd = edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1098 | |
| 1099 | /* dp aux is extremely sensitive to irq latency, hence request the |
| 1100 | * lowest possible wakeup latency and so prevent the cpu from going into |
| 1101 | * deep sleep states. |
| 1102 | */ |
| 1103 | pm_qos_update_request(&dev_priv->pm_qos, 0); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1104 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 1105 | intel_dp_check_edp(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1106 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1107 | /* Try to wait for any previous AUX channel activity */ |
| 1108 | for (try = 0; try < 3; try++) { |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 1109 | status = I915_READ_NOTRACE(ch_ctl); |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1110 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 1111 | break; |
| 1112 | msleep(1); |
| 1113 | } |
| 1114 | |
| 1115 | if (try == 3) { |
Mika Kuoppala | 02196c7 | 2015-08-06 16:48:58 +0300 | [diff] [blame] | 1116 | static u32 last_status = -1; |
| 1117 | const u32 status = I915_READ(ch_ctl); |
| 1118 | |
| 1119 | if (status != last_status) { |
| 1120 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 1121 | status); |
| 1122 | last_status = status; |
| 1123 | } |
| 1124 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1125 | ret = -EBUSY; |
| 1126 | goto out; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1129 | /* Only 5 data registers! */ |
| 1130 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { |
| 1131 | ret = -E2BIG; |
| 1132 | goto out; |
| 1133 | } |
| 1134 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 1135 | while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) { |
Ville Syrjälä | 8159c79 | 2018-02-22 23:27:32 +0200 | [diff] [blame] | 1136 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
| 1137 | has_aux_irq, |
| 1138 | send_bytes, |
| 1139 | aux_clock_divider); |
| 1140 | |
| 1141 | send_ctl |= aux_send_ctl_flags; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1142 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1143 | /* Must try at least 3 times according to DP spec */ |
| 1144 | for (try = 0; try < 5; try++) { |
| 1145 | /* Load the send data into the aux channel data registers */ |
| 1146 | for (i = 0; i < send_bytes; i += 4) |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1147 | I915_WRITE(ch_data[i >> 2], |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1148 | intel_dp_pack_aux(send + i, |
| 1149 | send_bytes - i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1150 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1151 | /* Send the command and wait for it to complete */ |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1152 | I915_WRITE(ch_ctl, send_ctl); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1153 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1154 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1155 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1156 | /* Clear done status and any errors */ |
| 1157 | I915_WRITE(ch_ctl, |
| 1158 | status | |
| 1159 | DP_AUX_CH_CTL_DONE | |
| 1160 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1161 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Adam Jackson | d7e96fe | 2011-07-26 15:39:46 -0400 | [diff] [blame] | 1162 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1163 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 |
| 1164 | * 400us delay required for errors and timeouts |
| 1165 | * Timeout errors from the HW already meet this |
| 1166 | * requirement so skip to next iteration |
| 1167 | */ |
Dhinakaran Pandiyan | 3975f0a | 2018-02-23 14:15:20 -0800 | [diff] [blame] | 1168 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
| 1169 | continue; |
| 1170 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1171 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
| 1172 | usleep_range(400, 500); |
| 1173 | continue; |
| 1174 | } |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1175 | if (status & DP_AUX_CH_CTL_DONE) |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1176 | goto done; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1177 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1180 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1181 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1182 | ret = -EBUSY; |
| 1183 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1186 | done: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1187 | /* Check for timeout or receive error. |
| 1188 | * Timeouts occur when the sink is not connected |
| 1189 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1190 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1191 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1192 | ret = -EIO; |
| 1193 | goto out; |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1194 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1195 | |
| 1196 | /* Timeouts occur when the device isn't connected, so they're |
| 1197 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1198 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Chris Wilson | a5570fe | 2017-02-23 11:51:02 +0000 | [diff] [blame] | 1199 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1200 | ret = -ETIMEDOUT; |
| 1201 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /* Unload any bytes sent back from the other side */ |
| 1205 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 1206 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1207 | |
| 1208 | /* |
| 1209 | * By BSpec: "Message sizes of 0 or >20 are not allowed." |
| 1210 | * We have no idea of what happened so we return -EBUSY so |
| 1211 | * drm layer takes care for the necessary retries. |
| 1212 | */ |
| 1213 | if (recv_bytes == 0 || recv_bytes > 20) { |
| 1214 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", |
| 1215 | recv_bytes); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1216 | ret = -EBUSY; |
| 1217 | goto out; |
| 1218 | } |
| 1219 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1220 | if (recv_bytes > recv_size) |
| 1221 | recv_bytes = recv_size; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1222 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1223 | for (i = 0; i < recv_bytes; i += 4) |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1224 | intel_dp_unpack_aux(I915_READ(ch_data[i >> 2]), |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1225 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1226 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1227 | ret = recv_bytes; |
| 1228 | out: |
| 1229 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); |
| 1230 | |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1231 | if (vdd) |
| 1232 | edp_panel_vdd_off(intel_dp, false); |
| 1233 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1234 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1235 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1236 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1239 | #define BARE_ADDRESS_SIZE 3 |
| 1240 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) |
Ville Syrjälä | 32078b72 | 2018-02-22 23:28:02 +0200 | [diff] [blame] | 1241 | |
| 1242 | static void |
| 1243 | intel_dp_aux_header(u8 txbuf[HEADER_SIZE], |
| 1244 | const struct drm_dp_aux_msg *msg) |
| 1245 | { |
| 1246 | txbuf[0] = (msg->request << 4) | ((msg->address >> 16) & 0xf); |
| 1247 | txbuf[1] = (msg->address >> 8) & 0xff; |
| 1248 | txbuf[2] = msg->address & 0xff; |
| 1249 | txbuf[3] = msg->size - 1; |
| 1250 | } |
| 1251 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1252 | static ssize_t |
| 1253 | 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] | 1254 | { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1255 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
| 1256 | uint8_t txbuf[20], rxbuf[20]; |
| 1257 | size_t txsize, rxsize; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1258 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1259 | |
Ville Syrjälä | 32078b72 | 2018-02-22 23:28:02 +0200 | [diff] [blame] | 1260 | intel_dp_aux_header(txbuf, msg); |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1261 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1262 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
| 1263 | case DP_AUX_NATIVE_WRITE: |
| 1264 | case DP_AUX_I2C_WRITE: |
Ville Syrjälä | c1e74122 | 2015-08-27 17:23:27 +0300 | [diff] [blame] | 1265 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1266 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1267 | rxsize = 2; /* 0 or 1 data bytes */ |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1268 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1269 | if (WARN_ON(txsize > 20)) |
| 1270 | return -E2BIG; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1271 | |
Ville Syrjälä | dd78809 | 2016-07-28 17:55:04 +0300 | [diff] [blame] | 1272 | WARN_ON(!msg->buffer != !msg->size); |
| 1273 | |
Imre Deak | d81a67c | 2016-01-29 14:52:26 +0200 | [diff] [blame] | 1274 | if (msg->buffer) |
| 1275 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1276 | |
Ville Syrjälä | f760626 | 2018-02-22 20:10:34 +0200 | [diff] [blame] | 1277 | ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize, |
Ville Syrjälä | 8159c79 | 2018-02-22 23:27:32 +0200 | [diff] [blame] | 1278 | rxbuf, rxsize, 0); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1279 | if (ret > 0) { |
| 1280 | msg->reply = rxbuf[0] >> 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1281 | |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1282 | if (ret > 1) { |
| 1283 | /* Number of bytes written in a short write. */ |
| 1284 | ret = clamp_t(int, rxbuf[1], 0, msg->size); |
| 1285 | } else { |
| 1286 | /* Return payload size. */ |
| 1287 | ret = msg->size; |
| 1288 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1289 | } |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1290 | break; |
| 1291 | |
| 1292 | case DP_AUX_NATIVE_READ: |
| 1293 | case DP_AUX_I2C_READ: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1294 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1295 | rxsize = msg->size + 1; |
| 1296 | |
| 1297 | if (WARN_ON(rxsize > 20)) |
| 1298 | return -E2BIG; |
| 1299 | |
Ville Syrjälä | f760626 | 2018-02-22 20:10:34 +0200 | [diff] [blame] | 1300 | ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize, |
Ville Syrjälä | 8159c79 | 2018-02-22 23:27:32 +0200 | [diff] [blame] | 1301 | rxbuf, rxsize, 0); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1302 | if (ret > 0) { |
| 1303 | msg->reply = rxbuf[0] >> 4; |
| 1304 | /* |
| 1305 | * Assume happy day, and copy the data. The caller is |
| 1306 | * expected to check msg->reply before touching it. |
| 1307 | * |
| 1308 | * Return payload size. |
| 1309 | */ |
| 1310 | ret--; |
| 1311 | memcpy(msg->buffer, rxbuf + 1, ret); |
| 1312 | } |
| 1313 | break; |
| 1314 | |
| 1315 | default: |
| 1316 | ret = -EINVAL; |
| 1317 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1318 | } |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1319 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1320 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1323 | static enum aux_ch intel_aux_ch(struct intel_dp *intel_dp) |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1324 | { |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1325 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 1326 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 1327 | enum port port = encoder->port; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1328 | const struct ddi_vbt_port_info *info = |
| 1329 | &dev_priv->vbt.ddi_port_info[port]; |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1330 | enum aux_ch aux_ch; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1331 | |
| 1332 | if (!info->alternate_aux_channel) { |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1333 | aux_ch = (enum aux_ch) port; |
| 1334 | |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1335 | DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n", |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1336 | aux_ch_name(aux_ch), port_name(port)); |
| 1337 | return aux_ch; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | switch (info->alternate_aux_channel) { |
| 1341 | case DP_AUX_A: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1342 | aux_ch = AUX_CH_A; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1343 | break; |
| 1344 | case DP_AUX_B: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1345 | aux_ch = AUX_CH_B; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1346 | break; |
| 1347 | case DP_AUX_C: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1348 | aux_ch = AUX_CH_C; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1349 | break; |
| 1350 | case DP_AUX_D: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1351 | aux_ch = AUX_CH_D; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1352 | break; |
Rodrigo Vivi | a324fca | 2018-01-29 15:22:15 -0800 | [diff] [blame] | 1353 | case DP_AUX_F: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1354 | aux_ch = AUX_CH_F; |
Rodrigo Vivi | a324fca | 2018-01-29 15:22:15 -0800 | [diff] [blame] | 1355 | break; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1356 | default: |
| 1357 | MISSING_CASE(info->alternate_aux_channel); |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1358 | aux_ch = AUX_CH_A; |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n", |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1363 | aux_ch_name(aux_ch), port_name(port)); |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1364 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1365 | return aux_ch; |
| 1366 | } |
| 1367 | |
| 1368 | static enum intel_display_power_domain |
| 1369 | intel_aux_power_domain(struct intel_dp *intel_dp) |
| 1370 | { |
| 1371 | switch (intel_dp->aux_ch) { |
| 1372 | case AUX_CH_A: |
| 1373 | return POWER_DOMAIN_AUX_A; |
| 1374 | case AUX_CH_B: |
| 1375 | return POWER_DOMAIN_AUX_B; |
| 1376 | case AUX_CH_C: |
| 1377 | return POWER_DOMAIN_AUX_C; |
| 1378 | case AUX_CH_D: |
| 1379 | return POWER_DOMAIN_AUX_D; |
| 1380 | case AUX_CH_F: |
| 1381 | return POWER_DOMAIN_AUX_F; |
| 1382 | default: |
| 1383 | MISSING_CASE(intel_dp->aux_ch); |
| 1384 | return POWER_DOMAIN_AUX_A; |
| 1385 | } |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1386 | } |
| 1387 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1388 | static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1389 | { |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1390 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 1391 | enum aux_ch aux_ch = intel_dp->aux_ch; |
| 1392 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1393 | switch (aux_ch) { |
| 1394 | case AUX_CH_B: |
| 1395 | case AUX_CH_C: |
| 1396 | case AUX_CH_D: |
| 1397 | return DP_AUX_CH_CTL(aux_ch); |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1398 | default: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1399 | MISSING_CASE(aux_ch); |
| 1400 | return DP_AUX_CH_CTL(AUX_CH_B); |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1404 | static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1405 | { |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1406 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 1407 | enum aux_ch aux_ch = intel_dp->aux_ch; |
| 1408 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1409 | switch (aux_ch) { |
| 1410 | case AUX_CH_B: |
| 1411 | case AUX_CH_C: |
| 1412 | case AUX_CH_D: |
| 1413 | return DP_AUX_CH_DATA(aux_ch, index); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1414 | default: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1415 | MISSING_CASE(aux_ch); |
| 1416 | return DP_AUX_CH_DATA(AUX_CH_B, index); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1420 | static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1421 | { |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1422 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 1423 | enum aux_ch aux_ch = intel_dp->aux_ch; |
| 1424 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1425 | switch (aux_ch) { |
| 1426 | case AUX_CH_A: |
| 1427 | return DP_AUX_CH_CTL(aux_ch); |
| 1428 | case AUX_CH_B: |
| 1429 | case AUX_CH_C: |
| 1430 | case AUX_CH_D: |
| 1431 | return PCH_DP_AUX_CH_CTL(aux_ch); |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1432 | default: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1433 | MISSING_CASE(aux_ch); |
| 1434 | return DP_AUX_CH_CTL(AUX_CH_A); |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1438 | static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1439 | { |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1440 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 1441 | enum aux_ch aux_ch = intel_dp->aux_ch; |
| 1442 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1443 | switch (aux_ch) { |
| 1444 | case AUX_CH_A: |
| 1445 | return DP_AUX_CH_DATA(aux_ch, index); |
| 1446 | case AUX_CH_B: |
| 1447 | case AUX_CH_C: |
| 1448 | case AUX_CH_D: |
| 1449 | return PCH_DP_AUX_CH_DATA(aux_ch, index); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1450 | default: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1451 | MISSING_CASE(aux_ch); |
| 1452 | return DP_AUX_CH_DATA(AUX_CH_A, index); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1453 | } |
| 1454 | } |
| 1455 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1456 | static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1457 | { |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1458 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 1459 | enum aux_ch aux_ch = intel_dp->aux_ch; |
| 1460 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1461 | switch (aux_ch) { |
| 1462 | case AUX_CH_A: |
| 1463 | case AUX_CH_B: |
| 1464 | case AUX_CH_C: |
| 1465 | case AUX_CH_D: |
| 1466 | case AUX_CH_F: |
| 1467 | return DP_AUX_CH_CTL(aux_ch); |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1468 | default: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1469 | MISSING_CASE(aux_ch); |
| 1470 | return DP_AUX_CH_CTL(AUX_CH_A); |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1474 | static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1475 | { |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1476 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 1477 | enum aux_ch aux_ch = intel_dp->aux_ch; |
| 1478 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1479 | switch (aux_ch) { |
| 1480 | case AUX_CH_A: |
| 1481 | case AUX_CH_B: |
| 1482 | case AUX_CH_C: |
| 1483 | case AUX_CH_D: |
| 1484 | case AUX_CH_F: |
| 1485 | return DP_AUX_CH_DATA(aux_ch, index); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1486 | default: |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1487 | MISSING_CASE(aux_ch); |
| 1488 | return DP_AUX_CH_DATA(AUX_CH_A, index); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
Ville Syrjälä | 91e939a | 2018-02-22 20:10:32 +0200 | [diff] [blame] | 1492 | static void |
| 1493 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
| 1494 | { |
| 1495 | kfree(intel_dp->aux.name); |
| 1496 | } |
| 1497 | |
| 1498 | static void |
| 1499 | intel_dp_aux_init(struct intel_dp *intel_dp) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1500 | { |
| 1501 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 91e939a | 2018-02-22 20:10:32 +0200 | [diff] [blame] | 1502 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 1503 | |
| 1504 | intel_dp->aux_ch = intel_aux_ch(intel_dp); |
| 1505 | intel_dp->aux_power_domain = intel_aux_power_domain(intel_dp); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1506 | |
Ville Syrjälä | 4904fa6 | 2018-02-22 20:10:31 +0200 | [diff] [blame] | 1507 | if (INTEL_GEN(dev_priv) >= 9) { |
| 1508 | intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg; |
| 1509 | intel_dp->aux_ch_data_reg = skl_aux_data_reg; |
| 1510 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
| 1511 | intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg; |
| 1512 | intel_dp->aux_ch_data_reg = ilk_aux_data_reg; |
| 1513 | } else { |
| 1514 | intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg; |
| 1515 | intel_dp->aux_ch_data_reg = g4x_aux_data_reg; |
| 1516 | } |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1517 | |
Ville Syrjälä | 91e939a | 2018-02-22 20:10:32 +0200 | [diff] [blame] | 1518 | if (INTEL_GEN(dev_priv) >= 9) |
| 1519 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; |
| 1520 | else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 1521 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; |
| 1522 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1523 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; |
| 1524 | else |
| 1525 | intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1526 | |
Ville Syrjälä | 91e939a | 2018-02-22 20:10:32 +0200 | [diff] [blame] | 1527 | if (INTEL_GEN(dev_priv) >= 9) |
| 1528 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; |
| 1529 | else |
| 1530 | intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl; |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1531 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1532 | drm_dp_aux_init(&intel_dp->aux); |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 1533 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1534 | /* Failure to allocate our preferred name is not critical */ |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 1535 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", |
| 1536 | port_name(encoder->port)); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1537 | intel_dp->aux.transfer = intel_dp_aux_transfer; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1540 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1541 | { |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 1542 | int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1]; |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1543 | |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 1544 | return max_rate >= 540000; |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1545 | } |
| 1546 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 1547 | static void |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1548 | intel_dp_set_clock(struct intel_encoder *encoder, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1549 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1550 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 1551 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1552 | const struct dp_link_dpll *divisor = NULL; |
| 1553 | int i, count = 0; |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1554 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 1555 | if (IS_G4X(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1556 | divisor = gen4_dpll; |
| 1557 | count = ARRAY_SIZE(gen4_dpll); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1558 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1559 | divisor = pch_dpll; |
| 1560 | count = ARRAY_SIZE(pch_dpll); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1561 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1562 | divisor = chv_dpll; |
| 1563 | count = ARRAY_SIZE(chv_dpll); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 1564 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 1565 | divisor = vlv_dpll; |
| 1566 | count = ARRAY_SIZE(vlv_dpll); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1567 | } |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1568 | |
| 1569 | if (divisor && count) { |
| 1570 | for (i = 0; i < count; i++) { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1571 | if (pipe_config->port_clock == divisor[i].clock) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1572 | pipe_config->dpll = divisor[i].dpll; |
| 1573 | pipe_config->clock_set = true; |
| 1574 | break; |
| 1575 | } |
| 1576 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1577 | } |
| 1578 | } |
| 1579 | |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1580 | static void snprintf_int_array(char *str, size_t len, |
| 1581 | const int *array, int nelem) |
| 1582 | { |
| 1583 | int i; |
| 1584 | |
| 1585 | str[0] = '\0'; |
| 1586 | |
| 1587 | for (i = 0; i < nelem; i++) { |
Jani Nikula | b2f505b | 2015-05-18 16:01:45 +0300 | [diff] [blame] | 1588 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1589 | if (r >= len) |
| 1590 | return; |
| 1591 | str += r; |
| 1592 | len -= r; |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | static void intel_dp_print_rates(struct intel_dp *intel_dp) |
| 1597 | { |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1598 | char str[128]; /* FIXME: too big for stack? */ |
| 1599 | |
| 1600 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 1601 | return; |
| 1602 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 1603 | snprintf_int_array(str, sizeof(str), |
| 1604 | intel_dp->source_rates, intel_dp->num_source_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1605 | DRM_DEBUG_KMS("source rates: %s\n", str); |
| 1606 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 1607 | snprintf_int_array(str, sizeof(str), |
| 1608 | intel_dp->sink_rates, intel_dp->num_sink_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1609 | DRM_DEBUG_KMS("sink rates: %s\n", str); |
| 1610 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1611 | snprintf_int_array(str, sizeof(str), |
| 1612 | intel_dp->common_rates, intel_dp->num_common_rates); |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1613 | DRM_DEBUG_KMS("common rates: %s\n", str); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1614 | } |
| 1615 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1616 | int |
| 1617 | intel_dp_max_link_rate(struct intel_dp *intel_dp) |
| 1618 | { |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1619 | int len; |
| 1620 | |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 1621 | len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate); |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1622 | if (WARN_ON(len <= 0)) |
| 1623 | return 162000; |
| 1624 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1625 | return intel_dp->common_rates[len - 1]; |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1626 | } |
| 1627 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1628 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
| 1629 | { |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 1630 | int i = intel_dp_rate_index(intel_dp->sink_rates, |
| 1631 | intel_dp->num_sink_rates, rate); |
Jani Nikula | b5c72b2 | 2017-03-28 17:59:02 +0300 | [diff] [blame] | 1632 | |
| 1633 | if (WARN_ON(i < 0)) |
| 1634 | i = 0; |
| 1635 | |
| 1636 | return i; |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1637 | } |
| 1638 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 1639 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
| 1640 | uint8_t *link_bw, uint8_t *rate_select) |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1641 | { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 1642 | /* eDP 1.4 rate select method. */ |
| 1643 | if (intel_dp->use_rate_select) { |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1644 | *link_bw = 0; |
| 1645 | *rate_select = |
| 1646 | intel_dp_rate_select(intel_dp, port_clock); |
| 1647 | } else { |
| 1648 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); |
| 1649 | *rate_select = 0; |
| 1650 | } |
| 1651 | } |
| 1652 | |
Jani Nikula | f580bea | 2016-09-15 16:28:52 +0300 | [diff] [blame] | 1653 | static int intel_dp_compute_bpp(struct intel_dp *intel_dp, |
| 1654 | struct intel_crtc_state *pipe_config) |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1655 | { |
| 1656 | int bpp, bpc; |
| 1657 | |
| 1658 | bpp = pipe_config->pipe_bpp; |
| 1659 | bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports); |
| 1660 | |
| 1661 | if (bpc > 0) |
| 1662 | bpp = min(bpp, 3*bpc); |
| 1663 | |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 1664 | /* For DP Compliance we override the computed bpp for the pipe */ |
| 1665 | if (intel_dp->compliance.test_data.bpc != 0) { |
| 1666 | pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc; |
| 1667 | pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3; |
| 1668 | DRM_DEBUG_KMS("Setting pipe_bpp to %d\n", |
| 1669 | pipe_config->pipe_bpp); |
| 1670 | } |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1671 | return bpp; |
| 1672 | } |
| 1673 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 1674 | static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1, |
| 1675 | struct drm_display_mode *m2) |
| 1676 | { |
| 1677 | bool bres = false; |
| 1678 | |
| 1679 | if (m1 && m2) |
| 1680 | bres = (m1->hdisplay == m2->hdisplay && |
| 1681 | m1->hsync_start == m2->hsync_start && |
| 1682 | m1->hsync_end == m2->hsync_end && |
| 1683 | m1->htotal == m2->htotal && |
| 1684 | m1->vdisplay == m2->vdisplay && |
| 1685 | m1->vsync_start == m2->vsync_start && |
| 1686 | m1->vsync_end == m2->vsync_end && |
| 1687 | m1->vtotal == m2->vtotal); |
| 1688 | return bres; |
| 1689 | } |
| 1690 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1691 | bool |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1692 | intel_dp_compute_config(struct intel_encoder *encoder, |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 1693 | struct intel_crtc_state *pipe_config, |
| 1694 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1695 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1696 | 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] | 1697 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1698 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1699 | enum port port = encoder->port; |
Ander Conselvan de Oliveira | 84556d5 | 2015-03-20 16:18:10 +0200 | [diff] [blame] | 1700 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1701 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1702 | struct intel_digital_connector_state *intel_conn_state = |
| 1703 | to_intel_digital_connector_state(conn_state); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1704 | int lane_count, clock; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1705 | int min_lane_count = 1; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 1706 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
Todd Previte | 06ea66b | 2014-01-20 10:19:39 -0700 | [diff] [blame] | 1707 | /* Conveniently, the link BW constants become indices with a shift...*/ |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1708 | int min_clock = 0; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1709 | int max_clock; |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1710 | int bpp, mode_rate; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1711 | int link_avail, link_clock; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1712 | int common_len; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1713 | uint8_t link_bw, rate_select; |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1714 | bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc, |
| 1715 | DP_DPCD_QUIRK_LIMITED_M_N); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1716 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1717 | common_len = intel_dp_common_len_rate_limit(intel_dp, |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 1718 | intel_dp->max_link_rate); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1719 | |
| 1720 | /* No common link rates between source and sink */ |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1721 | WARN_ON(common_len <= 0); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1722 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1723 | max_clock = common_len - 1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1724 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1725 | 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] | 1726 | pipe_config->has_pch_encoder = true; |
| 1727 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1728 | pipe_config->has_drrs = false; |
Ville Syrjälä | 20ff39f | 2017-11-29 18:43:01 +0200 | [diff] [blame] | 1729 | if (IS_G4X(dev_priv) || port == PORT_A) |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 1730 | pipe_config->has_audio = false; |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1731 | else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO) |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 1732 | pipe_config->has_audio = intel_dp->has_audio; |
| 1733 | else |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1734 | pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1735 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1736 | if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 1737 | struct drm_display_mode *panel_mode = |
| 1738 | intel_connector->panel.alt_fixed_mode; |
| 1739 | struct drm_display_mode *req_mode = &pipe_config->base.mode; |
| 1740 | |
| 1741 | if (!intel_edp_compare_alt_mode(req_mode, panel_mode)) |
| 1742 | panel_mode = intel_connector->panel.fixed_mode; |
| 1743 | |
| 1744 | drm_mode_debug_printmodeline(panel_mode); |
| 1745 | |
| 1746 | intel_fixed_panel_mode(panel_mode, adjusted_mode); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1747 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1748 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1749 | int ret; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 1750 | ret = skl_update_scaler_crtc(pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1751 | if (ret) |
| 1752 | return ret; |
| 1753 | } |
| 1754 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 1755 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1756 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 1757 | conn_state->scaling_mode); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1758 | else |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 1759 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 1760 | conn_state->scaling_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 1761 | } |
| 1762 | |
Ville Syrjälä | 05021389 | 2017-11-29 20:08:47 +0200 | [diff] [blame] | 1763 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
| 1764 | adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1765 | return false; |
| 1766 | |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 1767 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 1768 | return false; |
| 1769 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1770 | /* Use values requested by Compliance Test Request */ |
| 1771 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
Jani Nikula | ec990e2 | 2017-04-06 16:44:15 +0300 | [diff] [blame] | 1772 | int index; |
| 1773 | |
Manasi Navare | 140ef13 | 2017-06-08 13:41:03 -0700 | [diff] [blame] | 1774 | /* Validate the compliance test data since max values |
| 1775 | * might have changed due to link train fallback. |
| 1776 | */ |
| 1777 | if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate, |
| 1778 | intel_dp->compliance.test_lane_count)) { |
| 1779 | index = intel_dp_rate_index(intel_dp->common_rates, |
| 1780 | intel_dp->num_common_rates, |
| 1781 | intel_dp->compliance.test_link_rate); |
| 1782 | if (index >= 0) |
| 1783 | min_clock = max_clock = index; |
| 1784 | min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count; |
| 1785 | } |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1786 | } |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1787 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1788 | "max bw %d pixel clock %iKHz\n", |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1789 | max_lane_count, intel_dp->common_rates[max_clock], |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1790 | adjusted_mode->crtc_clock); |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1791 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1792 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
| 1793 | * bpc in between. */ |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1794 | bpp = intel_dp_compute_bpp(intel_dp, pipe_config); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1795 | if (intel_dp_is_edp(intel_dp)) { |
Thulasimani,Sivakumar | 22ce562 | 2015-07-31 11:05:27 +0530 | [diff] [blame] | 1796 | |
| 1797 | /* Get bpp from vbt only for panels that dont have bpp in edid */ |
| 1798 | if (intel_connector->base.display_info.bpc == 0 && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1799 | (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) { |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1800 | 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] | 1801 | dev_priv->vbt.edp.bpp); |
| 1802 | bpp = dev_priv->vbt.edp.bpp; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1803 | } |
| 1804 | |
Jani Nikula | 344c5bb | 2014-09-09 11:25:13 +0300 | [diff] [blame] | 1805 | /* |
| 1806 | * Use the maximum clock and number of lanes the eDP panel |
| 1807 | * advertizes being capable of. The panels are generally |
| 1808 | * designed to support only a single clock and lane |
| 1809 | * configuration, and typically these values correspond to the |
| 1810 | * native resolution of the panel. |
| 1811 | */ |
| 1812 | min_lane_count = max_lane_count; |
| 1813 | min_clock = max_clock; |
Imre Deak | 7984211 | 2013-07-18 17:44:13 +0300 | [diff] [blame] | 1814 | } |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1815 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1816 | for (; bpp >= 6*3; bpp -= 2*3) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1817 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
| 1818 | bpp); |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1819 | |
Dave Airlie | c693099 | 2014-07-14 11:04:39 +1000 | [diff] [blame] | 1820 | for (clock = min_clock; clock <= max_clock; clock++) { |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1821 | for (lane_count = min_lane_count; |
| 1822 | lane_count <= max_lane_count; |
| 1823 | lane_count <<= 1) { |
| 1824 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1825 | link_clock = intel_dp->common_rates[clock]; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1826 | link_avail = intel_dp_max_data_rate(link_clock, |
| 1827 | lane_count); |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 1828 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1829 | if (mode_rate <= link_avail) { |
| 1830 | goto found; |
| 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | return false; |
| 1837 | |
| 1838 | found: |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1839 | if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) { |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1840 | /* |
| 1841 | * See: |
| 1842 | * CEA-861-E - 5.1 Default Encoding Parameters |
| 1843 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry |
| 1844 | */ |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1845 | pipe_config->limited_color_range = |
Ville Syrjälä | c8127cf0 | 2017-01-11 16:18:35 +0200 | [diff] [blame] | 1846 | bpp != 18 && |
| 1847 | drm_default_rgb_quant_range(adjusted_mode) == |
| 1848 | HDMI_QUANTIZATION_RANGE_LIMITED; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1849 | } else { |
| 1850 | pipe_config->limited_color_range = |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1851 | intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1852 | } |
| 1853 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1854 | pipe_config->lane_count = lane_count; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1855 | |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1856 | pipe_config->pipe_bpp = bpp; |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1857 | pipe_config->port_clock = intel_dp->common_rates[clock]; |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1858 | |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1859 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
| 1860 | &link_bw, &rate_select); |
| 1861 | |
| 1862 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", |
| 1863 | link_bw, rate_select, pipe_config->lane_count, |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1864 | pipe_config->port_clock, bpp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1865 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
| 1866 | mode_rate, link_avail); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1867 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1868 | intel_link_compute_m_n(bpp, lane_count, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1869 | adjusted_mode->crtc_clock, |
| 1870 | pipe_config->port_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1871 | &pipe_config->dp_m_n, |
| 1872 | reduce_m_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1873 | |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1874 | if (intel_connector->panel.downclock_mode != NULL && |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 1875 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1876 | pipe_config->has_drrs = true; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1877 | intel_link_compute_m_n(bpp, lane_count, |
| 1878 | intel_connector->panel.downclock_mode->clock, |
| 1879 | pipe_config->port_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1880 | &pipe_config->dp_m2_n2, |
| 1881 | reduce_m_n); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1882 | } |
| 1883 | |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1884 | /* |
| 1885 | * DPLL0 VCO may need to be adjusted to get the correct |
| 1886 | * clock for eDP. This will affect cdclk as well. |
| 1887 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1888 | if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) { |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1889 | int vco; |
| 1890 | |
| 1891 | switch (pipe_config->port_clock / 2) { |
| 1892 | case 108000: |
| 1893 | case 216000: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1894 | vco = 8640000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1895 | break; |
| 1896 | default: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1897 | vco = 8100000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1898 | break; |
| 1899 | } |
| 1900 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 1901 | 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] | 1902 | } |
| 1903 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1904 | if (!HAS_DDI(dev_priv)) |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1905 | intel_dp_set_clock(encoder, pipe_config); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1906 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 1907 | intel_psr_compute_config(intel_dp, pipe_config); |
| 1908 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1909 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1912 | 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] | 1913 | int link_rate, uint8_t lane_count, |
| 1914 | bool link_mst) |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1915 | { |
Ville Syrjälä | edb2e53 | 2018-01-17 21:21:49 +0200 | [diff] [blame] | 1916 | intel_dp->link_trained = false; |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1917 | intel_dp->link_rate = link_rate; |
| 1918 | intel_dp->lane_count = lane_count; |
| 1919 | intel_dp->link_mst = link_mst; |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1920 | } |
| 1921 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1922 | static void intel_dp_prepare(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 1923 | const struct intel_crtc_state *pipe_config) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1924 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 1925 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1926 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1927 | enum port port = encoder->port; |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 1928 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1929 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1930 | |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1931 | intel_dp_set_link_params(intel_dp, pipe_config->port_clock, |
| 1932 | pipe_config->lane_count, |
| 1933 | intel_crtc_has_type(pipe_config, |
| 1934 | INTEL_OUTPUT_DP_MST)); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1935 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1936 | /* |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1937 | * There are four kinds of DP registers: |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1938 | * |
| 1939 | * IBX PCH |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1940 | * SNB CPU |
| 1941 | * IVB CPU |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1942 | * CPT PCH |
| 1943 | * |
| 1944 | * IBX PCH and CPU are the same for almost everything, |
| 1945 | * except that the CPU DP PLL is configured in this |
| 1946 | * register |
| 1947 | * |
| 1948 | * CPT PCH is quite different, having many bits moved |
| 1949 | * to the TRANS_DP_CTL register instead. That |
| 1950 | * configuration happens (oddly) in ironlake_pch_enable |
| 1951 | */ |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 1952 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1953 | /* Preserve the BIOS-computed detected bit. This is |
| 1954 | * supposed to be read-only. |
| 1955 | */ |
| 1956 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1957 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1958 | /* Handle DP bits in common between all three register formats */ |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1959 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1960 | intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1961 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1962 | /* Split out the IBX/CPU vs CPT settings */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1963 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1964 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1965 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1966 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1967 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1968 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1969 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
| 1970 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1971 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1972 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1973 | |
Daniel Vetter | 7c62a16 | 2013-06-01 17:16:20 +0200 | [diff] [blame] | 1974 | intel_dp->DP |= crtc->pipe << 29; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1975 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1976 | u32 trans_dp; |
| 1977 | |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1978 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1979 | |
| 1980 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 1981 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 1982 | trans_dp |= TRANS_DP_ENH_FRAMING; |
| 1983 | else |
| 1984 | trans_dp &= ~TRANS_DP_ENH_FRAMING; |
| 1985 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1986 | } else { |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 1987 | if (IS_G4X(dev_priv) && pipe_config->limited_color_range) |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1988 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1989 | |
| 1990 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1991 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1992 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1993 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1994 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
| 1995 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1996 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1997 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1998 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1999 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 2000 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2001 | else if (crtc->pipe == PIPE_B) |
| 2002 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2003 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 2006 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
| 2007 | #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] | 2008 | |
Paulo Zanoni | 1a5ef5b | 2013-12-19 14:29:43 -0200 | [diff] [blame] | 2009 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
| 2010 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2011 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 2012 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
| 2013 | #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] | 2014 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 2015 | static void intel_pps_verify_state(struct intel_dp *intel_dp); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 2016 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2017 | static void wait_panel_status(struct intel_dp *intel_dp, |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2018 | u32 mask, |
| 2019 | u32 value) |
| 2020 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2021 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2022 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2023 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2024 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2025 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 2026 | intel_pps_verify_state(intel_dp); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 2027 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2028 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 2029 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2030 | |
| 2031 | DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2032 | mask, value, |
| 2033 | I915_READ(pp_stat_reg), |
| 2034 | I915_READ(pp_ctrl_reg)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2035 | |
Chris Wilson | 9036ff0 | 2016-06-30 15:33:09 +0100 | [diff] [blame] | 2036 | if (intel_wait_for_register(dev_priv, |
| 2037 | pp_stat_reg, mask, value, |
| 2038 | 5000)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2039 | DRM_ERROR("Panel status timeout: status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2040 | I915_READ(pp_stat_reg), |
| 2041 | I915_READ(pp_ctrl_reg)); |
Chris Wilson | 54c136d | 2013-12-02 09:57:16 +0000 | [diff] [blame] | 2042 | |
| 2043 | DRM_DEBUG_KMS("Wait complete\n"); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2046 | static void wait_panel_on(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2047 | { |
| 2048 | DRM_DEBUG_KMS("Wait for panel power on\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2049 | wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2052 | static void wait_panel_off(struct intel_dp *intel_dp) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2053 | { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2054 | DRM_DEBUG_KMS("Wait for panel power off time\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2055 | wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2056 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2057 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2058 | static void wait_panel_power_cycle(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2059 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2060 | ktime_t panel_power_on_time; |
| 2061 | s64 panel_power_off_duration; |
| 2062 | |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2063 | DRM_DEBUG_KMS("Wait for panel power cycle\n"); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2064 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2065 | /* take the difference of currrent time and panel power off time |
| 2066 | * and then make panel wait for t11_t12 if needed. */ |
| 2067 | panel_power_on_time = ktime_get_boottime(); |
| 2068 | panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time); |
| 2069 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2070 | /* When we disable the VDD override bit last we have to do the manual |
| 2071 | * wait. */ |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2072 | if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay) |
| 2073 | wait_remaining_ms_from_jiffies(jiffies, |
| 2074 | intel_dp->panel_power_cycle_delay - panel_power_off_duration); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2075 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2076 | wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2077 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2078 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2079 | static void wait_backlight_on(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2080 | { |
| 2081 | wait_remaining_ms_from_jiffies(intel_dp->last_power_on, |
| 2082 | intel_dp->backlight_on_delay); |
| 2083 | } |
| 2084 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2085 | static void edp_wait_backlight_off(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2086 | { |
| 2087 | wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off, |
| 2088 | intel_dp->backlight_off_delay); |
| 2089 | } |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2090 | |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2091 | /* Read the current pp_control value, unlocking the register if it |
| 2092 | * is locked |
| 2093 | */ |
| 2094 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2095 | static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2096 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2097 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2098 | u32 control; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2099 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2100 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2101 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2102 | control = I915_READ(_pp_ctrl_reg(intel_dp)); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 2103 | if (WARN_ON(!HAS_DDI(dev_priv) && |
| 2104 | (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 2105 | control &= ~PANEL_UNLOCK_MASK; |
| 2106 | control |= PANEL_UNLOCK_REGS; |
| 2107 | } |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2108 | return control; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2111 | /* |
| 2112 | * Must be paired with edp_panel_vdd_off(). |
| 2113 | * Must hold pps_mutex around the whole on/off sequence. |
| 2114 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2115 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 2116 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2117 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2118 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2119 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2120 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2121 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2122 | bool need_to_disable = !intel_dp->want_panel_vdd; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2123 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2124 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2125 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2126 | if (!intel_dp_is_edp(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2127 | return false; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2128 | |
Egbert Eich | 2c623c1 | 2014-11-25 12:54:57 +0100 | [diff] [blame] | 2129 | cancel_delayed_work(&intel_dp->panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2130 | intel_dp->want_panel_vdd = true; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2131 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2132 | if (edp_have_panel_vdd(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2133 | return need_to_disable; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2134 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2135 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2136 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2137 | DRM_DEBUG_KMS("Turning eDP port %c VDD on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2138 | port_name(intel_dig_port->base.port)); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2139 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2140 | if (!edp_have_panel_power(intel_dp)) |
| 2141 | wait_panel_power_cycle(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2142 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2143 | pp = ironlake_get_pp_control(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2144 | pp |= EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2145 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2146 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 2147 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2148 | |
| 2149 | I915_WRITE(pp_ctrl_reg, pp); |
| 2150 | POSTING_READ(pp_ctrl_reg); |
| 2151 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2152 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2153 | /* |
| 2154 | * If the panel wasn't on, delay before accessing aux channel |
| 2155 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2156 | if (!edp_have_panel_power(intel_dp)) { |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2157 | DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2158 | port_name(intel_dig_port->base.port)); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2159 | msleep(intel_dp->panel_power_up_delay); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2160 | } |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2161 | |
| 2162 | return need_to_disable; |
| 2163 | } |
| 2164 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2165 | /* |
| 2166 | * Must be paired with intel_edp_panel_vdd_off() or |
| 2167 | * intel_edp_panel_off(). |
| 2168 | * Nested calls to these functions are not allowed since |
| 2169 | * we drop the lock. Caller must use some higher level |
| 2170 | * locking to prevent nested calls from other threads. |
| 2171 | */ |
Daniel Vetter | b80d6c7 | 2014-03-19 15:54:37 +0100 | [diff] [blame] | 2172 | void intel_edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2173 | { |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2174 | bool vdd; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2175 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2176 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2177 | return; |
| 2178 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2179 | pps_lock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2180 | vdd = edp_panel_vdd_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2181 | pps_unlock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2182 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2183 | I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2184 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2185 | } |
| 2186 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2187 | static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2188 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2189 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2190 | struct intel_digital_port *intel_dig_port = |
| 2191 | dp_to_dig_port(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2192 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2193 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2194 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2195 | lockdep_assert_held(&dev_priv->pps_mutex); |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 2196 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2197 | WARN_ON(intel_dp->want_panel_vdd); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2198 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2199 | if (!edp_have_panel_vdd(intel_dp)) |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2200 | return; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2201 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2202 | DRM_DEBUG_KMS("Turning eDP port %c VDD off\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2203 | port_name(intel_dig_port->base.port)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2204 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2205 | pp = ironlake_get_pp_control(intel_dp); |
| 2206 | pp &= ~EDP_FORCE_VDD; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2207 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2208 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
| 2209 | pp_stat_reg = _pp_stat_reg(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2210 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2211 | I915_WRITE(pp_ctrl_reg, pp); |
| 2212 | POSTING_READ(pp_ctrl_reg); |
Paulo Zanoni | 90791a5 | 2013-12-06 17:32:42 -0200 | [diff] [blame] | 2213 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2214 | /* Make sure sequencer is idle before allowing subsequent activity */ |
| 2215 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2216 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2217 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2218 | if ((pp & PANEL_POWER_ON) == 0) |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2219 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2220 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2221 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2224 | static void edp_panel_vdd_work(struct work_struct *__work) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2225 | { |
| 2226 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), |
| 2227 | struct intel_dp, panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2228 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2229 | pps_lock(intel_dp); |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2230 | if (!intel_dp->want_panel_vdd) |
| 2231 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2232 | pps_unlock(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2235 | static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) |
| 2236 | { |
| 2237 | unsigned long delay; |
| 2238 | |
| 2239 | /* |
| 2240 | * Queue the timer to fire a long time from now (relative to the power |
| 2241 | * down delay) to keep the panel power up across a sequence of |
| 2242 | * operations. |
| 2243 | */ |
| 2244 | delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5); |
| 2245 | schedule_delayed_work(&intel_dp->panel_vdd_work, delay); |
| 2246 | } |
| 2247 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2248 | /* |
| 2249 | * Must be paired with edp_panel_vdd_on(). |
| 2250 | * Must hold pps_mutex around the whole on/off sequence. |
| 2251 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2252 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2253 | 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] | 2254 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2255 | 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] | 2256 | |
| 2257 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2258 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2259 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2260 | return; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2261 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2262 | I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2263 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Keith Packard | f2e8b18 | 2011-11-01 20:01:35 -0700 | [diff] [blame] | 2264 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2265 | intel_dp->want_panel_vdd = false; |
| 2266 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2267 | if (sync) |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2268 | edp_panel_vdd_off_sync(intel_dp); |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2269 | else |
| 2270 | edp_panel_vdd_schedule_off(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2271 | } |
| 2272 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2273 | static void edp_panel_on(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2274 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2275 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2276 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2277 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2278 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2279 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2280 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2281 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2282 | return; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2283 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2284 | DRM_DEBUG_KMS("Turn eDP port %c panel power on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2285 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2286 | |
Ville Syrjälä | e7a89ac | 2014-10-16 21:30:07 +0300 | [diff] [blame] | 2287 | if (WARN(edp_have_panel_power(intel_dp), |
| 2288 | "eDP port %c panel power already on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2289 | port_name(dp_to_dig_port(intel_dp)->base.port))) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2290 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2291 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2292 | wait_panel_power_cycle(intel_dp); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2293 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2294 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2295 | pp = ironlake_get_pp_control(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2296 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2297 | /* ILK workaround: disable reset around power sequence */ |
| 2298 | pp &= ~PANEL_POWER_RESET; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2299 | I915_WRITE(pp_ctrl_reg, pp); |
| 2300 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2301 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2302 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2303 | pp |= PANEL_POWER_ON; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2304 | if (!IS_GEN5(dev_priv)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2305 | pp |= PANEL_POWER_RESET; |
| 2306 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2307 | I915_WRITE(pp_ctrl_reg, pp); |
| 2308 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2309 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2310 | wait_panel_on(intel_dp); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2311 | intel_dp->last_power_on = jiffies; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2312 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2313 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2314 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2315 | I915_WRITE(pp_ctrl_reg, pp); |
| 2316 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2317 | } |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2318 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2319 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2320 | void intel_edp_panel_on(struct intel_dp *intel_dp) |
| 2321 | { |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2322 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2323 | return; |
| 2324 | |
| 2325 | pps_lock(intel_dp); |
| 2326 | edp_panel_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2327 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2330 | |
| 2331 | static void edp_panel_off(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2332 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2333 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2334 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2335 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2336 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2337 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2338 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2339 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2340 | return; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2341 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2342 | DRM_DEBUG_KMS("Turn eDP port %c panel power off\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2343 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2344 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2345 | WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2346 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2347 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2348 | pp = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 35a3855 | 2012-08-12 22:17:14 +0200 | [diff] [blame] | 2349 | /* We need to switch off panel power _and_ force vdd, for otherwise some |
| 2350 | * panels get very unhappy and cease to work. */ |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2351 | pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | |
Patrik Jakobsson | b306415 | 2014-03-04 00:42:44 +0100 | [diff] [blame] | 2352 | EDP_BLC_ENABLE); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2353 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2354 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2355 | |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2356 | intel_dp->want_panel_vdd = false; |
| 2357 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2358 | I915_WRITE(pp_ctrl_reg, pp); |
| 2359 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2360 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2361 | wait_panel_off(intel_dp); |
Manasi Navare | d7ba25b | 2017-10-04 09:48:26 -0700 | [diff] [blame] | 2362 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2363 | |
| 2364 | /* We got a reference when we enabled the VDD. */ |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2365 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2366 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2367 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2368 | void intel_edp_panel_off(struct intel_dp *intel_dp) |
| 2369 | { |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2370 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2371 | return; |
| 2372 | |
| 2373 | pps_lock(intel_dp); |
| 2374 | edp_panel_off(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2375 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2378 | /* Enable backlight in the panel power control. */ |
| 2379 | static void _intel_edp_backlight_on(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2380 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2381 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2382 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2383 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2384 | |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 2385 | /* |
| 2386 | * If we enable the backlight right away following a panel power |
| 2387 | * on, we may see slight flicker as the panel syncs with the eDP |
| 2388 | * link. So delay a bit to make sure the image is solid before |
| 2389 | * allowing it to appear. |
| 2390 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2391 | wait_backlight_on(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2392 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2393 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2394 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2395 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2396 | pp |= EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2397 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2398 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2399 | |
| 2400 | I915_WRITE(pp_ctrl_reg, pp); |
| 2401 | POSTING_READ(pp_ctrl_reg); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2402 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2403 | pps_unlock(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2404 | } |
| 2405 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2406 | /* Enable backlight PWM and backlight PP control. */ |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2407 | void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state, |
| 2408 | const struct drm_connector_state *conn_state) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2409 | { |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2410 | struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder); |
| 2411 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2412 | if (!intel_dp_is_edp(intel_dp)) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2413 | return; |
| 2414 | |
| 2415 | DRM_DEBUG_KMS("\n"); |
| 2416 | |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2417 | intel_panel_enable_backlight(crtc_state, conn_state); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2418 | _intel_edp_backlight_on(intel_dp); |
| 2419 | } |
| 2420 | |
| 2421 | /* Disable backlight in the panel power control. */ |
| 2422 | static void _intel_edp_backlight_off(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2423 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2424 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2425 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2426 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2427 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2428 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2429 | return; |
| 2430 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2431 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2432 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2433 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2434 | pp &= ~EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2435 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2436 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2437 | |
| 2438 | I915_WRITE(pp_ctrl_reg, pp); |
| 2439 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2440 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2441 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2442 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2443 | intel_dp->last_backlight_off = jiffies; |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2444 | edp_wait_backlight_off(intel_dp); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2445 | } |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2446 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2447 | /* Disable backlight PP control and backlight PWM. */ |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2448 | void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2449 | { |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2450 | struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder); |
| 2451 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2452 | if (!intel_dp_is_edp(intel_dp)) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2453 | return; |
| 2454 | |
| 2455 | DRM_DEBUG_KMS("\n"); |
| 2456 | |
| 2457 | _intel_edp_backlight_off(intel_dp); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2458 | intel_panel_disable_backlight(old_conn_state); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2459 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2460 | |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2461 | /* |
| 2462 | * Hook for controlling the panel power control backlight through the bl_power |
| 2463 | * sysfs attribute. Take care to handle multiple calls. |
| 2464 | */ |
| 2465 | static void intel_edp_backlight_power(struct intel_connector *connector, |
| 2466 | bool enable) |
| 2467 | { |
| 2468 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2469 | bool is_enabled; |
| 2470 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2471 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2472 | is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2473 | pps_unlock(intel_dp); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2474 | |
| 2475 | if (is_enabled == enable) |
| 2476 | return; |
| 2477 | |
Jani Nikula | 23ba937 | 2014-08-27 14:08:43 +0300 | [diff] [blame] | 2478 | DRM_DEBUG_KMS("panel power control backlight %s\n", |
| 2479 | enable ? "enable" : "disable"); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2480 | |
| 2481 | if (enable) |
| 2482 | _intel_edp_backlight_on(intel_dp); |
| 2483 | else |
| 2484 | _intel_edp_backlight_off(intel_dp); |
| 2485 | } |
| 2486 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2487 | static void assert_dp_port(struct intel_dp *intel_dp, bool state) |
| 2488 | { |
| 2489 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 2490 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 2491 | bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN; |
| 2492 | |
| 2493 | I915_STATE_WARN(cur_state != state, |
| 2494 | "DP port %c state assertion failure (expected %s, current %s)\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2495 | port_name(dig_port->base.port), |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2496 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2497 | } |
| 2498 | #define assert_dp_port_disabled(d) assert_dp_port((d), false) |
| 2499 | |
| 2500 | static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state) |
| 2501 | { |
| 2502 | bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE; |
| 2503 | |
| 2504 | I915_STATE_WARN(cur_state != state, |
| 2505 | "eDP PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2506 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2507 | } |
| 2508 | #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) |
| 2509 | #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) |
| 2510 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2511 | static void ironlake_edp_pll_on(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2512 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2513 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2514 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2515 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2516 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2517 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2518 | assert_dp_port_disabled(intel_dp); |
| 2519 | assert_edp_pll_disabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2520 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2521 | DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n", |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2522 | pipe_config->port_clock); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2523 | |
| 2524 | intel_dp->DP &= ~DP_PLL_FREQ_MASK; |
| 2525 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2526 | if (pipe_config->port_clock == 162000) |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2527 | intel_dp->DP |= DP_PLL_FREQ_162MHZ; |
| 2528 | else |
| 2529 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
| 2530 | |
| 2531 | I915_WRITE(DP_A, intel_dp->DP); |
| 2532 | POSTING_READ(DP_A); |
| 2533 | udelay(500); |
| 2534 | |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2535 | /* |
| 2536 | * [DevILK] Work around required when enabling DP PLL |
| 2537 | * while a pipe is enabled going to FDI: |
| 2538 | * 1. Wait for the start of vertical blank on the enabled pipe going to FDI |
| 2539 | * 2. Program DP PLL enable |
| 2540 | */ |
| 2541 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 2542 | intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe); |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2543 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2544 | intel_dp->DP |= DP_PLL_ENABLE; |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2545 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2546 | I915_WRITE(DP_A, intel_dp->DP); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 2547 | POSTING_READ(DP_A); |
| 2548 | udelay(200); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2551 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp, |
| 2552 | const struct intel_crtc_state *old_crtc_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2553 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2554 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2555 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2556 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2557 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2558 | assert_dp_port_disabled(intel_dp); |
| 2559 | assert_edp_pll_enabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2560 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2561 | DRM_DEBUG_KMS("disabling eDP PLL\n"); |
| 2562 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2563 | intel_dp->DP &= ~DP_PLL_ENABLE; |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2564 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2565 | I915_WRITE(DP_A, intel_dp->DP); |
Chris Wilson | 1af5fa1 | 2010-09-08 21:07:28 +0100 | [diff] [blame] | 2566 | POSTING_READ(DP_A); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2567 | udelay(200); |
| 2568 | } |
| 2569 | |
Ville Syrjälä | 857c416 | 2017-10-27 12:45:23 +0300 | [diff] [blame] | 2570 | static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp) |
| 2571 | { |
| 2572 | /* |
| 2573 | * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus |
| 2574 | * be capable of signalling downstream hpd with a long pulse. |
| 2575 | * Whether or not that means D3 is safe to use is not clear, |
| 2576 | * but let's assume so until proven otherwise. |
| 2577 | * |
| 2578 | * FIXME should really check all downstream ports... |
| 2579 | */ |
| 2580 | return intel_dp->dpcd[DP_DPCD_REV] == 0x11 && |
| 2581 | intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT && |
| 2582 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD; |
| 2583 | } |
| 2584 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2585 | /* If the sink supports it, try to set the power state appropriately */ |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2586 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2587 | { |
| 2588 | int ret, i; |
| 2589 | |
| 2590 | /* Should have a valid DPCD by this point */ |
| 2591 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 2592 | return; |
| 2593 | |
| 2594 | if (mode != DRM_MODE_DPMS_ON) { |
Ville Syrjälä | 857c416 | 2017-10-27 12:45:23 +0300 | [diff] [blame] | 2595 | if (downstream_hpd_needs_d0(intel_dp)) |
| 2596 | return; |
| 2597 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2598 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2599 | DP_SET_POWER_D3); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2600 | } else { |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2601 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
| 2602 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2603 | /* |
| 2604 | * When turning on, we need to retry for 1ms to give the sink |
| 2605 | * time to wake up. |
| 2606 | */ |
| 2607 | for (i = 0; i < 3; i++) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2608 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2609 | DP_SET_POWER_D0); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2610 | if (ret == 1) |
| 2611 | break; |
| 2612 | msleep(1); |
| 2613 | } |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2614 | |
| 2615 | if (ret == 1 && lspcon->active) |
| 2616 | lspcon_wait_pcon_mode(lspcon); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2617 | } |
Jani Nikula | f9cac72 | 2014-09-02 16:33:52 +0300 | [diff] [blame] | 2618 | |
| 2619 | if (ret != 1) |
| 2620 | DRM_DEBUG_KMS("failed to %s sink power state\n", |
| 2621 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2624 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
| 2625 | enum pipe *pipe) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2626 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2627 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2628 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2629 | enum port port = encoder->port; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2630 | u32 tmp; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2631 | bool ret; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2632 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2633 | if (!intel_display_power_get_if_enabled(dev_priv, |
| 2634 | encoder->power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2635 | return false; |
| 2636 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2637 | ret = false; |
| 2638 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2639 | tmp = I915_READ(intel_dp->output_reg); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2640 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2641 | if (!(tmp & DP_PORT_EN)) |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2642 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2643 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2644 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2645 | *pipe = PORT_TO_PIPE_CPT(tmp); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2646 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2647 | enum pipe p; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2648 | |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2649 | for_each_pipe(dev_priv, p) { |
| 2650 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); |
| 2651 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { |
| 2652 | *pipe = p; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2653 | ret = true; |
| 2654 | |
| 2655 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2656 | } |
| 2657 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2658 | |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2659 | 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] | 2660 | i915_mmio_reg_offset(intel_dp->output_reg)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2661 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2662 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); |
| 2663 | } else { |
| 2664 | *pipe = PORT_TO_PIPE(tmp); |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2665 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2666 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2667 | ret = true; |
| 2668 | |
| 2669 | out: |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2670 | intel_display_power_put(dev_priv, encoder->power_domain); |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2671 | |
| 2672 | return ret; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2673 | } |
| 2674 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2675 | static void intel_dp_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2676 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2677 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2678 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2679 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2680 | u32 tmp, flags = 0; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2681 | enum port port = encoder->port; |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2682 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2683 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 2684 | if (encoder->type == INTEL_OUTPUT_EDP) |
| 2685 | pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP); |
| 2686 | else |
| 2687 | pipe_config->output_types |= BIT(INTEL_OUTPUT_DP); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2688 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2689 | tmp = I915_READ(intel_dp->output_reg); |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 2690 | |
| 2691 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2692 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2693 | if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2694 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 2695 | |
| 2696 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2697 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2698 | else |
| 2699 | flags |= DRM_MODE_FLAG_NHSYNC; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2700 | |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2701 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2702 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2703 | else |
| 2704 | flags |= DRM_MODE_FLAG_NVSYNC; |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2705 | } else { |
| 2706 | if (tmp & DP_SYNC_HS_HIGH) |
| 2707 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2708 | else |
| 2709 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2710 | |
| 2711 | if (tmp & DP_SYNC_VS_HIGH) |
| 2712 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2713 | else |
| 2714 | flags |= DRM_MODE_FLAG_NVSYNC; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2715 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2716 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2717 | pipe_config->base.adjusted_mode.flags |= flags; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2718 | |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 2719 | if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235) |
Ville Syrjälä | 8c875fc | 2014-09-12 15:46:29 +0300 | [diff] [blame] | 2720 | pipe_config->limited_color_range = true; |
| 2721 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2722 | pipe_config->lane_count = |
| 2723 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; |
| 2724 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2725 | intel_dp_get_m_n(crtc, pipe_config); |
| 2726 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2727 | if (port == PORT_A) { |
Ville Syrjälä | b377e0d | 2015-10-29 21:25:59 +0200 | [diff] [blame] | 2728 | 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] | 2729 | pipe_config->port_clock = 162000; |
| 2730 | else |
| 2731 | pipe_config->port_clock = 270000; |
| 2732 | } |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2733 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 2734 | pipe_config->base.adjusted_mode.crtc_clock = |
| 2735 | intel_dotclock_calculate(pipe_config->port_clock, |
| 2736 | &pipe_config->dp_m_n); |
Daniel Vetter | 7f16e5c | 2013-11-04 16:28:47 +0100 | [diff] [blame] | 2737 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2738 | if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2739 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2740 | /* |
| 2741 | * This is a big fat ugly hack. |
| 2742 | * |
| 2743 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2744 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2745 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2746 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2747 | * max, not what it tells us to use. |
| 2748 | * |
| 2749 | * Note: This will still be broken if the eDP panel is not lit |
| 2750 | * up by the BIOS, and thus we can't get the mode at module |
| 2751 | * load. |
| 2752 | */ |
| 2753 | 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] | 2754 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2755 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2756 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2759 | static void intel_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2760 | const struct intel_crtc_state *old_crtc_state, |
| 2761 | const struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2762 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2763 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2764 | |
Ville Syrjälä | edb2e53 | 2018-01-17 21:21:49 +0200 | [diff] [blame] | 2765 | intel_dp->link_trained = false; |
| 2766 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2767 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 8ec47de | 2017-10-30 20:46:53 +0200 | [diff] [blame] | 2768 | intel_audio_codec_disable(encoder, |
| 2769 | old_crtc_state, old_conn_state); |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2770 | |
| 2771 | /* Make sure the panel is off before trying to change the mode. But also |
| 2772 | * ensure that we have vdd while we switch off the panel. */ |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2773 | intel_edp_panel_vdd_on(intel_dp); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2774 | intel_edp_backlight_off(old_conn_state); |
Jani Nikula | fdbc3b1 | 2013-11-12 17:10:13 +0200 | [diff] [blame] | 2775 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2776 | intel_edp_panel_off(intel_dp); |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | static void g4x_disable_dp(struct intel_encoder *encoder, |
| 2780 | const struct intel_crtc_state *old_crtc_state, |
| 2781 | const struct drm_connector_state *old_conn_state) |
| 2782 | { |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2783 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2784 | |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2785 | /* disable the port before the pipe on g4x */ |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2786 | intel_dp_link_down(encoder, old_crtc_state); |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | static void ilk_disable_dp(struct intel_encoder *encoder, |
| 2790 | const struct intel_crtc_state *old_crtc_state, |
| 2791 | const struct drm_connector_state *old_conn_state) |
| 2792 | { |
| 2793 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
| 2794 | } |
| 2795 | |
| 2796 | static void vlv_disable_dp(struct intel_encoder *encoder, |
| 2797 | const struct intel_crtc_state *old_crtc_state, |
| 2798 | const struct drm_connector_state *old_conn_state) |
| 2799 | { |
| 2800 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2801 | |
| 2802 | intel_psr_disable(intel_dp, old_crtc_state); |
| 2803 | |
| 2804 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2807 | static void ilk_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2808 | const struct intel_crtc_state *old_crtc_state, |
| 2809 | const struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2810 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2811 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2812 | enum port port = encoder->port; |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2813 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2814 | intel_dp_link_down(encoder, old_crtc_state); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2815 | |
| 2816 | /* Only ilk+ has port A */ |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2817 | if (port == PORT_A) |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2818 | ironlake_edp_pll_off(intel_dp, old_crtc_state); |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2819 | } |
| 2820 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2821 | static void vlv_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2822 | const struct intel_crtc_state *old_crtc_state, |
| 2823 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2824 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2825 | intel_dp_link_down(encoder, old_crtc_state); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2826 | } |
| 2827 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2828 | static void chv_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2829 | const struct intel_crtc_state *old_crtc_state, |
| 2830 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2831 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2832 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2833 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2834 | intel_dp_link_down(encoder, old_crtc_state); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2835 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2836 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2837 | |
Ville Syrjälä | a8f327f | 2015-07-09 20:14:11 +0300 | [diff] [blame] | 2838 | /* Assert data lane reset */ |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 2839 | chv_data_lane_soft_reset(encoder, old_crtc_state, true); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2840 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2841 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2842 | } |
| 2843 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2844 | static void |
| 2845 | _intel_dp_set_link_train(struct intel_dp *intel_dp, |
| 2846 | uint32_t *DP, |
| 2847 | uint8_t dp_train_pat) |
| 2848 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2849 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2850 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2851 | enum port port = intel_dig_port->base.port; |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2852 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2853 | if (dp_train_pat & DP_TRAINING_PATTERN_MASK) |
| 2854 | DRM_DEBUG_KMS("Using DP training pattern TPS%d\n", |
| 2855 | dp_train_pat & DP_TRAINING_PATTERN_MASK); |
| 2856 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 2857 | if (HAS_DDI(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2858 | uint32_t temp = I915_READ(DP_TP_CTL(port)); |
| 2859 | |
| 2860 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) |
| 2861 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2862 | else |
| 2863 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2864 | |
| 2865 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 2866 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2867 | case DP_TRAINING_PATTERN_DISABLE: |
| 2868 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; |
| 2869 | |
| 2870 | break; |
| 2871 | case DP_TRAINING_PATTERN_1: |
| 2872 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2873 | break; |
| 2874 | case DP_TRAINING_PATTERN_2: |
| 2875 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; |
| 2876 | break; |
| 2877 | case DP_TRAINING_PATTERN_3: |
| 2878 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; |
| 2879 | break; |
| 2880 | } |
| 2881 | I915_WRITE(DP_TP_CTL(port), temp); |
| 2882 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2883 | } else if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2884 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2885 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 2886 | |
| 2887 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2888 | case DP_TRAINING_PATTERN_DISABLE: |
| 2889 | *DP |= DP_LINK_TRAIN_OFF_CPT; |
| 2890 | break; |
| 2891 | case DP_TRAINING_PATTERN_1: |
| 2892 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; |
| 2893 | break; |
| 2894 | case DP_TRAINING_PATTERN_2: |
| 2895 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2896 | break; |
| 2897 | case DP_TRAINING_PATTERN_3: |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2898 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2899 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2900 | break; |
| 2901 | } |
| 2902 | |
| 2903 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2904 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2905 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 2906 | else |
| 2907 | *DP &= ~DP_LINK_TRAIN_MASK; |
| 2908 | |
| 2909 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2910 | case DP_TRAINING_PATTERN_DISABLE: |
| 2911 | *DP |= DP_LINK_TRAIN_OFF; |
| 2912 | break; |
| 2913 | case DP_TRAINING_PATTERN_1: |
| 2914 | *DP |= DP_LINK_TRAIN_PAT_1; |
| 2915 | break; |
| 2916 | case DP_TRAINING_PATTERN_2: |
| 2917 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2918 | break; |
| 2919 | case DP_TRAINING_PATTERN_3: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2920 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2921 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; |
| 2922 | } else { |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2923 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2924 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2925 | } |
| 2926 | break; |
| 2927 | } |
| 2928 | } |
| 2929 | } |
| 2930 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2931 | static void intel_dp_enable_port(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2932 | const struct intel_crtc_state *old_crtc_state) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2933 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2934 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2935 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2936 | /* enable with pattern 1 (as per spec) */ |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2937 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2938 | 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] | 2939 | |
| 2940 | /* |
| 2941 | * Magic for VLV/CHV. We _must_ first set up the register |
| 2942 | * without actually enabling the port, and then do another |
| 2943 | * write to enable the port. Otherwise link training will |
| 2944 | * fail when the power sequencer is freshly used for this port. |
| 2945 | */ |
| 2946 | intel_dp->DP |= DP_PORT_EN; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2947 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2948 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2949 | |
| 2950 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 2951 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2952 | } |
| 2953 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2954 | static void intel_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2955 | const struct intel_crtc_state *pipe_config, |
| 2956 | const struct drm_connector_state *conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2957 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 2958 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2959 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2960 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2961 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2962 | enum pipe pipe = crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2963 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 2964 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
| 2965 | return; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2966 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2967 | pps_lock(intel_dp); |
| 2968 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2969 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2970 | vlv_init_panel_power_sequencer(encoder, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2971 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2972 | intel_dp_enable_port(intel_dp, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2973 | |
| 2974 | edp_panel_vdd_on(intel_dp); |
| 2975 | edp_panel_on(intel_dp); |
| 2976 | edp_panel_vdd_off(intel_dp, true); |
| 2977 | |
| 2978 | pps_unlock(intel_dp); |
| 2979 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2980 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2981 | unsigned int lane_mask = 0x0; |
| 2982 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2983 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2984 | lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2985 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 2986 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
| 2987 | lane_mask); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2988 | } |
Ville Syrjälä | 61234fa | 2014-10-16 21:27:34 +0300 | [diff] [blame] | 2989 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2990 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 2991 | intel_dp_start_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2992 | intel_dp_stop_link_train(intel_dp); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2993 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2994 | if (pipe_config->has_audio) { |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2995 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2996 | pipe_name(pipe)); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2997 | intel_audio_codec_enable(encoder, pipe_config, conn_state); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2998 | } |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2999 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3000 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3001 | static void g4x_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3002 | const struct intel_crtc_state *pipe_config, |
| 3003 | const struct drm_connector_state *conn_state) |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 3004 | { |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3005 | intel_enable_dp(encoder, pipe_config, conn_state); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 3006 | intel_edp_backlight_on(pipe_config, conn_state); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3007 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3008 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3009 | static void vlv_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3010 | const struct intel_crtc_state *pipe_config, |
| 3011 | const struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3012 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 3013 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 3014 | |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 3015 | intel_edp_backlight_on(pipe_config, conn_state); |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 3016 | intel_psr_enable(intel_dp, pipe_config); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3019 | static void g4x_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3020 | const struct intel_crtc_state *pipe_config, |
| 3021 | const struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3022 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 3023 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3024 | enum port port = encoder->port; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3025 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3026 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 3027 | |
Daniel Vetter | d41f1ef | 2014-04-24 23:54:53 +0200 | [diff] [blame] | 3028 | /* Only ilk+ has port A */ |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 3029 | if (port == PORT_A) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3030 | ironlake_edp_pll_on(intel_dp, pipe_config); |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3031 | } |
| 3032 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3033 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
| 3034 | { |
| 3035 | 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] | 3036 | 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] | 3037 | enum pipe pipe = intel_dp->pps_pipe; |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 3038 | i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3039 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3040 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 3041 | |
Ville Syrjälä | d158694 | 2017-02-08 19:52:54 +0200 | [diff] [blame] | 3042 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 3043 | return; |
| 3044 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3045 | edp_panel_vdd_off_sync(intel_dp); |
| 3046 | |
| 3047 | /* |
| 3048 | * VLV seems to get confused when multiple power seqeuencers |
| 3049 | * have the same port selected (even if only one has power/vdd |
| 3050 | * enabled). The failure manifests as vlv_wait_port_ready() failing |
| 3051 | * CHV on the other hand doesn't seem to mind having the same port |
| 3052 | * selected in multiple power seqeuencers, but let's clear the |
| 3053 | * port select always when logically disconnecting a power sequencer |
| 3054 | * from a port. |
| 3055 | */ |
| 3056 | DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3057 | pipe_name(pipe), port_name(intel_dig_port->base.port)); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3058 | I915_WRITE(pp_on_reg, 0); |
| 3059 | POSTING_READ(pp_on_reg); |
| 3060 | |
| 3061 | intel_dp->pps_pipe = INVALID_PIPE; |
| 3062 | } |
| 3063 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 3064 | static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv, |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3065 | enum pipe pipe) |
| 3066 | { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3067 | struct intel_encoder *encoder; |
| 3068 | |
| 3069 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 3070 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 3071 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3072 | struct intel_dp *intel_dp; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 3073 | enum port port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3074 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3075 | if (encoder->type != INTEL_OUTPUT_DP && |
| 3076 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3077 | continue; |
| 3078 | |
| 3079 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3080 | port = dp_to_dig_port(intel_dp)->base.port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3081 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3082 | WARN(intel_dp->active_pipe == pipe, |
| 3083 | "stealing pipe %c power sequencer from active (e)DP port %c\n", |
| 3084 | pipe_name(pipe), port_name(port)); |
| 3085 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3086 | if (intel_dp->pps_pipe != pipe) |
| 3087 | continue; |
| 3088 | |
| 3089 | 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] | 3090 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3091 | |
| 3092 | /* make sure vdd is off before we steal it */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3093 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3094 | } |
| 3095 | } |
| 3096 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3097 | static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder, |
| 3098 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3099 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 3100 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3101 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3102 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3103 | |
| 3104 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 3105 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3106 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 3107 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3108 | if (intel_dp->pps_pipe != INVALID_PIPE && |
| 3109 | intel_dp->pps_pipe != crtc->pipe) { |
| 3110 | /* |
| 3111 | * If another power sequencer was being used on this |
| 3112 | * port previously make sure to turn off vdd there while |
| 3113 | * we still have control of it. |
| 3114 | */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3115 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3116 | } |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3117 | |
| 3118 | /* |
| 3119 | * We may be stealing the power |
| 3120 | * sequencer from another port. |
| 3121 | */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 3122 | vlv_steal_power_sequencer(dev_priv, crtc->pipe); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3123 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3124 | intel_dp->active_pipe = crtc->pipe; |
| 3125 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3126 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3127 | return; |
| 3128 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3129 | /* now it's all ours */ |
| 3130 | intel_dp->pps_pipe = crtc->pipe; |
| 3131 | |
| 3132 | DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n", |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3133 | pipe_name(intel_dp->pps_pipe), port_name(encoder->port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3134 | |
| 3135 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 3136 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 3137 | intel_dp_init_panel_power_sequencer_registers(intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3138 | } |
| 3139 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3140 | static void vlv_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3141 | const struct intel_crtc_state *pipe_config, |
| 3142 | const struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3143 | { |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3144 | vlv_phy_pre_encoder_enable(encoder, pipe_config); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3145 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3146 | intel_enable_dp(encoder, pipe_config, conn_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3149 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3150 | const struct intel_crtc_state *pipe_config, |
| 3151 | const struct drm_connector_state *conn_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3152 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3153 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 3154 | |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3155 | vlv_phy_pre_pll_enable(encoder, pipe_config); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3158 | static void chv_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3159 | const struct intel_crtc_state *pipe_config, |
| 3160 | const struct drm_connector_state *conn_state) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3161 | { |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3162 | chv_phy_pre_encoder_enable(encoder, pipe_config); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3163 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3164 | intel_enable_dp(encoder, pipe_config, conn_state); |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 3165 | |
| 3166 | /* Second common lane will stay alive on its own now */ |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3167 | chv_phy_release_cl2_override(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3168 | } |
| 3169 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3170 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3171 | const struct intel_crtc_state *pipe_config, |
| 3172 | const struct drm_connector_state *conn_state) |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3173 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3174 | intel_dp_prepare(encoder, pipe_config); |
Ville Syrjälä | 625695f | 2014-06-28 02:04:02 +0300 | [diff] [blame] | 3175 | |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3176 | chv_phy_pre_pll_enable(encoder, pipe_config); |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3177 | } |
| 3178 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3179 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder, |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3180 | const struct intel_crtc_state *old_crtc_state, |
| 3181 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3182 | { |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3183 | chv_phy_post_pll_disable(encoder, old_crtc_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3184 | } |
| 3185 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3186 | /* |
| 3187 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 3188 | * link status information |
| 3189 | */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3190 | bool |
Keith Packard | 93f62da | 2011-11-01 19:45:03 -0700 | [diff] [blame] | 3191 | 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] | 3192 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3193 | return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status, |
| 3194 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Paulo Zanoni | 1100244 | 2014-06-13 18:45:41 -0300 | [diff] [blame] | 3197 | /* These are source-specific values. */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3198 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3199 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3200 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3201 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3202 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3203 | |
Ville Syrjälä | 7d4f37b | 2017-10-16 17:57:00 +0300 | [diff] [blame] | 3204 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | ffe5111 | 2017-02-23 19:49:01 +0200 | [diff] [blame] | 3205 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3206 | return intel_ddi_dp_voltage_max(encoder); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3207 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3208 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3209 | else if (IS_GEN7(dev_priv) && port == PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3210 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3211 | else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3212 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3213 | else |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3214 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3215 | } |
| 3216 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3217 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3218 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
| 3219 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3220 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3221 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3222 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3223 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3224 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 3225 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3226 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3227 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3228 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3229 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3230 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3231 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
| 3232 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3233 | default: |
| 3234 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
| 3235 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3236 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3237 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3238 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3239 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3240 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3241 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3242 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3243 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3244 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3245 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3246 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3247 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3248 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3249 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3250 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3251 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3252 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3253 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3254 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3255 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3256 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3257 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3258 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3259 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3260 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3261 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3262 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3263 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3264 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3265 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3266 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3267 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3268 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3269 | } |
| 3270 | } else { |
| 3271 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3272 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3273 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3274 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3275 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3276 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3277 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3278 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3279 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3280 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3281 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3285 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3286 | { |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3287 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3288 | unsigned long demph_reg_value, preemph_reg_value, |
| 3289 | uniqtranscale_reg_value; |
| 3290 | uint8_t train_set = intel_dp->train_set[0]; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3291 | |
| 3292 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3293 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3294 | preemph_reg_value = 0x0004000; |
| 3295 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3296 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3297 | demph_reg_value = 0x2B405555; |
| 3298 | uniqtranscale_reg_value = 0x552AB83A; |
| 3299 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3300 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3301 | demph_reg_value = 0x2B404040; |
| 3302 | uniqtranscale_reg_value = 0x5548B83A; |
| 3303 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3304 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3305 | demph_reg_value = 0x2B245555; |
| 3306 | uniqtranscale_reg_value = 0x5560B83A; |
| 3307 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3308 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3309 | demph_reg_value = 0x2B405555; |
| 3310 | uniqtranscale_reg_value = 0x5598DA3A; |
| 3311 | break; |
| 3312 | default: |
| 3313 | return 0; |
| 3314 | } |
| 3315 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3316 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3317 | preemph_reg_value = 0x0002000; |
| 3318 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3319 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3320 | demph_reg_value = 0x2B404040; |
| 3321 | uniqtranscale_reg_value = 0x5552B83A; |
| 3322 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3323 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3324 | demph_reg_value = 0x2B404848; |
| 3325 | uniqtranscale_reg_value = 0x5580B83A; |
| 3326 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3327 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3328 | demph_reg_value = 0x2B404040; |
| 3329 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3330 | break; |
| 3331 | default: |
| 3332 | return 0; |
| 3333 | } |
| 3334 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3335 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3336 | preemph_reg_value = 0x0000000; |
| 3337 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3338 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3339 | demph_reg_value = 0x2B305555; |
| 3340 | uniqtranscale_reg_value = 0x5570B83A; |
| 3341 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3342 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3343 | demph_reg_value = 0x2B2B4040; |
| 3344 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3345 | break; |
| 3346 | default: |
| 3347 | return 0; |
| 3348 | } |
| 3349 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3350 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3351 | preemph_reg_value = 0x0006000; |
| 3352 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3353 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3354 | demph_reg_value = 0x1B405555; |
| 3355 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3356 | break; |
| 3357 | default: |
| 3358 | return 0; |
| 3359 | } |
| 3360 | break; |
| 3361 | default: |
| 3362 | return 0; |
| 3363 | } |
| 3364 | |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3365 | vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value, |
| 3366 | uniqtranscale_reg_value, 0); |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3367 | |
| 3368 | return 0; |
| 3369 | } |
| 3370 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3371 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3372 | { |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3373 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3374 | u32 deemph_reg_value, margin_reg_value; |
| 3375 | bool uniq_trans_scale = false; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3376 | uint8_t train_set = intel_dp->train_set[0]; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3377 | |
| 3378 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3379 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3380 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3381 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3382 | deemph_reg_value = 128; |
| 3383 | margin_reg_value = 52; |
| 3384 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3385 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3386 | deemph_reg_value = 128; |
| 3387 | margin_reg_value = 77; |
| 3388 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3389 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3390 | deemph_reg_value = 128; |
| 3391 | margin_reg_value = 102; |
| 3392 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3393 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3394 | deemph_reg_value = 128; |
| 3395 | margin_reg_value = 154; |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3396 | uniq_trans_scale = true; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3397 | break; |
| 3398 | default: |
| 3399 | return 0; |
| 3400 | } |
| 3401 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3402 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3403 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3404 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3405 | deemph_reg_value = 85; |
| 3406 | margin_reg_value = 78; |
| 3407 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3408 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3409 | deemph_reg_value = 85; |
| 3410 | margin_reg_value = 116; |
| 3411 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3412 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3413 | deemph_reg_value = 85; |
| 3414 | margin_reg_value = 154; |
| 3415 | break; |
| 3416 | default: |
| 3417 | return 0; |
| 3418 | } |
| 3419 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3420 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3421 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3422 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3423 | deemph_reg_value = 64; |
| 3424 | margin_reg_value = 104; |
| 3425 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3426 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3427 | deemph_reg_value = 64; |
| 3428 | margin_reg_value = 154; |
| 3429 | break; |
| 3430 | default: |
| 3431 | return 0; |
| 3432 | } |
| 3433 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3434 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3435 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3436 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3437 | deemph_reg_value = 43; |
| 3438 | margin_reg_value = 154; |
| 3439 | break; |
| 3440 | default: |
| 3441 | return 0; |
| 3442 | } |
| 3443 | break; |
| 3444 | default: |
| 3445 | return 0; |
| 3446 | } |
| 3447 | |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3448 | chv_set_phy_signal_level(encoder, deemph_reg_value, |
| 3449 | margin_reg_value, uniq_trans_scale); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3450 | |
| 3451 | return 0; |
| 3452 | } |
| 3453 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3454 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3455 | gen4_signal_levels(uint8_t train_set) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3456 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3457 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3458 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3459 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3460 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3461 | default: |
| 3462 | signal_levels |= DP_VOLTAGE_0_4; |
| 3463 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3464 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3465 | signal_levels |= DP_VOLTAGE_0_6; |
| 3466 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3467 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3468 | signal_levels |= DP_VOLTAGE_0_8; |
| 3469 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3470 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3471 | signal_levels |= DP_VOLTAGE_1_2; |
| 3472 | break; |
| 3473 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3474 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3475 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3476 | default: |
| 3477 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 3478 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3479 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3480 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 3481 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3482 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3483 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 3484 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3485 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3486 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 3487 | break; |
| 3488 | } |
| 3489 | return signal_levels; |
| 3490 | } |
| 3491 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3492 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 3493 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3494 | gen6_edp_signal_levels(uint8_t train_set) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3495 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3496 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3497 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3498 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3499 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3500 | 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] | 3501 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3502 | 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] | 3503 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3504 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 3505 | 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] | 3506 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3507 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 3508 | 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] | 3509 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3510 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3511 | 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] | 3512 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3513 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3514 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3515 | "0x%x\n", signal_levels); |
| 3516 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3520 | /* Gen7's DP voltage swing and pre-emphasis control */ |
| 3521 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3522 | gen7_edp_signal_levels(uint8_t train_set) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3523 | { |
| 3524 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3525 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3526 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3527 | 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] | 3528 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3529 | 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] | 3530 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3531 | 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] | 3532 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
| 3533 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3534 | 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] | 3535 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3536 | 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] | 3537 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
| 3538 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3539 | 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] | 3540 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3541 | 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] | 3542 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
| 3543 | |
| 3544 | default: |
| 3545 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3546 | "0x%x\n", signal_levels); |
| 3547 | return EDP_LINK_TRAIN_500MV_0DB_IVB; |
| 3548 | } |
| 3549 | } |
| 3550 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3551 | void |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3552 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3553 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 3554 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3555 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3556 | enum port port = intel_dig_port->base.port; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3557 | uint32_t signal_levels, mask = 0; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3558 | uint8_t train_set = intel_dp->train_set[0]; |
| 3559 | |
Rodrigo Vivi | d509af6 | 2017-08-29 16:22:24 -0700 | [diff] [blame] | 3560 | if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
| 3561 | signal_levels = bxt_signal_levels(intel_dp); |
| 3562 | } else if (HAS_DDI(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3563 | signal_levels = ddi_signal_levels(intel_dp); |
Rodrigo Vivi | d509af6 | 2017-08-29 16:22:24 -0700 | [diff] [blame] | 3564 | mask = DDI_BUF_EMP_MASK; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3565 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3566 | signal_levels = chv_signal_levels(intel_dp); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 3567 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3568 | signal_levels = vlv_signal_levels(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3569 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3570 | signal_levels = gen7_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3571 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3572 | } else if (IS_GEN6(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3573 | signal_levels = gen6_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3574 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
| 3575 | } else { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3576 | signal_levels = gen4_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3577 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
| 3578 | } |
| 3579 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 3580 | if (mask) |
| 3581 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); |
| 3582 | |
| 3583 | DRM_DEBUG_KMS("Using vswing level %d\n", |
| 3584 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); |
| 3585 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", |
| 3586 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> |
| 3587 | DP_TRAIN_PRE_EMPHASIS_SHIFT); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3588 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3589 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3590 | |
| 3591 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 3592 | POSTING_READ(intel_dp->output_reg); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3593 | } |
| 3594 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3595 | void |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3596 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
| 3597 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3598 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 3599 | 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] | 3600 | struct drm_i915_private *dev_priv = |
| 3601 | to_i915(intel_dig_port->base.base.dev); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3602 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3603 | _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] | 3604 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3605 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3606 | POSTING_READ(intel_dp->output_reg); |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3607 | } |
| 3608 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3609 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3610 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 3611 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3612 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3613 | enum port port = intel_dig_port->base.port; |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3614 | uint32_t val; |
| 3615 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3616 | if (!HAS_DDI(dev_priv)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3617 | return; |
| 3618 | |
| 3619 | val = I915_READ(DP_TP_CTL(port)); |
| 3620 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 3621 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; |
| 3622 | I915_WRITE(DP_TP_CTL(port), val); |
| 3623 | |
| 3624 | /* |
| 3625 | * On PORT_A we can have only eDP in SST mode. There the only reason |
| 3626 | * we need to set idle transmission mode is to work around a HW issue |
| 3627 | * where we enable the pipe while not in idle link-training mode. |
| 3628 | * In this case there is requirement to wait for a minimum number of |
| 3629 | * idle patterns to be sent. |
| 3630 | */ |
| 3631 | if (port == PORT_A) |
| 3632 | return; |
| 3633 | |
Chris Wilson | a767017 | 2016-06-30 15:33:10 +0100 | [diff] [blame] | 3634 | if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port), |
| 3635 | DP_TP_STATUS_IDLE_DONE, |
| 3636 | DP_TP_STATUS_IDLE_DONE, |
| 3637 | 1)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3638 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); |
| 3639 | } |
| 3640 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3641 | static void |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3642 | intel_dp_link_down(struct intel_encoder *encoder, |
| 3643 | const struct intel_crtc_state *old_crtc_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3644 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3645 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 3646 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 3647 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 3648 | enum port port = encoder->port; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3649 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3650 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3651 | if (WARN_ON(HAS_DDI(dev_priv))) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 3652 | return; |
| 3653 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 3654 | 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] | 3655 | return; |
| 3656 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3657 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3658 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3659 | if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3660 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3661 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3662 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3663 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3664 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | aad3d14 | 2014-06-28 02:04:25 +0300 | [diff] [blame] | 3665 | DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 3666 | else |
| 3667 | DP &= ~DP_LINK_TRAIN_MASK; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3668 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3669 | } |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3670 | I915_WRITE(intel_dp->output_reg, DP); |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 3671 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3672 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3673 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
| 3674 | I915_WRITE(intel_dp->output_reg, DP); |
| 3675 | POSTING_READ(intel_dp->output_reg); |
| 3676 | |
| 3677 | /* |
| 3678 | * HW workaround for IBX, we need to move the port |
| 3679 | * to transcoder A after disabling it to allow the |
| 3680 | * matching HDMI port to be enabled on transcoder A. |
| 3681 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3682 | 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] | 3683 | /* |
| 3684 | * We get CPU/PCH FIFO underruns on the other pipe when |
| 3685 | * doing the workaround. Sweep them under the rug. |
| 3686 | */ |
| 3687 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3688 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3689 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3690 | /* always enable with pattern 1 (as per spec) */ |
| 3691 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); |
| 3692 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; |
| 3693 | I915_WRITE(intel_dp->output_reg, DP); |
| 3694 | POSTING_READ(intel_dp->output_reg); |
| 3695 | |
| 3696 | DP &= ~DP_PORT_EN; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3697 | I915_WRITE(intel_dp->output_reg, DP); |
Daniel Vetter | 0ca0968 | 2014-11-24 16:54:11 +0100 | [diff] [blame] | 3698 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3699 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3700 | intel_wait_for_vblank_if_active(dev_priv, PIPE_A); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3701 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
| 3702 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 3705 | msleep(intel_dp->panel_power_down_delay); |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 3706 | |
| 3707 | intel_dp->DP = DP; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3708 | |
| 3709 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 3710 | pps_lock(intel_dp); |
| 3711 | intel_dp->active_pipe = INVALID_PIPE; |
| 3712 | pps_unlock(intel_dp); |
| 3713 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
Imre Deak | 24e807e | 2016-10-24 19:33:28 +0300 | [diff] [blame] | 3716 | bool |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3717 | intel_dp_read_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3718 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3719 | if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, |
| 3720 | sizeof(intel_dp->dpcd)) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3721 | return false; /* aux transfer failed */ |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3722 | |
Andy Shevchenko | a8e9815 | 2014-09-01 14:12:01 +0300 | [diff] [blame] | 3723 | 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] | 3724 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3725 | return intel_dp->dpcd[DP_DPCD_REV] != 0; |
| 3726 | } |
| 3727 | |
| 3728 | static bool |
| 3729 | intel_edp_init_dpcd(struct intel_dp *intel_dp) |
| 3730 | { |
| 3731 | struct drm_i915_private *dev_priv = |
| 3732 | to_i915(dp_to_dig_port(intel_dp)->base.base.dev); |
| 3733 | |
| 3734 | /* this function is meant to be called only once */ |
| 3735 | WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0); |
| 3736 | |
| 3737 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3738 | return false; |
| 3739 | |
Jani Nikula | 84c3675 | 2017-05-18 14:10:23 +0300 | [diff] [blame] | 3740 | drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, |
| 3741 | drm_dp_is_branch(intel_dp->dpcd)); |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 3742 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3743 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 3744 | dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
| 3745 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 3746 | |
Dhinakaran Pandiyan | 77fe36f | 2018-02-23 14:15:17 -0800 | [diff] [blame] | 3747 | intel_psr_init_dpcd(intel_dp); |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3748 | |
Jani Nikula | 7c838e2 | 2017-10-26 17:29:31 +0300 | [diff] [blame] | 3749 | /* |
| 3750 | * Read the eDP display control registers. |
| 3751 | * |
| 3752 | * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in |
| 3753 | * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it |
| 3754 | * set, but require eDP 1.4+ detection (e.g. for supported link rates |
| 3755 | * method). The display control registers should read zero if they're |
| 3756 | * not supported anyway. |
| 3757 | */ |
| 3758 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, |
Dan Carpenter | f7170e2 | 2016-10-13 11:55:08 +0300 | [diff] [blame] | 3759 | intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == |
| 3760 | sizeof(intel_dp->edp_dpcd)) |
Jani Nikula | e6ed2a1 | 2017-10-26 17:29:32 +0300 | [diff] [blame] | 3761 | DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd), |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3762 | intel_dp->edp_dpcd); |
| 3763 | |
Jani Nikula | e6ed2a1 | 2017-10-26 17:29:32 +0300 | [diff] [blame] | 3764 | /* Read the eDP 1.4+ supported link rates. */ |
| 3765 | if (intel_dp->edp_dpcd[0] >= DP_EDP_14) { |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3766 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
| 3767 | int i; |
| 3768 | |
| 3769 | drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES, |
| 3770 | sink_rates, sizeof(sink_rates)); |
| 3771 | |
| 3772 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
| 3773 | int val = le16_to_cpu(sink_rates[i]); |
| 3774 | |
| 3775 | if (val == 0) |
| 3776 | break; |
| 3777 | |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 3778 | /* Value read multiplied by 200kHz gives the per-lane |
| 3779 | * link rate in kHz. The source rates are, however, |
| 3780 | * stored in terms of LS_Clk kHz. The full conversion |
| 3781 | * back to symbols is |
| 3782 | * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) |
| 3783 | */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3784 | intel_dp->sink_rates[i] = (val * 200) / 10; |
| 3785 | } |
| 3786 | intel_dp->num_sink_rates = i; |
| 3787 | } |
| 3788 | |
Jani Nikula | e6ed2a1 | 2017-10-26 17:29:32 +0300 | [diff] [blame] | 3789 | /* |
| 3790 | * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available, |
| 3791 | * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise. |
| 3792 | */ |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3793 | if (intel_dp->num_sink_rates) |
| 3794 | intel_dp->use_rate_select = true; |
| 3795 | else |
| 3796 | intel_dp_set_sink_rates(intel_dp); |
| 3797 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 3798 | intel_dp_set_common_rates(intel_dp); |
| 3799 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3800 | return true; |
| 3801 | } |
| 3802 | |
| 3803 | |
| 3804 | static bool |
| 3805 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
| 3806 | { |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3807 | u8 sink_count; |
| 3808 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3809 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3810 | return false; |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3811 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3812 | /* Don't clobber cached eDP rates. */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3813 | if (!intel_dp_is_edp(intel_dp)) { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3814 | intel_dp_set_sink_rates(intel_dp); |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 3815 | intel_dp_set_common_rates(intel_dp); |
| 3816 | } |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3817 | |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3818 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3819 | return false; |
| 3820 | |
| 3821 | /* |
| 3822 | * Sink count can change between short pulse hpd hence |
| 3823 | * a member variable in intel_dp will track any changes |
| 3824 | * between short pulse interrupts. |
| 3825 | */ |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3826 | intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count); |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3827 | |
| 3828 | /* |
| 3829 | * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that |
| 3830 | * a dongle is present but no display. Unless we require to know |
| 3831 | * if a dongle is present or not, we don't need to update |
| 3832 | * downstream port information. So, an early return here saves |
| 3833 | * time from performing other operations which are not required. |
| 3834 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3835 | if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3836 | return false; |
| 3837 | |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 3838 | if (!drm_dp_is_branch(intel_dp->dpcd)) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3839 | return true; /* native DP sink */ |
| 3840 | |
| 3841 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) |
| 3842 | return true; /* no per-port downstream info */ |
| 3843 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3844 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
| 3845 | intel_dp->downstream_ports, |
| 3846 | DP_MAX_DOWNSTREAM_PORTS) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3847 | return false; /* downstream port status fetch failed */ |
| 3848 | |
| 3849 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3852 | static bool |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3853 | intel_dp_can_mst(struct intel_dp *intel_dp) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3854 | { |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3855 | u8 mstm_cap; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3856 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3857 | if (!i915_modparams.enable_dp_mst) |
Nathan Schulte | 7cc9613 | 2016-03-15 10:14:05 -0500 | [diff] [blame] | 3858 | return false; |
| 3859 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3860 | if (!intel_dp->can_mst) |
| 3861 | return false; |
| 3862 | |
| 3863 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) |
| 3864 | return false; |
| 3865 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3866 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1) |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3867 | return false; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3868 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3869 | return mstm_cap & DP_MST_CAP; |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | static void |
| 3873 | intel_dp_configure_mst(struct intel_dp *intel_dp) |
| 3874 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3875 | if (!i915_modparams.enable_dp_mst) |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3876 | return; |
| 3877 | |
| 3878 | if (!intel_dp->can_mst) |
| 3879 | return; |
| 3880 | |
| 3881 | intel_dp->is_mst = intel_dp_can_mst(intel_dp); |
| 3882 | |
| 3883 | if (intel_dp->is_mst) |
| 3884 | DRM_DEBUG_KMS("Sink is MST capable\n"); |
| 3885 | else |
| 3886 | DRM_DEBUG_KMS("Sink is not MST capable\n"); |
| 3887 | |
| 3888 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 3889 | intel_dp->is_mst); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3890 | } |
| 3891 | |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3892 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp, |
| 3893 | struct intel_crtc_state *crtc_state, bool disable_wa) |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3894 | { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3895 | 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] | 3896 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3897 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3898 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3899 | int ret = 0; |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3900 | int count = 0; |
| 3901 | int attempts = 10; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3902 | |
| 3903 | 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] | 3904 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3905 | ret = -EIO; |
| 3906 | goto out; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3907 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3908 | |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3909 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3910 | buf & ~DP_TEST_SINK_START) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3911 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3912 | ret = -EIO; |
| 3913 | goto out; |
| 3914 | } |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3915 | |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3916 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3917 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3918 | |
| 3919 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3920 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3921 | ret = -EIO; |
| 3922 | goto out; |
| 3923 | } |
| 3924 | count = buf & DP_TEST_COUNT_MASK; |
| 3925 | } while (--attempts && count); |
| 3926 | |
| 3927 | if (attempts == 0) { |
Rodrigo Vivi | dc5a903 | 2016-01-29 14:44:59 -0800 | [diff] [blame] | 3928 | 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] | 3929 | ret = -ETIMEDOUT; |
| 3930 | } |
| 3931 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3932 | out: |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3933 | if (disable_wa) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 3934 | hsw_enable_ips(crtc_state); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3935 | return ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3938 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp, |
| 3939 | struct intel_crtc_state *crtc_state) |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3940 | { |
| 3941 | 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] | 3942 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3943 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3944 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3945 | int ret; |
| 3946 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3947 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0) |
| 3948 | return -EIO; |
| 3949 | |
| 3950 | if (!(buf & DP_TEST_CRC_SUPPORTED)) |
| 3951 | return -ENOTTY; |
| 3952 | |
| 3953 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) |
| 3954 | return -EIO; |
| 3955 | |
Rodrigo Vivi | 6d8175d | 2015-11-05 10:50:22 -0800 | [diff] [blame] | 3956 | if (buf & DP_TEST_SINK_START) { |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3957 | ret = intel_dp_sink_crc_stop(intel_dp, crtc_state, false); |
Rodrigo Vivi | 6d8175d | 2015-11-05 10:50:22 -0800 | [diff] [blame] | 3958 | if (ret) |
| 3959 | return ret; |
| 3960 | } |
| 3961 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 3962 | hsw_disable_ips(crtc_state); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3963 | |
| 3964 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
| 3965 | buf | DP_TEST_SINK_START) < 0) { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 3966 | hsw_enable_ips(crtc_state); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3967 | return -EIO; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3968 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3969 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3970 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3971 | return 0; |
| 3972 | } |
| 3973 | |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3974 | int intel_dp_sink_crc(struct intel_dp *intel_dp, struct intel_crtc_state *crtc_state, u8 *crc) |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3975 | { |
| 3976 | 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] | 3977 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3978 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3979 | u8 buf; |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3980 | int count, ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3981 | int attempts = 6; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3982 | |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 3983 | ret = intel_dp_sink_crc_start(intel_dp, crtc_state); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3984 | if (ret) |
| 3985 | return ret; |
| 3986 | |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3987 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3988 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3989 | |
Rodrigo Vivi | 1dda5f9 | 2014-10-01 07:32:37 -0700 | [diff] [blame] | 3990 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3991 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3992 | ret = -EIO; |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3993 | goto stop; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3994 | } |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3995 | count = buf & DP_TEST_COUNT_MASK; |
Rodrigo Vivi | aabc95d | 2015-07-23 16:35:50 -0700 | [diff] [blame] | 3996 | |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3997 | } while (--attempts && count == 0); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3998 | |
| 3999 | if (attempts == 0) { |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 4000 | DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n"); |
| 4001 | ret = -ETIMEDOUT; |
| 4002 | goto stop; |
| 4003 | } |
| 4004 | |
| 4005 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) { |
| 4006 | ret = -EIO; |
| 4007 | goto stop; |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 4008 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 4009 | |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 4010 | stop: |
Maarten Lankhorst | 9331353 | 2017-11-10 12:34:59 +0100 | [diff] [blame] | 4011 | intel_dp_sink_crc_stop(intel_dp, crtc_state, true); |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 4012 | return ret; |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 4013 | } |
| 4014 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4015 | static bool |
| 4016 | intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 4017 | { |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4018 | return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4019 | sink_irq_vector) == 1; |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4022 | static bool |
| 4023 | intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 4024 | { |
Pandiyan, Dhinakaran | e8b2577 | 2017-09-18 15:21:39 -0700 | [diff] [blame] | 4025 | return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI, |
| 4026 | sink_irq_vector, DP_DPRX_ESI_LEN) == |
| 4027 | DP_DPRX_ESI_LEN; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4028 | } |
| 4029 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4030 | 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] | 4031 | { |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4032 | int status = 0; |
Manasi Navare | 140ef13 | 2017-06-08 13:41:03 -0700 | [diff] [blame] | 4033 | int test_link_rate; |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4034 | uint8_t test_lane_count, test_link_bw; |
| 4035 | /* (DP CTS 1.2) |
| 4036 | * 4.3.1.11 |
| 4037 | */ |
| 4038 | /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */ |
| 4039 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT, |
| 4040 | &test_lane_count); |
| 4041 | |
| 4042 | if (status <= 0) { |
| 4043 | DRM_DEBUG_KMS("Lane count read failed\n"); |
| 4044 | return DP_TEST_NAK; |
| 4045 | } |
| 4046 | test_lane_count &= DP_MAX_LANE_COUNT_MASK; |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4047 | |
| 4048 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE, |
| 4049 | &test_link_bw); |
| 4050 | if (status <= 0) { |
| 4051 | DRM_DEBUG_KMS("Link Rate read failed\n"); |
| 4052 | return DP_TEST_NAK; |
| 4053 | } |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4054 | test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw); |
Manasi Navare | 140ef13 | 2017-06-08 13:41:03 -0700 | [diff] [blame] | 4055 | |
| 4056 | /* Validate the requested link rate and lane count */ |
| 4057 | if (!intel_dp_link_params_valid(intel_dp, test_link_rate, |
| 4058 | test_lane_count)) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4059 | return DP_TEST_NAK; |
| 4060 | |
| 4061 | intel_dp->compliance.test_lane_count = test_lane_count; |
| 4062 | intel_dp->compliance.test_link_rate = test_link_rate; |
| 4063 | |
| 4064 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp) |
| 4068 | { |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4069 | uint8_t test_pattern; |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4070 | uint8_t test_misc; |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4071 | __be16 h_width, v_height; |
| 4072 | int status = 0; |
| 4073 | |
| 4074 | /* Read the TEST_PATTERN (DP CTS 3.1.5) */ |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4075 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN, |
| 4076 | &test_pattern); |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4077 | if (status <= 0) { |
| 4078 | DRM_DEBUG_KMS("Test pattern read failed\n"); |
| 4079 | return DP_TEST_NAK; |
| 4080 | } |
| 4081 | if (test_pattern != DP_COLOR_RAMP) |
| 4082 | return DP_TEST_NAK; |
| 4083 | |
| 4084 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI, |
| 4085 | &h_width, 2); |
| 4086 | if (status <= 0) { |
| 4087 | DRM_DEBUG_KMS("H Width read failed\n"); |
| 4088 | return DP_TEST_NAK; |
| 4089 | } |
| 4090 | |
| 4091 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI, |
| 4092 | &v_height, 2); |
| 4093 | if (status <= 0) { |
| 4094 | DRM_DEBUG_KMS("V Height read failed\n"); |
| 4095 | return DP_TEST_NAK; |
| 4096 | } |
| 4097 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4098 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0, |
| 4099 | &test_misc); |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4100 | if (status <= 0) { |
| 4101 | DRM_DEBUG_KMS("TEST MISC read failed\n"); |
| 4102 | return DP_TEST_NAK; |
| 4103 | } |
| 4104 | if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB) |
| 4105 | return DP_TEST_NAK; |
| 4106 | if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA) |
| 4107 | return DP_TEST_NAK; |
| 4108 | switch (test_misc & DP_TEST_BIT_DEPTH_MASK) { |
| 4109 | case DP_TEST_BIT_DEPTH_6: |
| 4110 | intel_dp->compliance.test_data.bpc = 6; |
| 4111 | break; |
| 4112 | case DP_TEST_BIT_DEPTH_8: |
| 4113 | intel_dp->compliance.test_data.bpc = 8; |
| 4114 | break; |
| 4115 | default: |
| 4116 | return DP_TEST_NAK; |
| 4117 | } |
| 4118 | |
| 4119 | intel_dp->compliance.test_data.video_pattern = test_pattern; |
| 4120 | intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width); |
| 4121 | intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height); |
| 4122 | /* Set test active flag here so userspace doesn't interrupt things */ |
| 4123 | intel_dp->compliance.test_active = 1; |
| 4124 | |
| 4125 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp) |
| 4129 | { |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4130 | uint8_t test_result = DP_TEST_ACK; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4131 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4132 | struct drm_connector *connector = &intel_connector->base; |
| 4133 | |
| 4134 | if (intel_connector->detect_edid == NULL || |
Daniel Vetter | ac6f2e2 | 2015-05-08 16:15:41 +0200 | [diff] [blame] | 4135 | connector->edid_corrupt || |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4136 | intel_dp->aux.i2c_defer_count > 6) { |
| 4137 | /* Check EDID read for NACKs, DEFERs and corruption |
| 4138 | * (DP CTS 1.2 Core r1.1) |
| 4139 | * 4.2.2.4 : Failed EDID read, I2C_NAK |
| 4140 | * 4.2.2.5 : Failed EDID read, I2C_DEFER |
| 4141 | * 4.2.2.6 : EDID corruption detected |
| 4142 | * Use failsafe mode for all cases |
| 4143 | */ |
| 4144 | if (intel_dp->aux.i2c_nack_count > 0 || |
| 4145 | intel_dp->aux.i2c_defer_count > 0) |
| 4146 | DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n", |
| 4147 | intel_dp->aux.i2c_nack_count, |
| 4148 | intel_dp->aux.i2c_defer_count); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4149 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4150 | } else { |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 4151 | struct edid *block = intel_connector->detect_edid; |
| 4152 | |
| 4153 | /* We have to write the checksum |
| 4154 | * of the last block read |
| 4155 | */ |
| 4156 | block += intel_connector->detect_edid->extensions; |
| 4157 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4158 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM, |
| 4159 | block->checksum) <= 0) |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4160 | DRM_DEBUG_KMS("Failed to write EDID checksum\n"); |
| 4161 | |
| 4162 | test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE; |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4163 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | /* Set test active flag here so userspace doesn't interrupt things */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4167 | intel_dp->compliance.test_active = 1; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4168 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4169 | return test_result; |
| 4170 | } |
| 4171 | |
| 4172 | static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp) |
| 4173 | { |
| 4174 | uint8_t test_result = DP_TEST_NAK; |
| 4175 | return test_result; |
| 4176 | } |
| 4177 | |
| 4178 | static void intel_dp_handle_test_request(struct intel_dp *intel_dp) |
| 4179 | { |
| 4180 | uint8_t response = DP_TEST_NAK; |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4181 | uint8_t request = 0; |
| 4182 | int status; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4183 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4184 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4185 | if (status <= 0) { |
| 4186 | DRM_DEBUG_KMS("Could not read test request from sink\n"); |
| 4187 | goto update_status; |
| 4188 | } |
| 4189 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4190 | switch (request) { |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4191 | case DP_TEST_LINK_TRAINING: |
| 4192 | DRM_DEBUG_KMS("LINK_TRAINING test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4193 | response = intel_dp_autotest_link_training(intel_dp); |
| 4194 | break; |
| 4195 | case DP_TEST_LINK_VIDEO_PATTERN: |
| 4196 | DRM_DEBUG_KMS("TEST_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4197 | response = intel_dp_autotest_video_pattern(intel_dp); |
| 4198 | break; |
| 4199 | case DP_TEST_LINK_EDID_READ: |
| 4200 | DRM_DEBUG_KMS("EDID test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4201 | response = intel_dp_autotest_edid(intel_dp); |
| 4202 | break; |
| 4203 | case DP_TEST_LINK_PHY_TEST_PATTERN: |
| 4204 | DRM_DEBUG_KMS("PHY_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4205 | response = intel_dp_autotest_phy_pattern(intel_dp); |
| 4206 | break; |
| 4207 | default: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4208 | DRM_DEBUG_KMS("Invalid test request '%02x'\n", request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4209 | break; |
| 4210 | } |
| 4211 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4212 | if (response & DP_TEST_ACK) |
| 4213 | intel_dp->compliance.test_type = request; |
| 4214 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4215 | update_status: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4216 | status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4217 | if (status <= 0) |
| 4218 | DRM_DEBUG_KMS("Could not write test response to sink\n"); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4221 | static int |
| 4222 | intel_dp_check_mst_status(struct intel_dp *intel_dp) |
| 4223 | { |
| 4224 | bool bret; |
| 4225 | |
| 4226 | if (intel_dp->is_mst) { |
Pandiyan, Dhinakaran | e8b2577 | 2017-09-18 15:21:39 -0700 | [diff] [blame] | 4227 | u8 esi[DP_DPRX_ESI_LEN] = { 0 }; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4228 | int ret = 0; |
| 4229 | int retry; |
| 4230 | bool handled; |
| 4231 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4232 | go_again: |
| 4233 | if (bret == true) { |
| 4234 | |
| 4235 | /* check link status - esi[10] = 0x200c */ |
Ville Syrjälä | 19e0b4c | 2016-08-05 19:05:42 +0300 | [diff] [blame] | 4236 | if (intel_dp->active_mst_links && |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 4237 | !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4238 | DRM_DEBUG_KMS("channel EQ not ok, retraining\n"); |
| 4239 | intel_dp_start_link_train(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4240 | intel_dp_stop_link_train(intel_dp); |
| 4241 | } |
| 4242 | |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4243 | DRM_DEBUG_KMS("got esi %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4244 | ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); |
| 4245 | |
| 4246 | if (handled) { |
| 4247 | for (retry = 0; retry < 3; retry++) { |
| 4248 | int wret; |
| 4249 | wret = drm_dp_dpcd_write(&intel_dp->aux, |
| 4250 | DP_SINK_COUNT_ESI+1, |
| 4251 | &esi[1], 3); |
| 4252 | if (wret == 3) { |
| 4253 | break; |
| 4254 | } |
| 4255 | } |
| 4256 | |
| 4257 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4258 | if (bret == true) { |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4259 | DRM_DEBUG_KMS("got esi2 %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4260 | goto go_again; |
| 4261 | } |
| 4262 | } else |
| 4263 | ret = 0; |
| 4264 | |
| 4265 | return ret; |
| 4266 | } else { |
| 4267 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4268 | DRM_DEBUG_KMS("failed to get ESI - device may have failed\n"); |
| 4269 | intel_dp->is_mst = false; |
| 4270 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); |
| 4271 | /* send a hotplug event */ |
| 4272 | drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev); |
| 4273 | } |
| 4274 | } |
| 4275 | return -EINVAL; |
| 4276 | } |
| 4277 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4278 | static bool |
| 4279 | intel_dp_needs_link_retrain(struct intel_dp *intel_dp) |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4280 | { |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4281 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 4282 | |
Ville Syrjälä | edb2e53 | 2018-01-17 21:21:49 +0200 | [diff] [blame] | 4283 | if (!intel_dp->link_trained) |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4284 | return false; |
Ville Syrjälä | edb2e53 | 2018-01-17 21:21:49 +0200 | [diff] [blame] | 4285 | |
| 4286 | if (!intel_dp_get_link_status(intel_dp, link_status)) |
| 4287 | return false; |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4288 | |
| 4289 | /* |
| 4290 | * Validate the cached values of intel_dp->link_rate and |
| 4291 | * intel_dp->lane_count before attempting to retrain. |
| 4292 | */ |
| 4293 | if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate, |
| 4294 | intel_dp->lane_count)) |
| 4295 | return false; |
| 4296 | |
| 4297 | /* Retrain if Channel EQ or CR not ok */ |
| 4298 | return !drm_dp_channel_eq_ok(link_status, intel_dp->lane_count); |
| 4299 | } |
| 4300 | |
| 4301 | /* |
| 4302 | * If display is now connected check links status, |
| 4303 | * there has been known issues of link loss triggering |
| 4304 | * long pulse. |
| 4305 | * |
| 4306 | * Some sinks (eg. ASUS PB287Q) seem to perform some |
| 4307 | * weird HPD ping pong during modesets. So we can apparently |
| 4308 | * end up with HPD going low during a modeset, and then |
| 4309 | * going back up soon after. And once that happens we must |
| 4310 | * retrain the link to get a picture. That's in case no |
| 4311 | * userspace component reacted to intermittent HPD dip. |
| 4312 | */ |
| 4313 | int intel_dp_retrain_link(struct intel_encoder *encoder, |
| 4314 | struct drm_modeset_acquire_ctx *ctx) |
| 4315 | { |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4316 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4317 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 4318 | struct intel_connector *connector = intel_dp->attached_connector; |
| 4319 | struct drm_connector_state *conn_state; |
| 4320 | struct intel_crtc_state *crtc_state; |
| 4321 | struct intel_crtc *crtc; |
| 4322 | int ret; |
| 4323 | |
| 4324 | /* FIXME handle the MST connectors as well */ |
| 4325 | |
| 4326 | if (!connector || connector->base.status != connector_status_connected) |
| 4327 | return 0; |
| 4328 | |
| 4329 | ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, |
| 4330 | ctx); |
| 4331 | if (ret) |
| 4332 | return ret; |
| 4333 | |
| 4334 | conn_state = connector->base.state; |
| 4335 | |
| 4336 | crtc = to_intel_crtc(conn_state->crtc); |
| 4337 | if (!crtc) |
| 4338 | return 0; |
| 4339 | |
| 4340 | ret = drm_modeset_lock(&crtc->base.mutex, ctx); |
| 4341 | if (ret) |
| 4342 | return ret; |
| 4343 | |
| 4344 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 4345 | |
| 4346 | WARN_ON(!intel_crtc_has_dp_encoder(crtc_state)); |
| 4347 | |
| 4348 | if (!crtc_state->base.active) |
| 4349 | return 0; |
| 4350 | |
| 4351 | if (conn_state->commit && |
| 4352 | !try_wait_for_completion(&conn_state->commit->hw_done)) |
| 4353 | return 0; |
| 4354 | |
| 4355 | if (!intel_dp_needs_link_retrain(intel_dp)) |
| 4356 | return 0; |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4357 | |
| 4358 | /* Suppress underruns caused by re-training */ |
| 4359 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
| 4360 | if (crtc->config->has_pch_encoder) |
| 4361 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4362 | intel_crtc_pch_transcoder(crtc), false); |
| 4363 | |
| 4364 | intel_dp_start_link_train(intel_dp); |
| 4365 | intel_dp_stop_link_train(intel_dp); |
| 4366 | |
| 4367 | /* Keep underrun reporting disabled until things are stable */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4368 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4369 | |
| 4370 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 4371 | if (crtc->config->has_pch_encoder) |
| 4372 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4373 | intel_crtc_pch_transcoder(crtc), true); |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4374 | |
| 4375 | return 0; |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4376 | } |
| 4377 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4378 | /* |
| 4379 | * If display is now connected check links status, |
| 4380 | * there has been known issues of link loss triggering |
| 4381 | * long pulse. |
| 4382 | * |
| 4383 | * Some sinks (eg. ASUS PB287Q) seem to perform some |
| 4384 | * weird HPD ping pong during modesets. So we can apparently |
| 4385 | * end up with HPD going low during a modeset, and then |
| 4386 | * going back up soon after. And once that happens we must |
| 4387 | * retrain the link to get a picture. That's in case no |
| 4388 | * userspace component reacted to intermittent HPD dip. |
| 4389 | */ |
| 4390 | static bool intel_dp_hotplug(struct intel_encoder *encoder, |
| 4391 | struct intel_connector *connector) |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4392 | { |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4393 | struct drm_modeset_acquire_ctx ctx; |
| 4394 | bool changed; |
| 4395 | int ret; |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4396 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4397 | changed = intel_encoder_hotplug(encoder, connector); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4398 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4399 | drm_modeset_acquire_init(&ctx, 0); |
| 4400 | |
| 4401 | for (;;) { |
| 4402 | ret = intel_dp_retrain_link(encoder, &ctx); |
| 4403 | |
| 4404 | if (ret == -EDEADLK) { |
| 4405 | drm_modeset_backoff(&ctx); |
| 4406 | continue; |
| 4407 | } |
| 4408 | |
| 4409 | break; |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4410 | } |
| 4411 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4412 | drm_modeset_drop_locks(&ctx); |
| 4413 | drm_modeset_acquire_fini(&ctx); |
| 4414 | WARN(ret, "Acquiring modeset locks failed with %i\n", ret); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4415 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4416 | return changed; |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4417 | } |
| 4418 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4419 | /* |
| 4420 | * According to DP spec |
| 4421 | * 5.1.2: |
| 4422 | * 1. Read DPCD |
| 4423 | * 2. Configure link according to Receiver Capabilities |
| 4424 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 4425 | * 4. Check link status on receipt of hot-plug interrupt |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4426 | * |
| 4427 | * intel_dp_short_pulse - handles short pulse interrupts |
| 4428 | * when full detection is not required. |
| 4429 | * Returns %true if short pulse is handled and full detection |
| 4430 | * is NOT required and %false otherwise. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4431 | */ |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4432 | static bool |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4433 | intel_dp_short_pulse(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4434 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4435 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4436 | u8 sink_irq_vector = 0; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4437 | u8 old_sink_count = intel_dp->sink_count; |
| 4438 | bool ret; |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4439 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4440 | /* |
| 4441 | * Clearing compliance test variables to allow capturing |
| 4442 | * of values for next automated test request. |
| 4443 | */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4444 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4445 | |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4446 | /* |
| 4447 | * Now read the DPCD to see if it's actually running |
| 4448 | * If the current value of sink count doesn't match with |
| 4449 | * the value that was stored earlier or dpcd read failed |
| 4450 | * we need to do full detection |
| 4451 | */ |
| 4452 | ret = intel_dp_get_dpcd(intel_dp); |
| 4453 | |
| 4454 | if ((old_sink_count != intel_dp->sink_count) || !ret) { |
| 4455 | /* No need to proceed if we are going to do full detect */ |
| 4456 | return false; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 4457 | } |
| 4458 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4459 | /* Try to read the source of the interrupt */ |
| 4460 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4461 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4462 | sink_irq_vector != 0) { |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4463 | /* Clear interrupt source */ |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4464 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4465 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4466 | sink_irq_vector); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4467 | |
| 4468 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4469 | intel_dp_handle_test_request(intel_dp); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4470 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4471 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4472 | } |
| 4473 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 4474 | /* defer to the hotplug work for link retraining if needed */ |
| 4475 | if (intel_dp_needs_link_retrain(intel_dp)) |
| 4476 | return false; |
Daniel Vetter | 42e5e65 | 2017-11-13 17:01:40 +0100 | [diff] [blame] | 4477 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4478 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 4479 | DRM_DEBUG_KMS("Link Training Compliance Test requested\n"); |
| 4480 | /* Send a Hotplug Uevent to userspace to start modeset */ |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4481 | drm_kms_helper_hotplug_event(&dev_priv->drm); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4482 | } |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4483 | |
| 4484 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4485 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4486 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4487 | /* XXX this is probably wrong for multiple downstream ports */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4488 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4489 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4490 | { |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4491 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4492 | uint8_t *dpcd = intel_dp->dpcd; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4493 | uint8_t type; |
| 4494 | |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4495 | if (lspcon->active) |
| 4496 | lspcon_resume(lspcon); |
| 4497 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4498 | if (!intel_dp_get_dpcd(intel_dp)) |
| 4499 | return connector_status_disconnected; |
| 4500 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4501 | if (intel_dp_is_edp(intel_dp)) |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 4502 | return connector_status_connected; |
| 4503 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4504 | /* if there's no downstream port, we're done */ |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 4505 | if (!drm_dp_is_branch(dpcd)) |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4506 | return connector_status_connected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4507 | |
| 4508 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4509 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 4510 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4511 | |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 4512 | return intel_dp->sink_count ? |
| 4513 | connector_status_connected : connector_status_disconnected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4514 | } |
| 4515 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4516 | if (intel_dp_can_mst(intel_dp)) |
| 4517 | return connector_status_connected; |
| 4518 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4519 | /* If no HPD, poke DDC gently */ |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 4520 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4521 | return connector_status_connected; |
| 4522 | |
| 4523 | /* Well we tried, say unknown for unreliable port types */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4524 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 4525 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 4526 | if (type == DP_DS_PORT_TYPE_VGA || |
| 4527 | type == DP_DS_PORT_TYPE_NON_EDID) |
| 4528 | return connector_status_unknown; |
| 4529 | } else { |
| 4530 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
| 4531 | DP_DWN_STRM_PORT_TYPE_MASK; |
| 4532 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || |
| 4533 | type == DP_DWN_STRM_PORT_TYPE_OTHER) |
| 4534 | return connector_status_unknown; |
| 4535 | } |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4536 | |
| 4537 | /* Anything else is out of spec, warn and ignore */ |
| 4538 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4539 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | static enum drm_connector_status |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4543 | edp_detect(struct intel_dp *intel_dp) |
| 4544 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4545 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4546 | enum drm_connector_status status; |
| 4547 | |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4548 | status = intel_panel_detect(dev_priv); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4549 | if (status == connector_status_unknown) |
| 4550 | status = connector_status_connected; |
| 4551 | |
| 4552 | return status; |
| 4553 | } |
| 4554 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4555 | static bool ibx_digital_port_connected(struct intel_encoder *encoder) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4556 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4557 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4558 | u32 bit; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 4559 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4560 | switch (encoder->hpd_pin) { |
| 4561 | case HPD_PORT_B: |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4562 | bit = SDE_PORTB_HOTPLUG; |
| 4563 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4564 | case HPD_PORT_C: |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4565 | bit = SDE_PORTC_HOTPLUG; |
| 4566 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4567 | case HPD_PORT_D: |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4568 | bit = SDE_PORTD_HOTPLUG; |
| 4569 | break; |
| 4570 | default: |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4571 | MISSING_CASE(encoder->hpd_pin); |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4572 | return false; |
| 4573 | } |
| 4574 | |
| 4575 | return I915_READ(SDEISR) & bit; |
| 4576 | } |
| 4577 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4578 | static bool cpt_digital_port_connected(struct intel_encoder *encoder) |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4579 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4580 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4581 | u32 bit; |
| 4582 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4583 | switch (encoder->hpd_pin) { |
| 4584 | case HPD_PORT_B: |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4585 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 4586 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4587 | case HPD_PORT_C: |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4588 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 4589 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4590 | case HPD_PORT_D: |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4591 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 4592 | break; |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4593 | default: |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4594 | MISSING_CASE(encoder->hpd_pin); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4595 | return false; |
| 4596 | } |
| 4597 | |
| 4598 | return I915_READ(SDEISR) & bit; |
| 4599 | } |
| 4600 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4601 | static bool spt_digital_port_connected(struct intel_encoder *encoder) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4602 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4603 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4604 | u32 bit; |
| 4605 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4606 | switch (encoder->hpd_pin) { |
| 4607 | case HPD_PORT_A: |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4608 | bit = SDE_PORTA_HOTPLUG_SPT; |
| 4609 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4610 | case HPD_PORT_E: |
Jani Nikula | a78695d | 2015-09-18 15:54:50 +0300 | [diff] [blame] | 4611 | bit = SDE_PORTE_HOTPLUG_SPT; |
| 4612 | break; |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4613 | default: |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4614 | return cpt_digital_port_connected(encoder); |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4615 | } |
Damien Lespiau | 1b46963 | 2012-12-13 16:09:01 +0000 | [diff] [blame] | 4616 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4617 | return I915_READ(SDEISR) & bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4618 | } |
| 4619 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4620 | static bool g4x_digital_port_connected(struct intel_encoder *encoder) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4621 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4622 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4623 | u32 bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4624 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4625 | switch (encoder->hpd_pin) { |
| 4626 | case HPD_PORT_B: |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4627 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; |
| 4628 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4629 | case HPD_PORT_C: |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4630 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; |
| 4631 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4632 | case HPD_PORT_D: |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4633 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; |
| 4634 | break; |
| 4635 | default: |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4636 | MISSING_CASE(encoder->hpd_pin); |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4637 | return false; |
| 4638 | } |
| 4639 | |
| 4640 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 4641 | } |
| 4642 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4643 | static bool gm45_digital_port_connected(struct intel_encoder *encoder) |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4644 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4645 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4646 | u32 bit; |
| 4647 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4648 | switch (encoder->hpd_pin) { |
| 4649 | case HPD_PORT_B: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4650 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4651 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4652 | case HPD_PORT_C: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4653 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4654 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4655 | case HPD_PORT_D: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4656 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4657 | break; |
| 4658 | default: |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4659 | MISSING_CASE(encoder->hpd_pin); |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4660 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4663 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
Dave Airlie | 2a592be | 2014-09-01 16:58:12 +1000 | [diff] [blame] | 4664 | } |
| 4665 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4666 | static bool ilk_digital_port_connected(struct intel_encoder *encoder) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4667 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4668 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4669 | |
| 4670 | if (encoder->hpd_pin == HPD_PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4671 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG; |
| 4672 | else |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4673 | return ibx_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4674 | } |
| 4675 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4676 | static bool snb_digital_port_connected(struct intel_encoder *encoder) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4677 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4678 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4679 | |
| 4680 | if (encoder->hpd_pin == HPD_PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4681 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG; |
| 4682 | else |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4683 | return cpt_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4684 | } |
| 4685 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4686 | static bool ivb_digital_port_connected(struct intel_encoder *encoder) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4687 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4688 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4689 | |
| 4690 | if (encoder->hpd_pin == HPD_PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4691 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB; |
| 4692 | else |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4693 | return cpt_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4694 | } |
| 4695 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4696 | static bool bdw_digital_port_connected(struct intel_encoder *encoder) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4697 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4698 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4699 | |
| 4700 | if (encoder->hpd_pin == HPD_PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4701 | return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG; |
| 4702 | else |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4703 | return cpt_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4704 | } |
| 4705 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4706 | static bool bxt_digital_port_connected(struct intel_encoder *encoder) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4707 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4708 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4709 | u32 bit; |
| 4710 | |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4711 | switch (encoder->hpd_pin) { |
| 4712 | case HPD_PORT_A: |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4713 | bit = BXT_DE_PORT_HP_DDIA; |
| 4714 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4715 | case HPD_PORT_B: |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4716 | bit = BXT_DE_PORT_HP_DDIB; |
| 4717 | break; |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4718 | case HPD_PORT_C: |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4719 | bit = BXT_DE_PORT_HP_DDIC; |
| 4720 | break; |
| 4721 | default: |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4722 | MISSING_CASE(encoder->hpd_pin); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4723 | return false; |
| 4724 | } |
| 4725 | |
| 4726 | return I915_READ(GEN8_DE_PORT_ISR) & bit; |
| 4727 | } |
| 4728 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4729 | /* |
| 4730 | * intel_digital_port_connected - is the specified port connected? |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4731 | * @encoder: intel_encoder |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4732 | * |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4733 | * Return %true if port is connected, %false otherwise. |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4734 | */ |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4735 | bool intel_digital_port_connected(struct intel_encoder *encoder) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4736 | { |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4737 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4738 | |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4739 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 4740 | if (IS_GM45(dev_priv)) |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4741 | return gm45_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4742 | else |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4743 | return g4x_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | if (IS_GEN5(dev_priv)) |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4747 | return ilk_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4748 | else if (IS_GEN6(dev_priv)) |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4749 | return snb_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4750 | else if (IS_GEN7(dev_priv)) |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4751 | return ivb_digital_port_connected(encoder); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4752 | else if (IS_GEN8(dev_priv)) |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4753 | return bdw_digital_port_connected(encoder); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4754 | else if (IS_GEN9_LP(dev_priv)) |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4755 | return bxt_digital_port_connected(encoder); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4756 | else |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4757 | return spt_digital_port_connected(encoder); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4758 | } |
| 4759 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4760 | static struct edid * |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4761 | intel_dp_get_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4762 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4763 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4764 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4765 | /* use cached edid if we have one */ |
| 4766 | if (intel_connector->edid) { |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4767 | /* invalid edid */ |
| 4768 | if (IS_ERR(intel_connector->edid)) |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4769 | return NULL; |
| 4770 | |
Jani Nikula | 55e9ede | 2013-10-01 10:38:54 +0300 | [diff] [blame] | 4771 | return drm_edid_duplicate(intel_connector->edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4772 | } else |
| 4773 | return drm_get_edid(&intel_connector->base, |
| 4774 | &intel_dp->aux.ddc); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4777 | static void |
| 4778 | intel_dp_set_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4779 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4780 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4781 | struct edid *edid; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4782 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4783 | intel_dp_unset_edid(intel_dp); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4784 | edid = intel_dp_get_edid(intel_dp); |
| 4785 | intel_connector->detect_edid = edid; |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4786 | |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 4787 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4788 | } |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4789 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4790 | static void |
| 4791 | intel_dp_unset_edid(struct intel_dp *intel_dp) |
| 4792 | { |
| 4793 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4794 | |
| 4795 | kfree(intel_connector->detect_edid); |
| 4796 | intel_connector->detect_edid = NULL; |
| 4797 | |
| 4798 | intel_dp->has_audio = false; |
| 4799 | } |
| 4800 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4801 | static int |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4802 | intel_dp_long_pulse(struct intel_connector *connector) |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4803 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4804 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
| 4805 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4806 | enum drm_connector_status status; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4807 | u8 sink_irq_vector = 0; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4808 | |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4809 | WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex)); |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4810 | |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4811 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4812 | |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4813 | /* Can't disconnect eDP, but you can close the lid... */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4814 | if (intel_dp_is_edp(intel_dp)) |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4815 | status = edp_detect(intel_dp); |
Rodrigo Vivi | 7533eb4 | 2018-01-29 15:22:20 -0800 | [diff] [blame] | 4816 | else if (intel_digital_port_connected(&dp_to_dig_port(intel_dp)->base)) |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4817 | status = intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4818 | else |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4819 | status = connector_status_disconnected; |
| 4820 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4821 | if (status == connector_status_disconnected) { |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4822 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4823 | |
jim.bride@linux.intel.com | 0e505a0 | 2016-04-11 10:11:24 -0700 | [diff] [blame] | 4824 | if (intel_dp->is_mst) { |
| 4825 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4826 | intel_dp->is_mst, |
| 4827 | intel_dp->mst_mgr.mst_state); |
| 4828 | intel_dp->is_mst = false; |
| 4829 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4830 | intel_dp->is_mst); |
| 4831 | } |
| 4832 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4833 | goto out; |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4834 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4835 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4836 | if (intel_dp->reset_link_params) { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 4837 | /* Initial max link lane count */ |
| 4838 | intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp); |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4839 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 4840 | /* Initial max link rate */ |
| 4841 | intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp); |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4842 | |
| 4843 | intel_dp->reset_link_params = false; |
| 4844 | } |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4845 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4846 | intel_dp_print_rates(intel_dp); |
| 4847 | |
Jani Nikula | 84c3675 | 2017-05-18 14:10:23 +0300 | [diff] [blame] | 4848 | drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, |
| 4849 | drm_dp_is_branch(intel_dp->dpcd)); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 4850 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4851 | intel_dp_configure_mst(intel_dp); |
| 4852 | |
| 4853 | if (intel_dp->is_mst) { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4854 | /* |
| 4855 | * If we are in MST mode then this connector |
| 4856 | * won't appear connected or have anything |
| 4857 | * with EDID on it |
| 4858 | */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4859 | status = connector_status_disconnected; |
| 4860 | goto out; |
| 4861 | } |
| 4862 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4863 | /* |
| 4864 | * Clearing NACK and defer counts to get their exact values |
| 4865 | * while reading EDID which are required by Compliance tests |
| 4866 | * 4.2.2.4 and 4.2.2.5 |
| 4867 | */ |
| 4868 | intel_dp->aux.i2c_nack_count = 0; |
| 4869 | intel_dp->aux.i2c_defer_count = 0; |
| 4870 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4871 | intel_dp_set_edid(intel_dp); |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4872 | if (intel_dp_is_edp(intel_dp) || connector->detect_edid) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4873 | status = connector_status_connected; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4874 | intel_dp->detect_done = true; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4875 | |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4876 | /* Try to read the source of the interrupt */ |
| 4877 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4878 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4879 | sink_irq_vector != 0) { |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4880 | /* Clear interrupt source */ |
| 4881 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4882 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4883 | sink_irq_vector); |
| 4884 | |
| 4885 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
| 4886 | intel_dp_handle_test_request(intel_dp); |
| 4887 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4888 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4889 | } |
| 4890 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4891 | out: |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4892 | if (status != connector_status_connected && !intel_dp->is_mst) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4893 | intel_dp_unset_edid(intel_dp); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4894 | |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 4895 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4896 | return status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4897 | } |
| 4898 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4899 | static int |
| 4900 | intel_dp_detect(struct drm_connector *connector, |
| 4901 | struct drm_modeset_acquire_ctx *ctx, |
| 4902 | bool force) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4903 | { |
| 4904 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4905 | int status = connector->status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4906 | |
| 4907 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4908 | connector->base.id, connector->name); |
| 4909 | |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4910 | /* If full detect is not performed yet, do a full detect */ |
Daniel Vetter | 42e5e65 | 2017-11-13 17:01:40 +0100 | [diff] [blame] | 4911 | if (!intel_dp->detect_done) { |
| 4912 | struct drm_crtc *crtc; |
| 4913 | int ret; |
| 4914 | |
| 4915 | crtc = connector->state->crtc; |
| 4916 | if (crtc) { |
| 4917 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 4918 | if (ret) |
| 4919 | return ret; |
| 4920 | } |
| 4921 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4922 | status = intel_dp_long_pulse(intel_dp->attached_connector); |
Daniel Vetter | 42e5e65 | 2017-11-13 17:01:40 +0100 | [diff] [blame] | 4923 | } |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4924 | |
| 4925 | intel_dp->detect_done = false; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4926 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4927 | return status; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4928 | } |
| 4929 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4930 | static void |
| 4931 | intel_dp_force(struct drm_connector *connector) |
| 4932 | { |
| 4933 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 4934 | 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] | 4935 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4936 | |
| 4937 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4938 | connector->base.id, connector->name); |
| 4939 | intel_dp_unset_edid(intel_dp); |
| 4940 | |
| 4941 | if (connector->status != connector_status_connected) |
| 4942 | return; |
| 4943 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4944 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4945 | |
| 4946 | intel_dp_set_edid(intel_dp); |
| 4947 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4948 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4949 | } |
| 4950 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4951 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 4952 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4953 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4954 | struct edid *edid; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4955 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4956 | edid = intel_connector->detect_edid; |
| 4957 | if (edid) { |
| 4958 | int ret = intel_connector_update_modes(connector, edid); |
| 4959 | if (ret) |
| 4960 | return ret; |
| 4961 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4962 | |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4963 | /* if eDP has no EDID, fall back to fixed mode */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4964 | if (intel_dp_is_edp(intel_attached_dp(connector)) && |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4965 | intel_connector->panel.fixed_mode) { |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4966 | struct drm_display_mode *mode; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4967 | |
| 4968 | mode = drm_mode_duplicate(connector->dev, |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4969 | intel_connector->panel.fixed_mode); |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4970 | if (mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4971 | drm_mode_probed_add(connector, mode); |
| 4972 | return 1; |
| 4973 | } |
| 4974 | } |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4975 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4976 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4979 | static int |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4980 | intel_dp_connector_register(struct drm_connector *connector) |
| 4981 | { |
| 4982 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 4983 | int ret; |
| 4984 | |
| 4985 | ret = intel_connector_register(connector); |
| 4986 | if (ret) |
| 4987 | return ret; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4988 | |
| 4989 | i915_debugfs_connector_add(connector); |
| 4990 | |
| 4991 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
| 4992 | intel_dp->aux.name, connector->kdev->kobj.name); |
| 4993 | |
| 4994 | intel_dp->aux.dev = connector->kdev; |
| 4995 | return drm_dp_aux_register(&intel_dp->aux); |
| 4996 | } |
| 4997 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4998 | static void |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4999 | intel_dp_connector_unregister(struct drm_connector *connector) |
| 5000 | { |
| 5001 | drm_dp_aux_unregister(&intel_attached_dp(connector)->aux); |
| 5002 | intel_connector_unregister(connector); |
| 5003 | } |
| 5004 | |
| 5005 | static void |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 5006 | intel_dp_connector_destroy(struct drm_connector *connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5007 | { |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 5008 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 5009 | |
Chris Wilson | 10e972d | 2014-09-04 21:43:45 +0100 | [diff] [blame] | 5010 | kfree(intel_connector->detect_edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 5011 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 5012 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 5013 | kfree(intel_connector->edid); |
| 5014 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5015 | /* |
| 5016 | * Can't call intel_dp_is_edp() since the encoder may have been |
| 5017 | * destroyed already. |
| 5018 | */ |
Paulo Zanoni | acd8db10 | 2013-06-12 17:27:23 -0300 | [diff] [blame] | 5019 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 5020 | intel_panel_fini(&intel_connector->panel); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 5021 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5022 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 5023 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 5026 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5027 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 5028 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 5029 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5030 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5031 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5032 | if (intel_dp_is_edp(intel_dp)) { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 5033 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 5034 | /* |
| 5035 | * vdd might still be enabled do to the delayed vdd off. |
| 5036 | * Make sure vdd is actually turned off here. |
| 5037 | */ |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 5038 | pps_lock(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 5039 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 5040 | pps_unlock(intel_dp); |
| 5041 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5042 | if (intel_dp->edp_notifier.notifier_call) { |
| 5043 | unregister_reboot_notifier(&intel_dp->edp_notifier); |
| 5044 | intel_dp->edp_notifier.notifier_call = NULL; |
| 5045 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 5046 | } |
Chris Wilson | 9968188 | 2016-06-20 09:29:17 +0100 | [diff] [blame] | 5047 | |
| 5048 | intel_dp_aux_fini(intel_dp); |
| 5049 | |
Imre Deak | c8bd0e4 | 2014-12-12 17:57:38 +0200 | [diff] [blame] | 5050 | drm_encoder_cleanup(encoder); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 5051 | kfree(intel_dig_port); |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5052 | } |
| 5053 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 5054 | void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 5055 | { |
| 5056 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 5057 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5058 | if (!intel_dp_is_edp(intel_dp)) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 5059 | return; |
| 5060 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 5061 | /* |
| 5062 | * vdd might still be enabled do to the delayed vdd off. |
| 5063 | * Make sure vdd is actually turned off here. |
| 5064 | */ |
Ville Syrjälä | afa4e53 | 2014-11-25 15:43:48 +0200 | [diff] [blame] | 5065 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 5066 | pps_lock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 5067 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 5068 | pps_unlock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 5069 | } |
| 5070 | |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5071 | static |
| 5072 | int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *intel_dig_port, |
| 5073 | u8 *an) |
| 5074 | { |
| 5075 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_dig_port->base.base); |
Ville Syrjälä | 32078b72 | 2018-02-22 23:28:02 +0200 | [diff] [blame] | 5076 | static const struct drm_dp_aux_msg msg = { |
| 5077 | .request = DP_AUX_NATIVE_WRITE, |
| 5078 | .address = DP_AUX_HDCP_AKSV, |
| 5079 | .size = DRM_HDCP_KSV_LEN, |
| 5080 | }; |
| 5081 | uint8_t txbuf[HEADER_SIZE + DRM_HDCP_KSV_LEN] = {}, rxbuf[2], reply = 0; |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5082 | ssize_t dpcd_ret; |
| 5083 | int ret; |
| 5084 | |
| 5085 | /* Output An first, that's easy */ |
| 5086 | dpcd_ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux, DP_AUX_HDCP_AN, |
| 5087 | an, DRM_HDCP_AN_LEN); |
| 5088 | if (dpcd_ret != DRM_HDCP_AN_LEN) { |
| 5089 | DRM_ERROR("Failed to write An over DP/AUX (%zd)\n", dpcd_ret); |
| 5090 | return dpcd_ret >= 0 ? -EIO : dpcd_ret; |
| 5091 | } |
| 5092 | |
| 5093 | /* |
| 5094 | * Since Aksv is Oh-So-Secret, we can't access it in software. So in |
| 5095 | * order to get it on the wire, we need to create the AUX header as if |
| 5096 | * we were writing the data, and then tickle the hardware to output the |
| 5097 | * data once the header is sent out. |
| 5098 | */ |
Ville Syrjälä | 32078b72 | 2018-02-22 23:28:02 +0200 | [diff] [blame] | 5099 | intel_dp_aux_header(txbuf, &msg); |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5100 | |
Ville Syrjälä | 32078b72 | 2018-02-22 23:28:02 +0200 | [diff] [blame] | 5101 | ret = intel_dp_aux_xfer(intel_dp, txbuf, HEADER_SIZE + msg.size, |
Ville Syrjälä | 8159c79 | 2018-02-22 23:27:32 +0200 | [diff] [blame] | 5102 | rxbuf, sizeof(rxbuf), |
| 5103 | DP_AUX_CH_CTL_AUX_AKSV_SELECT); |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5104 | if (ret < 0) { |
| 5105 | DRM_ERROR("Write Aksv over DP/AUX failed (%d)\n", ret); |
| 5106 | return ret; |
| 5107 | } else if (ret == 0) { |
| 5108 | DRM_ERROR("Aksv write over DP/AUX was empty\n"); |
| 5109 | return -EIO; |
| 5110 | } |
| 5111 | |
| 5112 | reply = (rxbuf[0] >> 4) & DP_AUX_NATIVE_REPLY_MASK; |
| 5113 | return reply == DP_AUX_NATIVE_REPLY_ACK ? 0 : -EIO; |
| 5114 | } |
| 5115 | |
| 5116 | static int intel_dp_hdcp_read_bksv(struct intel_digital_port *intel_dig_port, |
| 5117 | u8 *bksv) |
| 5118 | { |
| 5119 | ssize_t ret; |
| 5120 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BKSV, bksv, |
| 5121 | DRM_HDCP_KSV_LEN); |
| 5122 | if (ret != DRM_HDCP_KSV_LEN) { |
| 5123 | DRM_ERROR("Read Bksv from DP/AUX failed (%zd)\n", ret); |
| 5124 | return ret >= 0 ? -EIO : ret; |
| 5125 | } |
| 5126 | return 0; |
| 5127 | } |
| 5128 | |
| 5129 | static int intel_dp_hdcp_read_bstatus(struct intel_digital_port *intel_dig_port, |
| 5130 | u8 *bstatus) |
| 5131 | { |
| 5132 | ssize_t ret; |
| 5133 | /* |
| 5134 | * For some reason the HDMI and DP HDCP specs call this register |
| 5135 | * definition by different names. In the HDMI spec, it's called BSTATUS, |
| 5136 | * but in DP it's called BINFO. |
| 5137 | */ |
| 5138 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BINFO, |
| 5139 | bstatus, DRM_HDCP_BSTATUS_LEN); |
| 5140 | if (ret != DRM_HDCP_BSTATUS_LEN) { |
| 5141 | DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret); |
| 5142 | return ret >= 0 ? -EIO : ret; |
| 5143 | } |
| 5144 | return 0; |
| 5145 | } |
| 5146 | |
| 5147 | static |
Ramalingam C | 791a98d | 2018-02-03 03:39:08 +0530 | [diff] [blame] | 5148 | int intel_dp_hdcp_read_bcaps(struct intel_digital_port *intel_dig_port, |
| 5149 | u8 *bcaps) |
| 5150 | { |
| 5151 | ssize_t ret; |
| 5152 | |
| 5153 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BCAPS, |
| 5154 | bcaps, 1); |
| 5155 | if (ret != 1) { |
| 5156 | DRM_ERROR("Read bcaps from DP/AUX failed (%zd)\n", ret); |
| 5157 | return ret >= 0 ? -EIO : ret; |
| 5158 | } |
| 5159 | |
| 5160 | return 0; |
| 5161 | } |
| 5162 | |
| 5163 | static |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5164 | int intel_dp_hdcp_repeater_present(struct intel_digital_port *intel_dig_port, |
| 5165 | bool *repeater_present) |
| 5166 | { |
| 5167 | ssize_t ret; |
| 5168 | u8 bcaps; |
Ramalingam C | 791a98d | 2018-02-03 03:39:08 +0530 | [diff] [blame] | 5169 | |
| 5170 | ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps); |
| 5171 | if (ret) |
| 5172 | return ret; |
| 5173 | |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5174 | *repeater_present = bcaps & DP_BCAPS_REPEATER_PRESENT; |
| 5175 | return 0; |
| 5176 | } |
| 5177 | |
| 5178 | static |
| 5179 | int intel_dp_hdcp_read_ri_prime(struct intel_digital_port *intel_dig_port, |
| 5180 | u8 *ri_prime) |
| 5181 | { |
| 5182 | ssize_t ret; |
| 5183 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_RI_PRIME, |
| 5184 | ri_prime, DRM_HDCP_RI_LEN); |
| 5185 | if (ret != DRM_HDCP_RI_LEN) { |
| 5186 | DRM_ERROR("Read Ri' from DP/AUX failed (%zd)\n", ret); |
| 5187 | return ret >= 0 ? -EIO : ret; |
| 5188 | } |
| 5189 | return 0; |
| 5190 | } |
| 5191 | |
| 5192 | static |
| 5193 | int intel_dp_hdcp_read_ksv_ready(struct intel_digital_port *intel_dig_port, |
| 5194 | bool *ksv_ready) |
| 5195 | { |
| 5196 | ssize_t ret; |
| 5197 | u8 bstatus; |
| 5198 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS, |
| 5199 | &bstatus, 1); |
| 5200 | if (ret != 1) { |
| 5201 | DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret); |
| 5202 | return ret >= 0 ? -EIO : ret; |
| 5203 | } |
| 5204 | *ksv_ready = bstatus & DP_BSTATUS_READY; |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
| 5208 | static |
| 5209 | int intel_dp_hdcp_read_ksv_fifo(struct intel_digital_port *intel_dig_port, |
| 5210 | int num_downstream, u8 *ksv_fifo) |
| 5211 | { |
| 5212 | ssize_t ret; |
| 5213 | int i; |
| 5214 | |
| 5215 | /* KSV list is read via 15 byte window (3 entries @ 5 bytes each) */ |
| 5216 | for (i = 0; i < num_downstream; i += 3) { |
| 5217 | size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN; |
| 5218 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, |
| 5219 | DP_AUX_HDCP_KSV_FIFO, |
| 5220 | ksv_fifo + i * DRM_HDCP_KSV_LEN, |
| 5221 | len); |
| 5222 | if (ret != len) { |
| 5223 | DRM_ERROR("Read ksv[%d] from DP/AUX failed (%zd)\n", i, |
| 5224 | ret); |
| 5225 | return ret >= 0 ? -EIO : ret; |
| 5226 | } |
| 5227 | } |
| 5228 | return 0; |
| 5229 | } |
| 5230 | |
| 5231 | static |
| 5232 | int intel_dp_hdcp_read_v_prime_part(struct intel_digital_port *intel_dig_port, |
| 5233 | int i, u32 *part) |
| 5234 | { |
| 5235 | ssize_t ret; |
| 5236 | |
| 5237 | if (i >= DRM_HDCP_V_PRIME_NUM_PARTS) |
| 5238 | return -EINVAL; |
| 5239 | |
| 5240 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, |
| 5241 | DP_AUX_HDCP_V_PRIME(i), part, |
| 5242 | DRM_HDCP_V_PRIME_PART_LEN); |
| 5243 | if (ret != DRM_HDCP_V_PRIME_PART_LEN) { |
| 5244 | DRM_ERROR("Read v'[%d] from DP/AUX failed (%zd)\n", i, ret); |
| 5245 | return ret >= 0 ? -EIO : ret; |
| 5246 | } |
| 5247 | return 0; |
| 5248 | } |
| 5249 | |
| 5250 | static |
| 5251 | int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *intel_dig_port, |
| 5252 | bool enable) |
| 5253 | { |
| 5254 | /* Not used for single stream DisplayPort setups */ |
| 5255 | return 0; |
| 5256 | } |
| 5257 | |
| 5258 | static |
| 5259 | bool intel_dp_hdcp_check_link(struct intel_digital_port *intel_dig_port) |
| 5260 | { |
| 5261 | ssize_t ret; |
| 5262 | u8 bstatus; |
Chris Wilson | b7fc1a9 | 2018-01-18 16:10:25 +0000 | [diff] [blame] | 5263 | |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5264 | ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS, |
| 5265 | &bstatus, 1); |
| 5266 | if (ret != 1) { |
| 5267 | DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret); |
Chris Wilson | b7fc1a9 | 2018-01-18 16:10:25 +0000 | [diff] [blame] | 5268 | return false; |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5269 | } |
Chris Wilson | b7fc1a9 | 2018-01-18 16:10:25 +0000 | [diff] [blame] | 5270 | |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5271 | return !(bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ)); |
| 5272 | } |
| 5273 | |
Ramalingam C | 791a98d | 2018-02-03 03:39:08 +0530 | [diff] [blame] | 5274 | static |
| 5275 | int intel_dp_hdcp_capable(struct intel_digital_port *intel_dig_port, |
| 5276 | bool *hdcp_capable) |
| 5277 | { |
| 5278 | ssize_t ret; |
| 5279 | u8 bcaps; |
| 5280 | |
| 5281 | ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps); |
| 5282 | if (ret) |
| 5283 | return ret; |
| 5284 | |
| 5285 | *hdcp_capable = bcaps & DP_BCAPS_HDCP_CAPABLE; |
| 5286 | return 0; |
| 5287 | } |
| 5288 | |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5289 | static const struct intel_hdcp_shim intel_dp_hdcp_shim = { |
| 5290 | .write_an_aksv = intel_dp_hdcp_write_an_aksv, |
| 5291 | .read_bksv = intel_dp_hdcp_read_bksv, |
| 5292 | .read_bstatus = intel_dp_hdcp_read_bstatus, |
| 5293 | .repeater_present = intel_dp_hdcp_repeater_present, |
| 5294 | .read_ri_prime = intel_dp_hdcp_read_ri_prime, |
| 5295 | .read_ksv_ready = intel_dp_hdcp_read_ksv_ready, |
| 5296 | .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo, |
| 5297 | .read_v_prime_part = intel_dp_hdcp_read_v_prime_part, |
| 5298 | .toggle_signalling = intel_dp_hdcp_toggle_signalling, |
| 5299 | .check_link = intel_dp_hdcp_check_link, |
Ramalingam C | 791a98d | 2018-02-03 03:39:08 +0530 | [diff] [blame] | 5300 | .hdcp_capable = intel_dp_hdcp_capable, |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5301 | }; |
| 5302 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5303 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
| 5304 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 5305 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5306 | |
| 5307 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5308 | |
| 5309 | if (!edp_have_panel_vdd(intel_dp)) |
| 5310 | return; |
| 5311 | |
| 5312 | /* |
| 5313 | * The VDD bit needs a power domain reference, so if the bit is |
| 5314 | * already enabled when we boot or resume, grab this reference and |
| 5315 | * schedule a vdd off, so we don't hold on to the reference |
| 5316 | * indefinitely. |
| 5317 | */ |
| 5318 | 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] | 5319 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5320 | |
| 5321 | edp_panel_vdd_schedule_off(intel_dp); |
| 5322 | } |
| 5323 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5324 | static enum pipe vlv_active_pipe(struct intel_dp *intel_dp) |
| 5325 | { |
| 5326 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 5327 | |
| 5328 | if ((intel_dp->DP & DP_PORT_EN) == 0) |
| 5329 | return INVALID_PIPE; |
| 5330 | |
| 5331 | if (IS_CHERRYVIEW(dev_priv)) |
| 5332 | return DP_PORT_TO_PIPE_CHV(intel_dp->DP); |
| 5333 | else |
| 5334 | return PORT_TO_PIPE(intel_dp->DP); |
| 5335 | } |
| 5336 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 5337 | void intel_dp_encoder_reset(struct drm_encoder *encoder) |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5338 | { |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5339 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5340 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 5341 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5342 | |
| 5343 | if (!HAS_DDI(dev_priv)) |
| 5344 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5345 | |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5346 | if (lspcon->active) |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 5347 | lspcon_resume(lspcon); |
| 5348 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5349 | intel_dp->reset_link_params = true; |
| 5350 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5351 | pps_lock(intel_dp); |
| 5352 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5353 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5354 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 5355 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5356 | if (intel_dp_is_edp(intel_dp)) { |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5357 | /* Reinit the power sequencer, in case BIOS did something with it. */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5358 | intel_dp_pps_init(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5359 | intel_edp_panel_vdd_sanitize(intel_dp); |
| 5360 | } |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5361 | |
| 5362 | pps_unlock(intel_dp); |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5363 | } |
| 5364 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5365 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 5366 | .force = intel_dp_force, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5367 | .fill_modes = drm_helper_probe_single_connector_modes, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5368 | .atomic_get_property = intel_digital_connector_atomic_get_property, |
| 5369 | .atomic_set_property = intel_digital_connector_atomic_set_property, |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5370 | .late_register = intel_dp_connector_register, |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 5371 | .early_unregister = intel_dp_connector_unregister, |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 5372 | .destroy = intel_dp_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 5373 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5374 | .atomic_duplicate_state = intel_digital_connector_duplicate_state, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5375 | }; |
| 5376 | |
| 5377 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 5378 | .detect_ctx = intel_dp_detect, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5379 | .get_modes = intel_dp_get_modes, |
| 5380 | .mode_valid = intel_dp_mode_valid, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5381 | .atomic_check = intel_digital_connector_atomic_check, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5382 | }; |
| 5383 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5384 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5385 | .reset = intel_dp_encoder_reset, |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5386 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5387 | }; |
| 5388 | |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5389 | enum irqreturn |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5390 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
| 5391 | { |
| 5392 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 5393 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5394 | enum irqreturn ret = IRQ_NONE; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5395 | |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5396 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
| 5397 | /* |
| 5398 | * vdd off can generate a long pulse on eDP which |
| 5399 | * would require vdd on to handle it, and thus we |
| 5400 | * would end up in an endless cycle of |
| 5401 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." |
| 5402 | */ |
| 5403 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5404 | port_name(intel_dig_port->base.port)); |
Ville Syrjälä | a8b3d52f8 | 2015-02-10 14:11:46 +0200 | [diff] [blame] | 5405 | return IRQ_HANDLED; |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5406 | } |
| 5407 | |
Ville Syrjälä | 26fbb77 | 2014-08-11 18:37:37 +0300 | [diff] [blame] | 5408 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5409 | port_name(intel_dig_port->base.port), |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5410 | long_hpd ? "long" : "short"); |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5411 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5412 | if (long_hpd) { |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5413 | intel_dp->reset_link_params = true; |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5414 | intel_dp->detect_done = false; |
| 5415 | return IRQ_NONE; |
| 5416 | } |
| 5417 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5418 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5419 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5420 | if (intel_dp->is_mst) { |
| 5421 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) { |
| 5422 | /* |
| 5423 | * If we were in MST mode, and device is not |
| 5424 | * there, get out of MST mode |
| 5425 | */ |
| 5426 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 5427 | intel_dp->is_mst, intel_dp->mst_mgr.mst_state); |
| 5428 | intel_dp->is_mst = false; |
| 5429 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 5430 | intel_dp->is_mst); |
| 5431 | intel_dp->detect_done = false; |
| 5432 | goto put_power; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5433 | } |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5434 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5435 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5436 | if (!intel_dp->is_mst) { |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 5437 | bool handled; |
Daniel Vetter | 42e5e65 | 2017-11-13 17:01:40 +0100 | [diff] [blame] | 5438 | |
| 5439 | handled = intel_dp_short_pulse(intel_dp); |
| 5440 | |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 5441 | /* Short pulse can signify loss of hdcp authentication */ |
| 5442 | intel_hdcp_check_link(intel_dp->attached_connector); |
| 5443 | |
Daniel Vetter | 42e5e65 | 2017-11-13 17:01:40 +0100 | [diff] [blame] | 5444 | if (!handled) { |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5445 | intel_dp->detect_done = false; |
| 5446 | goto put_power; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 5447 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5448 | } |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5449 | |
| 5450 | ret = IRQ_HANDLED; |
| 5451 | |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5452 | put_power: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5453 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5454 | |
| 5455 | return ret; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5456 | } |
| 5457 | |
Rodrigo Vivi | 477ec32 | 2015-08-06 15:51:39 +0800 | [diff] [blame] | 5458 | /* check the VBT to see whether the eDP is on another port */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 5459 | bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port) |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 5460 | { |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5461 | /* |
| 5462 | * eDP not supported on g4x. so bail out early just |
| 5463 | * for a bit extra safety in case the VBT is bonkers. |
| 5464 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5465 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5466 | return false; |
| 5467 | |
Imre Deak | a98d9c1 | 2016-12-21 12:17:24 +0200 | [diff] [blame] | 5468 | if (INTEL_GEN(dev_priv) < 9 && port == PORT_A) |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5469 | return true; |
| 5470 | |
Jani Nikula | 951d9ef | 2016-03-16 12:43:31 +0200 | [diff] [blame] | 5471 | return intel_bios_is_port_edp(dev_priv, port); |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 5472 | } |
| 5473 | |
Maarten Lankhorst | 200819a | 2017-04-10 12:51:10 +0200 | [diff] [blame] | 5474 | static void |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5475 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 5476 | { |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5477 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Ville Syrjälä | 68ec073 | 2017-11-29 18:43:02 +0200 | [diff] [blame] | 5478 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5479 | |
Ville Syrjälä | 68ec073 | 2017-11-29 18:43:02 +0200 | [diff] [blame] | 5480 | if (!IS_G4X(dev_priv) && port != PORT_A) |
| 5481 | intel_attach_force_audio_property(connector); |
| 5482 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 5483 | intel_attach_broadcast_rgb_property(connector); |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5484 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5485 | if (intel_dp_is_edp(intel_dp)) { |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5486 | u32 allowed_scalers; |
| 5487 | |
| 5488 | allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN); |
| 5489 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 5490 | allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER); |
| 5491 | |
| 5492 | drm_connector_attach_scaling_mode_property(connector, allowed_scalers); |
| 5493 | |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 5494 | connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT; |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5495 | |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5496 | } |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5497 | } |
| 5498 | |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5499 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
| 5500 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 5501 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5502 | intel_dp->last_power_on = jiffies; |
| 5503 | intel_dp->last_backlight_off = jiffies; |
| 5504 | } |
| 5505 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5506 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5507 | intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5508 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5509 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5510 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5511 | struct pps_registers regs; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5512 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5513 | intel_pps_get_registers(intel_dp, ®s); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5514 | |
| 5515 | /* Workaround: Need to write PP_CONTROL with the unlock key as |
| 5516 | * the very first thing. */ |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5517 | pp_ctl = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5518 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5519 | pp_on = I915_READ(regs.pp_on); |
| 5520 | pp_off = I915_READ(regs.pp_off); |
Anusha Srivatsa | b0d6a0f | 2018-01-11 16:00:07 -0200 | [diff] [blame] | 5521 | if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) && |
| 5522 | !HAS_PCH_ICP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5523 | I915_WRITE(regs.pp_ctrl, pp_ctl); |
| 5524 | pp_div = I915_READ(regs.pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5525 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5526 | |
| 5527 | /* Pull timing values out of registers */ |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5528 | seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 5529 | PANEL_POWER_UP_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5530 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5531 | seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 5532 | PANEL_LIGHT_ON_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5533 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5534 | seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 5535 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5536 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5537 | seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 5538 | PANEL_POWER_DOWN_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5539 | |
Anusha Srivatsa | b0d6a0f | 2018-01-11 16:00:07 -0200 | [diff] [blame] | 5540 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) || |
| 5541 | HAS_PCH_ICP(dev_priv)) { |
Manasi Navare | 12c8ca9 | 2017-06-26 12:21:45 -0700 | [diff] [blame] | 5542 | seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> |
| 5543 | BXT_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5544 | } else { |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5545 | seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5546 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5547 | } |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | static void |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5551 | intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq) |
| 5552 | { |
| 5553 | DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 5554 | state_name, |
| 5555 | seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12); |
| 5556 | } |
| 5557 | |
| 5558 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5559 | intel_pps_verify_state(struct intel_dp *intel_dp) |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5560 | { |
| 5561 | struct edp_power_seq hw; |
| 5562 | struct edp_power_seq *sw = &intel_dp->pps_delays; |
| 5563 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5564 | intel_pps_readout_hw_state(intel_dp, &hw); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5565 | |
| 5566 | if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 || |
| 5567 | hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) { |
| 5568 | DRM_ERROR("PPS state mismatch\n"); |
| 5569 | intel_pps_dump_state("sw", sw); |
| 5570 | intel_pps_dump_state("hw", &hw); |
| 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5575 | intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp) |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5576 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5577 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5578 | struct edp_power_seq cur, vbt, spec, |
| 5579 | *final = &intel_dp->pps_delays; |
| 5580 | |
| 5581 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5582 | |
| 5583 | /* already initialized? */ |
| 5584 | if (final->t11_t12 != 0) |
| 5585 | return; |
| 5586 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5587 | intel_pps_readout_hw_state(intel_dp, &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5588 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5589 | intel_pps_dump_state("cur", &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5590 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 5591 | vbt = dev_priv->vbt.edp.pps; |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 5592 | /* On Toshiba Satellite P50-C-18C system the VBT T12 delay |
| 5593 | * of 500ms appears to be too short. Ocassionally the panel |
| 5594 | * just fails to power back on. Increasing the delay to 800ms |
| 5595 | * seems sufficient to avoid this problem. |
| 5596 | */ |
| 5597 | if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) { |
Manasi Navare | 7313f5a | 2017-10-03 16:37:25 -0700 | [diff] [blame] | 5598 | vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10); |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 5599 | DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n", |
| 5600 | vbt.t11_t12); |
| 5601 | } |
Manasi Navare | 770a17a | 2017-06-26 12:21:44 -0700 | [diff] [blame] | 5602 | /* T11_T12 delay is special and actually in units of 100ms, but zero |
| 5603 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5604 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5605 | * too. */ |
| 5606 | vbt.t11_t12 += 100 * 10; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5607 | |
| 5608 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of |
| 5609 | * our hw here, which are all in 100usec. */ |
| 5610 | spec.t1_t3 = 210 * 10; |
| 5611 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ |
| 5612 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ |
| 5613 | spec.t10 = 500 * 10; |
| 5614 | /* This one is special and actually in units of 100ms, but zero |
| 5615 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5616 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5617 | * too. */ |
| 5618 | spec.t11_t12 = (510 + 100) * 10; |
| 5619 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5620 | intel_pps_dump_state("vbt", &vbt); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5621 | |
| 5622 | /* Use the max of the register settings and vbt. If both are |
| 5623 | * unset, fall back to the spec limits. */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5624 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5625 | spec.field : \ |
| 5626 | max(cur.field, vbt.field)) |
| 5627 | assign_final(t1_t3); |
| 5628 | assign_final(t8); |
| 5629 | assign_final(t9); |
| 5630 | assign_final(t10); |
| 5631 | assign_final(t11_t12); |
| 5632 | #undef assign_final |
| 5633 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5634 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5635 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 5636 | intel_dp->backlight_on_delay = get_delay(t8); |
| 5637 | intel_dp->backlight_off_delay = get_delay(t9); |
| 5638 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 5639 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 5640 | #undef get_delay |
| 5641 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5642 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 5643 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 5644 | intel_dp->panel_power_cycle_delay); |
| 5645 | |
| 5646 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 5647 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5648 | |
| 5649 | /* |
| 5650 | * We override the HW backlight delays to 1 because we do manual waits |
| 5651 | * on them. For T8, even BSpec recommends doing it. For T9, if we |
| 5652 | * don't do this, we'll end up waiting for the backlight off delay |
| 5653 | * twice: once when we do the manual sleep, and once when we disable |
| 5654 | * the panel and wait for the PP_STATUS bit to become zero. |
| 5655 | */ |
| 5656 | final->t8 = 1; |
| 5657 | final->t9 = 1; |
Imre Deak | 5643205 | 2017-11-29 19:51:37 +0200 | [diff] [blame] | 5658 | |
| 5659 | /* |
| 5660 | * HW has only a 100msec granularity for t11_t12 so round it up |
| 5661 | * accordingly. |
| 5662 | */ |
| 5663 | final->t11_t12 = roundup(final->t11_t12, 100 * 10); |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5664 | } |
| 5665 | |
| 5666 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5667 | intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5668 | bool force_disable_vdd) |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5669 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5670 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5671 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 5672 | int div = dev_priv->rawclk_freq / 1000; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5673 | struct pps_registers regs; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5674 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5675 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5676 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 5677 | lockdep_assert_held(&dev_priv->pps_mutex); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5678 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5679 | intel_pps_get_registers(intel_dp, ®s); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5680 | |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5681 | /* |
| 5682 | * On some VLV machines the BIOS can leave the VDD |
| 5683 | * enabled even on power seqeuencers which aren't |
| 5684 | * hooked up to any port. This would mess up the |
| 5685 | * power domain tracking the first time we pick |
| 5686 | * one of these power sequencers for use since |
| 5687 | * edp_panel_vdd_on() would notice that the VDD was |
| 5688 | * already on and therefore wouldn't grab the power |
| 5689 | * domain reference. Disable VDD first to avoid this. |
| 5690 | * This also avoids spuriously turning the VDD on as |
| 5691 | * soon as the new power seqeuencer gets initialized. |
| 5692 | */ |
| 5693 | if (force_disable_vdd) { |
| 5694 | u32 pp = ironlake_get_pp_control(intel_dp); |
| 5695 | |
| 5696 | WARN(pp & PANEL_POWER_ON, "Panel power already on\n"); |
| 5697 | |
| 5698 | if (pp & EDP_FORCE_VDD) |
| 5699 | DRM_DEBUG_KMS("VDD already on, disabling first\n"); |
| 5700 | |
| 5701 | pp &= ~EDP_FORCE_VDD; |
| 5702 | |
| 5703 | I915_WRITE(regs.pp_ctrl, pp); |
| 5704 | } |
| 5705 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5706 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5707 | (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT); |
| 5708 | pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5709 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5710 | /* Compute the divisor for the pp clock, simply match the Bspec |
| 5711 | * formula. */ |
Anusha Srivatsa | b0d6a0f | 2018-01-11 16:00:07 -0200 | [diff] [blame] | 5712 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) || |
| 5713 | HAS_PCH_ICP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5714 | pp_div = I915_READ(regs.pp_ctrl); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5715 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; |
Manasi Navare | 12c8ca9 | 2017-06-26 12:21:45 -0700 | [diff] [blame] | 5716 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5717 | << BXT_POWER_CYCLE_DELAY_SHIFT); |
| 5718 | } else { |
| 5719 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 5720 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
| 5721 | << PANEL_POWER_CYCLE_DELAY_SHIFT); |
| 5722 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5723 | |
| 5724 | /* Haswell doesn't have any port selection bits for the panel |
| 5725 | * power sequencer any more. */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5726 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5727 | port_sel = PANEL_PORT_SELECT_VLV(port); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5728 | } 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] | 5729 | if (port == PORT_A) |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5730 | port_sel = PANEL_PORT_SELECT_DPA; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5731 | else |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5732 | port_sel = PANEL_PORT_SELECT_DPD; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5733 | } |
| 5734 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5735 | pp_on |= port_sel; |
| 5736 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5737 | I915_WRITE(regs.pp_on, pp_on); |
| 5738 | I915_WRITE(regs.pp_off, pp_off); |
Anusha Srivatsa | b0d6a0f | 2018-01-11 16:00:07 -0200 | [diff] [blame] | 5739 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) || |
| 5740 | HAS_PCH_ICP(dev_priv)) |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5741 | I915_WRITE(regs.pp_ctrl, pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5742 | else |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5743 | I915_WRITE(regs.pp_div, pp_div); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5744 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5745 | 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] | 5746 | I915_READ(regs.pp_on), |
| 5747 | I915_READ(regs.pp_off), |
Anusha Srivatsa | b0d6a0f | 2018-01-11 16:00:07 -0200 | [diff] [blame] | 5748 | (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) || |
| 5749 | HAS_PCH_ICP(dev_priv)) ? |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5750 | (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) : |
| 5751 | I915_READ(regs.pp_div)); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 5752 | } |
| 5753 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5754 | static void intel_dp_pps_init(struct intel_dp *intel_dp) |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5755 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5756 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5757 | |
| 5758 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5759 | vlv_initial_power_sequencer_setup(intel_dp); |
| 5760 | } else { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 5761 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 5762 | intel_dp_init_panel_power_sequencer_registers(intel_dp, false); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5763 | } |
| 5764 | } |
| 5765 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5766 | /** |
| 5767 | * 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] | 5768 | * @dev_priv: i915 device |
Maarten Lankhorst | e896402 | 2016-08-25 11:07:02 +0200 | [diff] [blame] | 5769 | * @crtc_state: a pointer to the active intel_crtc_state |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5770 | * @refresh_rate: RR to be programmed |
| 5771 | * |
| 5772 | * This function gets called when refresh rate (RR) has to be changed from |
| 5773 | * one frequency to another. Switches can be between high and low RR |
| 5774 | * supported by the panel or to any other RR based on media playback (in |
| 5775 | * this case, RR value needs to be passed from user space). |
| 5776 | * |
| 5777 | * The caller of this function needs to take a lock on dev_priv->drrs. |
| 5778 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5779 | static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5780 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5781 | int refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5782 | { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5783 | struct intel_encoder *encoder; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5784 | struct intel_digital_port *dig_port = NULL; |
| 5785 | struct intel_dp *intel_dp = dev_priv->drrs.dp; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5786 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5787 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5788 | |
| 5789 | if (refresh_rate <= 0) { |
| 5790 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); |
| 5791 | return; |
| 5792 | } |
| 5793 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5794 | if (intel_dp == NULL) { |
| 5795 | DRM_DEBUG_KMS("DRRS not supported.\n"); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5796 | return; |
| 5797 | } |
| 5798 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5799 | dig_port = dp_to_dig_port(intel_dp); |
| 5800 | encoder = &dig_port->base; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5801 | |
| 5802 | if (!intel_crtc) { |
| 5803 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); |
| 5804 | return; |
| 5805 | } |
| 5806 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5807 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5808 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
| 5809 | return; |
| 5810 | } |
| 5811 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5812 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
| 5813 | refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5814 | index = DRRS_LOW_RR; |
| 5815 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5816 | if (index == dev_priv->drrs.refresh_rate_type) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5817 | DRM_DEBUG_KMS( |
| 5818 | "DRRS requested for previously set RR...ignoring\n"); |
| 5819 | return; |
| 5820 | } |
| 5821 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5822 | if (!crtc_state->base.active) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5823 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); |
| 5824 | return; |
| 5825 | } |
| 5826 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5827 | if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) { |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5828 | switch (index) { |
| 5829 | case DRRS_HIGH_RR: |
| 5830 | intel_dp_set_m_n(intel_crtc, M1_N1); |
| 5831 | break; |
| 5832 | case DRRS_LOW_RR: |
| 5833 | intel_dp_set_m_n(intel_crtc, M2_N2); |
| 5834 | break; |
| 5835 | case DRRS_MAX_RR: |
| 5836 | default: |
| 5837 | DRM_ERROR("Unsupported refreshrate type\n"); |
| 5838 | } |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5839 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 5840 | i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5841 | u32 val; |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5842 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5843 | val = I915_READ(reg); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5844 | if (index > DRRS_HIGH_RR) { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5845 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5846 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5847 | else |
| 5848 | val |= PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5849 | } else { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5850 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5851 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5852 | else |
| 5853 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5854 | } |
| 5855 | I915_WRITE(reg, val); |
| 5856 | } |
| 5857 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5858 | dev_priv->drrs.refresh_rate_type = index; |
| 5859 | |
| 5860 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); |
| 5861 | } |
| 5862 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5863 | /** |
| 5864 | * intel_edp_drrs_enable - init drrs struct if supported |
| 5865 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5866 | * @crtc_state: A pointer to the active crtc state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5867 | * |
| 5868 | * Initializes frontbuffer_bits and drrs.dp |
| 5869 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5870 | void intel_edp_drrs_enable(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5871 | const struct intel_crtc_state *crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5872 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 5873 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5874 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5875 | if (!crtc_state->has_drrs) { |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5876 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); |
| 5877 | return; |
| 5878 | } |
| 5879 | |
Radhakrishna Sripada | da83ef8 | 2017-09-14 11:16:41 -0700 | [diff] [blame] | 5880 | if (dev_priv->psr.enabled) { |
| 5881 | DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n"); |
| 5882 | return; |
| 5883 | } |
| 5884 | |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5885 | mutex_lock(&dev_priv->drrs.mutex); |
| 5886 | if (WARN_ON(dev_priv->drrs.dp)) { |
| 5887 | DRM_ERROR("DRRS already enabled\n"); |
| 5888 | goto unlock; |
| 5889 | } |
| 5890 | |
| 5891 | dev_priv->drrs.busy_frontbuffer_bits = 0; |
| 5892 | |
| 5893 | dev_priv->drrs.dp = intel_dp; |
| 5894 | |
| 5895 | unlock: |
| 5896 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5897 | } |
| 5898 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5899 | /** |
| 5900 | * intel_edp_drrs_disable - Disable DRRS |
| 5901 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5902 | * @old_crtc_state: Pointer to old crtc_state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5903 | * |
| 5904 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5905 | void intel_edp_drrs_disable(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5906 | const struct intel_crtc_state *old_crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5907 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 5908 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5909 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5910 | if (!old_crtc_state->has_drrs) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5911 | return; |
| 5912 | |
| 5913 | mutex_lock(&dev_priv->drrs.mutex); |
| 5914 | if (!dev_priv->drrs.dp) { |
| 5915 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5916 | return; |
| 5917 | } |
| 5918 | |
| 5919 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5920 | intel_dp_set_drrs_state(dev_priv, old_crtc_state, |
| 5921 | intel_dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5922 | |
| 5923 | dev_priv->drrs.dp = NULL; |
| 5924 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5925 | |
| 5926 | cancel_delayed_work_sync(&dev_priv->drrs.work); |
| 5927 | } |
| 5928 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5929 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
| 5930 | { |
| 5931 | struct drm_i915_private *dev_priv = |
| 5932 | container_of(work, typeof(*dev_priv), drrs.work.work); |
| 5933 | struct intel_dp *intel_dp; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5934 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5935 | mutex_lock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5936 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5937 | intel_dp = dev_priv->drrs.dp; |
| 5938 | |
| 5939 | if (!intel_dp) |
| 5940 | goto unlock; |
| 5941 | |
| 5942 | /* |
| 5943 | * The delayed work can race with an invalidate hence we need to |
| 5944 | * recheck. |
| 5945 | */ |
| 5946 | |
| 5947 | if (dev_priv->drrs.busy_frontbuffer_bits) |
| 5948 | goto unlock; |
| 5949 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5950 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) { |
| 5951 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 5952 | |
| 5953 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5954 | intel_dp->attached_connector->panel.downclock_mode->vrefresh); |
| 5955 | } |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5956 | |
| 5957 | unlock: |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5958 | mutex_unlock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5959 | } |
| 5960 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5961 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5962 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5963 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5964 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5965 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5966 | * This function gets called everytime rendering on the given planes start. |
| 5967 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5968 | * |
| 5969 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5970 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5971 | void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv, |
| 5972 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5973 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5974 | struct drm_crtc *crtc; |
| 5975 | enum pipe pipe; |
| 5976 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5977 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5978 | return; |
| 5979 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5980 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5981 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5982 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5983 | if (!dev_priv->drrs.dp) { |
| 5984 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5985 | return; |
| 5986 | } |
| 5987 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5988 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5989 | pipe = to_intel_crtc(crtc)->pipe; |
| 5990 | |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5991 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 5992 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; |
| 5993 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5994 | /* invalidate means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5995 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5996 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5997 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5998 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5999 | mutex_unlock(&dev_priv->drrs.mutex); |
| 6000 | } |
| 6001 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 6002 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 6003 | * intel_edp_drrs_flush - Restart Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 6004 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 6005 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 6006 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 6007 | * This function gets called every time rendering on the given planes has |
| 6008 | * completed or flip on a crtc is completed. So DRRS should be upclocked |
| 6009 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, |
| 6010 | * if no other planes are dirty. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 6011 | * |
| 6012 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 6013 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 6014 | void intel_edp_drrs_flush(struct drm_i915_private *dev_priv, |
| 6015 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6016 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6017 | struct drm_crtc *crtc; |
| 6018 | enum pipe pipe; |
| 6019 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 6020 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6021 | return; |
| 6022 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 6023 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 6024 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6025 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 6026 | if (!dev_priv->drrs.dp) { |
| 6027 | mutex_unlock(&dev_priv->drrs.mutex); |
| 6028 | return; |
| 6029 | } |
| 6030 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6031 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 6032 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 6033 | |
| 6034 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6035 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 6036 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 6037 | /* flush means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 6038 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 6039 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 6040 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 6041 | |
| 6042 | /* |
| 6043 | * flush also means no more activity hence schedule downclock, if all |
| 6044 | * other fbs are quiescent too |
| 6045 | */ |
| 6046 | if (!dev_priv->drrs.busy_frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 6047 | schedule_delayed_work(&dev_priv->drrs.work, |
| 6048 | msecs_to_jiffies(1000)); |
| 6049 | mutex_unlock(&dev_priv->drrs.mutex); |
| 6050 | } |
| 6051 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 6052 | /** |
| 6053 | * DOC: Display Refresh Rate Switching (DRRS) |
| 6054 | * |
| 6055 | * Display Refresh Rate Switching (DRRS) is a power conservation feature |
| 6056 | * which enables swtching between low and high refresh rates, |
| 6057 | * dynamically, based on the usage scenario. This feature is applicable |
| 6058 | * for internal panels. |
| 6059 | * |
| 6060 | * Indication that the panel supports DRRS is given by the panel EDID, which |
| 6061 | * would list multiple refresh rates for one resolution. |
| 6062 | * |
| 6063 | * DRRS is of 2 types - static and seamless. |
| 6064 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset |
| 6065 | * (may appear as a blink on screen) and is used in dock-undock scenario. |
| 6066 | * Seamless DRRS involves changing RR without any visual effect to the user |
| 6067 | * and can be used during normal system usage. This is done by programming |
| 6068 | * certain registers. |
| 6069 | * |
| 6070 | * Support for static/seamless DRRS may be indicated in the VBT based on |
| 6071 | * inputs from the panel spec. |
| 6072 | * |
| 6073 | * DRRS saves power by switching to low RR based on usage scenarios. |
| 6074 | * |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 6075 | * The implementation is based on frontbuffer tracking implementation. When |
| 6076 | * there is a disturbance on the screen triggered by user activity or a periodic |
| 6077 | * system activity, DRRS is disabled (RR is changed to high RR). When there is |
| 6078 | * no movement on screen, after a timeout of 1 second, a switch to low RR is |
| 6079 | * made. |
| 6080 | * |
| 6081 | * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate() |
| 6082 | * and intel_edp_drrs_flush() are called. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 6083 | * |
| 6084 | * DRRS can be further extended to support other internal panels and also |
| 6085 | * the scenario of video playback wherein RR is set based on the rate |
| 6086 | * requested by userspace. |
| 6087 | */ |
| 6088 | |
| 6089 | /** |
| 6090 | * intel_dp_drrs_init - Init basic DRRS work and mutex. |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6091 | * @connector: eDP connector |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 6092 | * @fixed_mode: preferred mode of panel |
| 6093 | * |
| 6094 | * This function is called only once at driver load to initialize basic |
| 6095 | * DRRS stuff. |
| 6096 | * |
| 6097 | * Returns: |
| 6098 | * Downclock mode if panel supports it, else return NULL. |
| 6099 | * DRRS support is determined by the presence of downclock mode (apart |
| 6100 | * from VBT setting). |
| 6101 | */ |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6102 | static struct drm_display_mode * |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6103 | intel_dp_drrs_init(struct intel_connector *connector, |
| 6104 | struct drm_display_mode *fixed_mode) |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6105 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6106 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6107 | struct drm_display_mode *downclock_mode = NULL; |
| 6108 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 6109 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
| 6110 | mutex_init(&dev_priv->drrs.mutex); |
| 6111 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6112 | if (INTEL_GEN(dev_priv) <= 6) { |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6113 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); |
| 6114 | return NULL; |
| 6115 | } |
| 6116 | |
| 6117 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 6118 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6119 | return NULL; |
| 6120 | } |
| 6121 | |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6122 | downclock_mode = intel_find_panel_downclock(dev_priv, fixed_mode, |
| 6123 | &connector->base); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6124 | |
| 6125 | if (!downclock_mode) { |
Ramalingam C | a1d2634 | 2015-02-23 17:38:33 +0530 | [diff] [blame] | 6126 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6127 | return NULL; |
| 6128 | } |
| 6129 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 6130 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 6131 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 6132 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 6133 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6134 | return downclock_mode; |
| 6135 | } |
| 6136 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6137 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 6138 | struct intel_connector *intel_connector) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6139 | { |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6140 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6141 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6142 | struct drm_connector *connector = &intel_connector->base; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6143 | struct drm_display_mode *fixed_mode = NULL; |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 6144 | struct drm_display_mode *alt_fixed_mode = NULL; |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6145 | struct drm_display_mode *downclock_mode = NULL; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6146 | bool has_dpcd; |
| 6147 | struct drm_display_mode *scan; |
| 6148 | struct edid *edid; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 6149 | enum pipe pipe = INVALID_PIPE; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6150 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6151 | if (!intel_dp_is_edp(intel_dp)) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6152 | return true; |
| 6153 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 6154 | /* |
| 6155 | * On IBX/CPT we may get here with LVDS already registered. Since the |
| 6156 | * driver uses the only internal power sequencer available for both |
| 6157 | * eDP and LVDS bail out early in this case to prevent interfering |
| 6158 | * with an already powered-on LVDS power sequencer. |
| 6159 | */ |
Ville Syrjälä | 2f77347 | 2017-11-09 17:27:58 +0200 | [diff] [blame] | 6160 | if (intel_get_lvds_encoder(&dev_priv->drm)) { |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 6161 | WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))); |
| 6162 | DRM_INFO("LVDS was detected, not registering eDP\n"); |
| 6163 | |
| 6164 | return false; |
| 6165 | } |
| 6166 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 6167 | pps_lock(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 6168 | |
| 6169 | intel_dp_init_panel_power_timestamps(intel_dp); |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame] | 6170 | intel_dp_pps_init(intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 6171 | intel_edp_panel_vdd_sanitize(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 6172 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 6173 | pps_unlock(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 6174 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6175 | /* Cache DPCD and EDID for edp. */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 6176 | has_dpcd = intel_edp_init_dpcd(intel_dp); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6177 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 6178 | if (!has_dpcd) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6179 | /* if this fails, presume the device is a ghost */ |
| 6180 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 6181 | goto out_vdd_off; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6182 | } |
| 6183 | |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 6184 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 6185 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6186 | if (edid) { |
| 6187 | if (drm_add_edid_modes(connector, edid)) { |
| 6188 | drm_mode_connector_update_edid_property(connector, |
| 6189 | edid); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6190 | } else { |
| 6191 | kfree(edid); |
| 6192 | edid = ERR_PTR(-EINVAL); |
| 6193 | } |
| 6194 | } else { |
| 6195 | edid = ERR_PTR(-ENOENT); |
| 6196 | } |
| 6197 | intel_connector->edid = edid; |
| 6198 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 6199 | /* prefer fixed mode from EDID if available, save an alt mode also */ |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6200 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 6201 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 6202 | fixed_mode = drm_mode_duplicate(dev, scan); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6203 | downclock_mode = intel_dp_drrs_init( |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 6204 | intel_connector, fixed_mode); |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 6205 | } else if (!alt_fixed_mode) { |
| 6206 | alt_fixed_mode = drm_mode_duplicate(dev, scan); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /* fallback to VBT if available for eDP */ |
| 6211 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { |
| 6212 | fixed_mode = drm_mode_duplicate(dev, |
| 6213 | dev_priv->vbt.lfp_lvds_vbt_mode); |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 6214 | if (fixed_mode) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6215 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 6216 | connector->display_info.width_mm = fixed_mode->width_mm; |
| 6217 | connector->display_info.height_mm = fixed_mode->height_mm; |
| 6218 | } |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6219 | } |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 6220 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6221 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6222 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 6223 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
| 6224 | register_reboot_notifier(&intel_dp->edp_notifier); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 6225 | |
| 6226 | /* |
| 6227 | * Figure out the current pipe for the initial backlight setup. |
| 6228 | * If the current pipe isn't valid, try the PPS pipe, and if that |
| 6229 | * fails just assume pipe A. |
| 6230 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6231 | pipe = vlv_active_pipe(intel_dp); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 6232 | |
| 6233 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 6234 | pipe = intel_dp->pps_pipe; |
| 6235 | |
| 6236 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 6237 | pipe = PIPE_A; |
| 6238 | |
| 6239 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", |
| 6240 | pipe_name(pipe)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 6241 | } |
| 6242 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 6243 | intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode, |
| 6244 | downclock_mode); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 6245 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 6246 | intel_panel_setup_backlight(connector, pipe); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6247 | |
| 6248 | return true; |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 6249 | |
| 6250 | out_vdd_off: |
| 6251 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 6252 | /* |
| 6253 | * vdd might still be enabled do to the delayed vdd off. |
| 6254 | * Make sure vdd is actually turned off here. |
| 6255 | */ |
| 6256 | pps_lock(intel_dp); |
| 6257 | edp_panel_vdd_off_sync(intel_dp); |
| 6258 | pps_unlock(intel_dp); |
| 6259 | |
| 6260 | return false; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 6261 | } |
| 6262 | |
Manasi Navare | 9301397 | 2017-04-06 16:44:19 +0300 | [diff] [blame] | 6263 | static void intel_dp_modeset_retry_work_fn(struct work_struct *work) |
| 6264 | { |
| 6265 | struct intel_connector *intel_connector; |
| 6266 | struct drm_connector *connector; |
| 6267 | |
| 6268 | intel_connector = container_of(work, typeof(*intel_connector), |
| 6269 | modeset_retry_work); |
| 6270 | connector = &intel_connector->base; |
| 6271 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, |
| 6272 | connector->name); |
| 6273 | |
| 6274 | /* Grab the locks before changing connector property*/ |
| 6275 | mutex_lock(&connector->dev->mode_config.mutex); |
| 6276 | /* Set connector link status to BAD and send a Uevent to notify |
| 6277 | * userspace to do a modeset. |
| 6278 | */ |
| 6279 | drm_mode_connector_set_link_status_property(connector, |
| 6280 | DRM_MODE_LINK_STATUS_BAD); |
| 6281 | mutex_unlock(&connector->dev->mode_config.mutex); |
| 6282 | /* Send Hotplug uevent so userspace can reprobe */ |
| 6283 | drm_kms_helper_hotplug_event(connector->dev); |
| 6284 | } |
| 6285 | |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6286 | bool |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6287 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
| 6288 | struct intel_connector *intel_connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6289 | { |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6290 | struct drm_connector *connector = &intel_connector->base; |
| 6291 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 6292 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 6293 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6294 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 6295 | enum port port = intel_encoder->port; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6296 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6297 | |
Manasi Navare | 9301397 | 2017-04-06 16:44:19 +0300 | [diff] [blame] | 6298 | /* Initialize the work for modeset in case of link train failure */ |
| 6299 | INIT_WORK(&intel_connector->modeset_retry_work, |
| 6300 | intel_dp_modeset_retry_work_fn); |
| 6301 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6302 | if (WARN(intel_dig_port->max_lanes < 1, |
| 6303 | "Not enough lanes (%d) for DP on port %c\n", |
| 6304 | intel_dig_port->max_lanes, port_name(port))) |
| 6305 | return false; |
| 6306 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 6307 | intel_dp_set_source_rates(intel_dp); |
| 6308 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 6309 | intel_dp->reset_link_params = true; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 6310 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6311 | intel_dp->active_pipe = INVALID_PIPE; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 6312 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6313 | /* intel_dp vfuncs */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6314 | if (HAS_DDI(dev_priv)) |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 6315 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; |
| 6316 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 6317 | /* Preserve the current hw state. */ |
| 6318 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 6319 | intel_dp->attached_connector = intel_connector; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 6320 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 6321 | if (intel_dp_is_port_edp(dev_priv, port)) |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 6322 | type = DRM_MODE_CONNECTOR_eDP; |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 6323 | else |
| 6324 | type = DRM_MODE_CONNECTOR_DisplayPort; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6325 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6326 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 6327 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 6328 | |
Imre Deak | f7d2490 | 2013-05-08 13:14:05 +0300 | [diff] [blame] | 6329 | /* |
| 6330 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but |
| 6331 | * for DP the encoder type can be set by the caller to |
| 6332 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. |
| 6333 | */ |
| 6334 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 6335 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 6336 | |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6337 | /* eDP only on port B and/or C on vlv/chv */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6338 | if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6339 | intel_dp_is_edp(intel_dp) && |
| 6340 | port != PORT_B && port != PORT_C)) |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6341 | return false; |
| 6342 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 6343 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
| 6344 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", |
| 6345 | port_name(port)); |
| 6346 | |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6347 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6348 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 6349 | |
Ville Syrjälä | 05021389 | 2017-11-29 20:08:47 +0200 | [diff] [blame] | 6350 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) |
| 6351 | connector->interlace_allowed = true; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6352 | connector->doublescan_allowed = 0; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 6353 | |
Ville Syrjälä | bdabdb6 | 2018-02-22 20:10:30 +0200 | [diff] [blame] | 6354 | intel_encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port); |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 6355 | |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 6356 | intel_dp_aux_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6357 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 6358 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 6359 | edp_panel_vdd_work); |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 6360 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6361 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6362 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6363 | if (HAS_DDI(dev_priv)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 6364 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 6365 | else |
| 6366 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
| 6367 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6368 | /* init MST on ports that can support it */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6369 | if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) && |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 6370 | (port == PORT_B || port == PORT_C || |
| 6371 | port == PORT_D || port == PORT_F)) |
Jani Nikula | 0c9b371 | 2015-05-18 17:10:01 +0300 | [diff] [blame] | 6372 | intel_dp_mst_encoder_init(intel_dig_port, |
| 6373 | intel_connector->base.base.id); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6374 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 6375 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6376 | intel_dp_aux_fini(intel_dp); |
| 6377 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
| 6378 | goto fail; |
Paulo Zanoni | b2f246a | 2013-06-12 17:27:26 -0300 | [diff] [blame] | 6379 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 6380 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 6381 | intel_dp_add_properties(intel_dp, connector); |
| 6382 | |
Ramalingam C | fdddd08 | 2018-01-18 11:18:05 +0530 | [diff] [blame] | 6383 | if (is_hdcp_supported(dev_priv, port) && !intel_dp_is_edp(intel_dp)) { |
Sean Paul | 20f24d7 | 2018-01-08 14:55:43 -0500 | [diff] [blame] | 6384 | int ret = intel_hdcp_init(intel_connector, &intel_dp_hdcp_shim); |
| 6385 | if (ret) |
| 6386 | DRM_DEBUG_KMS("HDCP init failed, skipping.\n"); |
| 6387 | } |
| 6388 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6389 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 6390 | * 0xd. Failure to do so will result in spurious interrupts being |
| 6391 | * generated on the port when a cable is not attached. |
| 6392 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6393 | if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6394 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 6395 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 6396 | } |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6397 | |
| 6398 | return true; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6399 | |
| 6400 | fail: |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6401 | drm_connector_cleanup(connector); |
| 6402 | |
| 6403 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6404 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6405 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6406 | bool intel_dp_init(struct drm_i915_private *dev_priv, |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6407 | i915_reg_t output_reg, |
| 6408 | enum port port) |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6409 | { |
| 6410 | struct intel_digital_port *intel_dig_port; |
| 6411 | struct intel_encoder *intel_encoder; |
| 6412 | struct drm_encoder *encoder; |
| 6413 | struct intel_connector *intel_connector; |
| 6414 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 6415 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6416 | if (!intel_dig_port) |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6417 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6418 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6419 | intel_connector = intel_connector_alloc(); |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6420 | if (!intel_connector) |
| 6421 | goto err_connector_alloc; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6422 | |
| 6423 | intel_encoder = &intel_dig_port->base; |
| 6424 | encoder = &intel_encoder->base; |
| 6425 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6426 | if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, |
| 6427 | &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, |
| 6428 | "DP %c", port_name(port))) |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6429 | goto err_encoder_init; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6430 | |
Ville Syrjälä | c85d200 | 2018-01-17 21:21:47 +0200 | [diff] [blame] | 6431 | intel_encoder->hotplug = intel_dp_hotplug; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 6432 | intel_encoder->compute_config = intel_dp_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6433 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 6434 | intel_encoder->get_config = intel_dp_get_config; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 6435 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6436 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 6437 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 6438 | intel_encoder->pre_enable = chv_pre_enable_dp; |
| 6439 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6440 | intel_encoder->disable = vlv_disable_dp; |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 6441 | intel_encoder->post_disable = chv_post_disable_dp; |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6442 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6443 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6444 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6445 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
| 6446 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6447 | intel_encoder->disable = vlv_disable_dp; |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 6448 | intel_encoder->post_disable = vlv_post_disable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6449 | } else if (INTEL_GEN(dev_priv) >= 5) { |
| 6450 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6451 | intel_encoder->enable = g4x_enable_dp; |
| 6452 | intel_encoder->disable = ilk_disable_dp; |
| 6453 | intel_encoder->post_disable = ilk_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6454 | } else { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6455 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6456 | intel_encoder->enable = g4x_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6457 | intel_encoder->disable = g4x_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6458 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6459 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6460 | intel_dig_port->dp.output_reg = output_reg; |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6461 | intel_dig_port->max_lanes = 4; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6462 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 6463 | intel_encoder->type = INTEL_OUTPUT_DP; |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6464 | intel_encoder->power_domain = intel_port_to_power_domain(port); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6465 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 882ec38 | 2014-04-28 14:07:43 +0300 | [diff] [blame] | 6466 | if (port == PORT_D) |
| 6467 | intel_encoder->crtc_mask = 1 << 2; |
| 6468 | else |
| 6469 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
| 6470 | } else { |
| 6471 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 6472 | } |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 6473 | intel_encoder->cloneable = 0; |
Pandiyan, Dhinakaran | 03cdc1d | 2016-09-19 18:24:38 -0700 | [diff] [blame] | 6474 | intel_encoder->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6475 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6476 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6477 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6478 | |
Ville Syrjälä | 385e4de | 2017-08-18 16:49:55 +0300 | [diff] [blame] | 6479 | if (port != PORT_A) |
| 6480 | intel_infoframe_init(intel_dig_port); |
| 6481 | |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6482 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
| 6483 | goto err_init_connector; |
| 6484 | |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6485 | return true; |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6486 | |
| 6487 | err_init_connector: |
| 6488 | drm_encoder_cleanup(encoder); |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6489 | err_encoder_init: |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6490 | kfree(intel_connector); |
| 6491 | err_connector_alloc: |
| 6492 | kfree(intel_dig_port); |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6493 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6494 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6495 | |
| 6496 | void intel_dp_mst_suspend(struct drm_device *dev) |
| 6497 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6498 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6499 | int i; |
| 6500 | |
| 6501 | /* disable MST */ |
| 6502 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6503 | 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] | 6504 | |
| 6505 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6506 | continue; |
| 6507 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6508 | if (intel_dig_port->dp.is_mst) |
| 6509 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6510 | } |
| 6511 | } |
| 6512 | |
| 6513 | void intel_dp_mst_resume(struct drm_device *dev) |
| 6514 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6515 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6516 | int i; |
| 6517 | |
| 6518 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6519 | 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] | 6520 | int ret; |
| 6521 | |
| 6522 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6523 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6524 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6525 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); |
| 6526 | if (ret) |
| 6527 | intel_dp_check_mst_status(&intel_dig_port->dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6528 | } |
| 6529 | } |