Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Keith Packard <keithp@keithp.com> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 30 | #include <linux/export.h> |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 31 | #include <linux/types.h> |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 32 | #include <linux/notifier.h> |
| 33 | #include <linux/reboot.h> |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 34 | #include <asm/byteorder.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 36 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drm_crtc.h> |
| 38 | #include <drm/drm_crtc_helper.h> |
| 39 | #include <drm/drm_edid.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 40 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 41 | #include <drm/i915_drm.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 42 | #include "i915_drv.h" |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 43 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 44 | #define DP_LINK_CHECK_TIMEOUT (10 * 1000) |
Pandiyan, Dhinakaran | e8b2577 | 2017-09-18 15:21:39 -0700 | [diff] [blame] | 45 | #define DP_DPRX_ESI_LEN 14 |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 46 | |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 47 | /* Compliance test status bits */ |
| 48 | #define INTEL_DP_RESOLUTION_SHIFT_MASK 0 |
| 49 | #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 50 | #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 51 | #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK) |
| 52 | |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 53 | struct dp_link_dpll { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 54 | int clock; |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 55 | struct dpll dpll; |
| 56 | }; |
| 57 | |
| 58 | static const struct dp_link_dpll gen4_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 59 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 60 | { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 61 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 62 | { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } } |
| 63 | }; |
| 64 | |
| 65 | static const struct dp_link_dpll pch_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 66 | { 162000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 67 | { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 68 | { 270000, |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 69 | { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } } |
| 70 | }; |
| 71 | |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 72 | static const struct dp_link_dpll vlv_dpll[] = { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 73 | { 162000, |
Chon Ming Lee | 58f6e63 | 2013-09-25 15:47:51 +0800 | [diff] [blame] | 74 | { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 75 | { 270000, |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 76 | { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } } |
| 77 | }; |
| 78 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 79 | /* |
| 80 | * CHV supports eDP 1.4 that have more link rates. |
| 81 | * Below only provides the fixed rate but exclude variable rate. |
| 82 | */ |
| 83 | static const struct dp_link_dpll chv_dpll[] = { |
| 84 | /* |
| 85 | * CHV requires to program fractional division for m2. |
| 86 | * m2 is stored in fixed point format using formula below |
| 87 | * (m2_int << 22) | m2_fraction |
| 88 | */ |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 89 | { 162000, /* m2_int = 32, m2_fraction = 1677722 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 90 | { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 91 | { 270000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 92 | { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 93 | { 540000, /* m2_int = 27, m2_fraction = 0 */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 94 | { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } } |
| 95 | }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 96 | |
Sonika Jindal | 64987fc | 2015-05-26 17:50:13 +0530 | [diff] [blame] | 97 | static const int bxt_rates[] = { 162000, 216000, 243000, 270000, |
| 98 | 324000, 432000, 540000 }; |
Sonika Jindal | 637a9c6 | 2015-05-07 09:52:08 +0530 | [diff] [blame] | 99 | static const int skl_rates[] = { 162000, 216000, 270000, |
Ville Syrjälä | f4896f1 | 2015-03-12 17:10:27 +0200 | [diff] [blame] | 100 | 324000, 432000, 540000 }; |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 101 | static const int cnl_rates[] = { 162000, 216000, 270000, |
| 102 | 324000, 432000, 540000, |
| 103 | 648000, 810000 }; |
Ville Syrjälä | f4896f1 | 2015-03-12 17:10:27 +0200 | [diff] [blame] | 104 | static const int default_rates[] = { 162000, 270000, 540000 }; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 105 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 106 | /** |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 107 | * 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] | 108 | * @intel_dp: DP struct |
| 109 | * |
| 110 | * If a CPU or PCH DP output is attached to an eDP panel, this function |
| 111 | * will return true, and false otherwise. |
| 112 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 113 | bool intel_dp_is_edp(struct intel_dp *intel_dp) |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 114 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 115 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 116 | |
| 117 | return intel_dig_port->base.type == INTEL_OUTPUT_EDP; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 120 | 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] | 121 | { |
Imre Deak | 68b4d82 | 2013-05-08 13:14:06 +0300 | [diff] [blame] | 122 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 123 | |
| 124 | return intel_dig_port->base.base.dev; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 127 | static struct intel_dp *intel_attached_dp(struct drm_connector *connector) |
| 128 | { |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 129 | return enc_to_intel_dp(&intel_attached_encoder(connector)->base); |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 132 | static void intel_dp_link_down(struct intel_encoder *encoder, |
| 133 | const struct intel_crtc_state *old_crtc_state); |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 134 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 135 | 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] | 136 | static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder, |
| 137 | const struct intel_crtc_state *crtc_state); |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 138 | 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] | 139 | enum pipe pipe); |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 140 | static void intel_dp_unset_edid(struct intel_dp *intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 141 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 142 | /* update sink rates from dpcd */ |
| 143 | static void intel_dp_set_sink_rates(struct intel_dp *intel_dp) |
| 144 | { |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 145 | int i, max_rate; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 146 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 147 | 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] | 148 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 149 | for (i = 0; i < ARRAY_SIZE(default_rates); i++) { |
| 150 | if (default_rates[i] > max_rate) |
| 151 | break; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 152 | intel_dp->sink_rates[i] = default_rates[i]; |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 153 | } |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 154 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 155 | intel_dp->num_sink_rates = i; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 156 | } |
| 157 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 158 | /* Theoretical max between source and sink */ |
| 159 | static int intel_dp_max_common_rate(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 160 | { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 161 | return intel_dp->common_rates[intel_dp->num_common_rates - 1]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 164 | /* Theoretical max between source and sink */ |
| 165 | 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] | 166 | { |
| 167 | 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] | 168 | int source_max = intel_dig_port->max_lanes; |
| 169 | int sink_max = drm_dp_max_lane_count(intel_dp->dpcd); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 170 | |
| 171 | return min(source_max, sink_max); |
| 172 | } |
| 173 | |
Jani Nikula | 3d65a73 | 2017-04-06 16:44:14 +0300 | [diff] [blame] | 174 | int intel_dp_max_lane_count(struct intel_dp *intel_dp) |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 175 | { |
| 176 | return intel_dp->max_link_lane_count; |
| 177 | } |
| 178 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 179 | int |
Keith Packard | c898261 | 2012-01-25 08:16:25 -0800 | [diff] [blame] | 180 | intel_dp_link_required(int pixel_clock, int bpp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 181 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 182 | /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */ |
| 183 | return DIV_ROUND_UP(pixel_clock * bpp, 8); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 186 | int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 187 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 188 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 189 | /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the |
| 190 | * link rate that is generally expressed in Gbps. Since, 8 bits of data |
| 191 | * is transmitted every LS_Clk per lane, there is no need to account for |
| 192 | * the channel encoding that is done in the PHY layer here. |
| 193 | */ |
| 194 | |
| 195 | return max_link_clock * max_lanes; |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 196 | } |
| 197 | |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 198 | static int |
| 199 | intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp) |
| 200 | { |
| 201 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 202 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 203 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 204 | int max_dotclk = dev_priv->max_dotclk_freq; |
| 205 | int ds_max_dotclk; |
| 206 | |
| 207 | int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 208 | |
| 209 | if (type != DP_DS_PORT_TYPE_VGA) |
| 210 | return max_dotclk; |
| 211 | |
| 212 | ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd, |
| 213 | intel_dp->downstream_ports); |
| 214 | |
| 215 | if (ds_max_dotclk != 0) |
| 216 | max_dotclk = min(max_dotclk, ds_max_dotclk); |
| 217 | |
| 218 | return max_dotclk; |
| 219 | } |
| 220 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 221 | static void |
| 222 | intel_dp_set_source_rates(struct intel_dp *intel_dp) |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 223 | { |
| 224 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 225 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 226 | enum port port = dig_port->base.port; |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 227 | const int *source_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 228 | int size; |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 229 | u32 voltage; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 230 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 231 | /* This should only be done once */ |
| 232 | WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates); |
| 233 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 234 | if (IS_GEN9_LP(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 235 | source_rates = bxt_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 236 | size = ARRAY_SIZE(bxt_rates); |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 237 | } else if (IS_CANNONLAKE(dev_priv)) { |
| 238 | source_rates = cnl_rates; |
| 239 | size = ARRAY_SIZE(cnl_rates); |
| 240 | voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; |
| 241 | if (port == PORT_A || port == PORT_D || |
| 242 | voltage == VOLTAGE_INFO_0_85V) |
| 243 | size -= 2; |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 244 | } else if (IS_GEN9_BC(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 245 | source_rates = skl_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 246 | size = ARRAY_SIZE(skl_rates); |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 247 | } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) || |
| 248 | IS_BROADWELL(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 249 | source_rates = default_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 250 | size = ARRAY_SIZE(default_rates); |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 251 | } else { |
| 252 | source_rates = default_rates; |
| 253 | size = ARRAY_SIZE(default_rates) - 1; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 256 | intel_dp->source_rates = source_rates; |
| 257 | intel_dp->num_source_rates = size; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static int intersect_rates(const int *source_rates, int source_len, |
| 261 | const int *sink_rates, int sink_len, |
| 262 | int *common_rates) |
| 263 | { |
| 264 | int i = 0, j = 0, k = 0; |
| 265 | |
| 266 | while (i < source_len && j < sink_len) { |
| 267 | if (source_rates[i] == sink_rates[j]) { |
| 268 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
| 269 | return k; |
| 270 | common_rates[k] = source_rates[i]; |
| 271 | ++k; |
| 272 | ++i; |
| 273 | ++j; |
| 274 | } else if (source_rates[i] < sink_rates[j]) { |
| 275 | ++i; |
| 276 | } else { |
| 277 | ++j; |
| 278 | } |
| 279 | } |
| 280 | return k; |
| 281 | } |
| 282 | |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 283 | /* return index of rate in rates array, or -1 if not found */ |
| 284 | static int intel_dp_rate_index(const int *rates, int len, int rate) |
| 285 | { |
| 286 | int i; |
| 287 | |
| 288 | for (i = 0; i < len; i++) |
| 289 | if (rate == rates[i]) |
| 290 | return i; |
| 291 | |
| 292 | return -1; |
| 293 | } |
| 294 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 295 | 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] | 296 | { |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 297 | 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] | 298 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 299 | intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates, |
| 300 | intel_dp->num_source_rates, |
| 301 | intel_dp->sink_rates, |
| 302 | intel_dp->num_sink_rates, |
| 303 | intel_dp->common_rates); |
| 304 | |
| 305 | /* Paranoia, there should always be something in common. */ |
| 306 | if (WARN_ON(intel_dp->num_common_rates == 0)) { |
| 307 | intel_dp->common_rates[0] = default_rates[0]; |
| 308 | intel_dp->num_common_rates = 1; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /* get length of common rates potentially limited by max_rate */ |
| 313 | static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp, |
| 314 | int max_rate) |
| 315 | { |
| 316 | const int *common_rates = intel_dp->common_rates; |
| 317 | int i, common_len = intel_dp->num_common_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 318 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 319 | /* Limit results by potentially reduced max rate */ |
| 320 | for (i = 0; i < common_len; i++) { |
| 321 | if (common_rates[common_len - i - 1] <= max_rate) |
| 322 | return common_len - i; |
| 323 | } |
| 324 | |
| 325 | return 0; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 328 | static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate, |
| 329 | uint8_t lane_count) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 330 | { |
| 331 | /* |
| 332 | * FIXME: we need to synchronize the current link parameters with |
| 333 | * hardware readout. Currently fast link training doesn't work on |
| 334 | * boot-up. |
| 335 | */ |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 336 | if (link_rate == 0 || |
| 337 | link_rate > intel_dp->max_link_rate) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 338 | return false; |
| 339 | |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 340 | if (lane_count == 0 || |
| 341 | lane_count > intel_dp_max_lane_count(intel_dp)) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 342 | return false; |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 347 | int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, |
| 348 | int link_rate, uint8_t lane_count) |
| 349 | { |
Jani Nikula | b1810a7 | 2017-04-06 16:44:11 +0300 | [diff] [blame] | 350 | int index; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 351 | |
Jani Nikula | b1810a7 | 2017-04-06 16:44:11 +0300 | [diff] [blame] | 352 | index = intel_dp_rate_index(intel_dp->common_rates, |
| 353 | intel_dp->num_common_rates, |
| 354 | link_rate); |
| 355 | if (index > 0) { |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 356 | intel_dp->max_link_rate = intel_dp->common_rates[index - 1]; |
| 357 | intel_dp->max_link_lane_count = lane_count; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 358 | } else if (lane_count > 1) { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 359 | intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp); |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 360 | intel_dp->max_link_lane_count = lane_count >> 1; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 361 | } else { |
| 362 | DRM_ERROR("Link Training Unsuccessful\n"); |
| 363 | return -1; |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 369 | static enum drm_mode_status |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 370 | intel_dp_mode_valid(struct drm_connector *connector, |
| 371 | struct drm_display_mode *mode) |
| 372 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 373 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 374 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 375 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 376 | int target_clock = mode->clock; |
| 377 | int max_rate, mode_rate, max_lanes, max_link_clock; |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 378 | int max_dotclk; |
| 379 | |
| 380 | max_dotclk = intel_dp_downstream_max_dotclock(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 381 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 382 | if (intel_dp_is_edp(intel_dp) && fixed_mode) { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 383 | if (mode->hdisplay > fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 384 | return MODE_PANEL; |
| 385 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 386 | if (mode->vdisplay > fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 387 | return MODE_PANEL; |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 388 | |
| 389 | target_clock = fixed_mode->clock; |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 392 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 393 | max_lanes = intel_dp_max_lane_count(intel_dp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 394 | |
| 395 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); |
| 396 | mode_rate = intel_dp_link_required(target_clock, 18); |
| 397 | |
Mika Kahola | 799487f | 2016-02-02 15:16:38 +0200 | [diff] [blame] | 398 | if (mode_rate > max_rate || target_clock > max_dotclk) |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 399 | return MODE_CLOCK_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 400 | |
| 401 | if (mode->clock < 10000) |
| 402 | return MODE_CLOCK_LOW; |
| 403 | |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 404 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 405 | return MODE_H_ILLEGAL; |
| 406 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 407 | return MODE_OK; |
| 408 | } |
| 409 | |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 410 | 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] | 411 | { |
| 412 | int i; |
| 413 | uint32_t v = 0; |
| 414 | |
| 415 | if (src_bytes > 4) |
| 416 | src_bytes = 4; |
| 417 | for (i = 0; i < src_bytes; i++) |
| 418 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 419 | return v; |
| 420 | } |
| 421 | |
Damien Lespiau | c2af70e | 2015-02-10 19:32:23 +0000 | [diff] [blame] | 422 | 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] | 423 | { |
| 424 | int i; |
| 425 | if (dst_bytes > 4) |
| 426 | dst_bytes = 4; |
| 427 | for (i = 0; i < dst_bytes; i++) |
| 428 | dst[i] = src >> ((3-i) * 8); |
| 429 | } |
| 430 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 431 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 432 | intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 433 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 434 | 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] | 435 | bool force_disable_vdd); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 436 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 437 | intel_dp_pps_init(struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 438 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 439 | static void pps_lock(struct intel_dp *intel_dp) |
| 440 | { |
| 441 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 442 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 443 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 444 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * See vlv_power_sequencer_reset() why we need |
| 448 | * a power domain reference here. |
| 449 | */ |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 450 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 451 | |
| 452 | mutex_lock(&dev_priv->pps_mutex); |
| 453 | } |
| 454 | |
| 455 | static void pps_unlock(struct intel_dp *intel_dp) |
| 456 | { |
| 457 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 458 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 459 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 460 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 461 | |
| 462 | mutex_unlock(&dev_priv->pps_mutex); |
| 463 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 464 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 465 | } |
| 466 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 467 | static void |
| 468 | vlv_power_sequencer_kick(struct intel_dp *intel_dp) |
| 469 | { |
| 470 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 471 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 472 | enum pipe pipe = intel_dp->pps_pipe; |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 473 | bool pll_enabled, release_cl_override = false; |
| 474 | enum dpio_phy phy = DPIO_PHY(pipe); |
| 475 | enum dpio_channel ch = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 476 | uint32_t DP; |
| 477 | |
| 478 | if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN, |
| 479 | "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] | 480 | pipe_name(pipe), port_name(intel_dig_port->base.port))) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 481 | return; |
| 482 | |
| 483 | 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] | 484 | pipe_name(pipe), port_name(intel_dig_port->base.port)); |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 485 | |
| 486 | /* Preserve the BIOS-computed detected bit. This is |
| 487 | * supposed to be read-only. |
| 488 | */ |
| 489 | DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
| 490 | DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
| 491 | DP |= DP_PORT_WIDTH(1); |
| 492 | DP |= DP_LINK_TRAIN_PAT_1; |
| 493 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 494 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 495 | DP |= DP_PIPE_SELECT_CHV(pipe); |
| 496 | else if (pipe == PIPE_B) |
| 497 | DP |= DP_PIPEB_SELECT; |
| 498 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 499 | pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE; |
| 500 | |
| 501 | /* |
| 502 | * The DPLL for the pipe must be enabled for this to work. |
| 503 | * So enable temporarily it if it's not already enabled. |
| 504 | */ |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 505 | if (!pll_enabled) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 506 | release_cl_override = IS_CHERRYVIEW(dev_priv) && |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 507 | !chv_phy_powergate_ch(dev_priv, phy, ch, true); |
| 508 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 509 | if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ? |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 510 | &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) { |
| 511 | DRM_ERROR("Failed to force on pll for pipe %c!\n", |
| 512 | pipe_name(pipe)); |
| 513 | return; |
| 514 | } |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 515 | } |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 516 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 517 | /* |
| 518 | * Similar magic as in intel_dp_enable_port(). |
| 519 | * We _must_ do this port enable + disable trick |
| 520 | * to make this power seqeuencer lock onto the port. |
| 521 | * Otherwise even VDD force bit won't work. |
| 522 | */ |
| 523 | I915_WRITE(intel_dp->output_reg, DP); |
| 524 | POSTING_READ(intel_dp->output_reg); |
| 525 | |
| 526 | I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN); |
| 527 | POSTING_READ(intel_dp->output_reg); |
| 528 | |
| 529 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
| 530 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 531 | |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 532 | if (!pll_enabled) { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 533 | vlv_force_pll_off(dev_priv, pipe); |
Ville Syrjälä | 0047eed | 2015-07-10 10:56:24 +0300 | [diff] [blame] | 534 | |
| 535 | if (release_cl_override) |
| 536 | chv_phy_powergate_ch(dev_priv, phy, ch, false); |
| 537 | } |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 538 | } |
| 539 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 540 | static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv) |
| 541 | { |
| 542 | struct intel_encoder *encoder; |
| 543 | unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); |
| 544 | |
| 545 | /* |
| 546 | * We don't have power sequencer currently. |
| 547 | * Pick one that's not used by other ports. |
| 548 | */ |
| 549 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 550 | struct intel_dp *intel_dp; |
| 551 | |
| 552 | if (encoder->type != INTEL_OUTPUT_DP && |
| 553 | encoder->type != INTEL_OUTPUT_EDP) |
| 554 | continue; |
| 555 | |
| 556 | intel_dp = enc_to_intel_dp(&encoder->base); |
| 557 | |
| 558 | if (encoder->type == INTEL_OUTPUT_EDP) { |
| 559 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 560 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 561 | |
| 562 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 563 | pipes &= ~(1 << intel_dp->pps_pipe); |
| 564 | } else { |
| 565 | WARN_ON(intel_dp->pps_pipe != INVALID_PIPE); |
| 566 | |
| 567 | if (intel_dp->active_pipe != INVALID_PIPE) |
| 568 | pipes &= ~(1 << intel_dp->active_pipe); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | if (pipes == 0) |
| 573 | return INVALID_PIPE; |
| 574 | |
| 575 | return ffs(pipes) - 1; |
| 576 | } |
| 577 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 578 | static enum pipe |
| 579 | vlv_power_sequencer_pipe(struct intel_dp *intel_dp) |
| 580 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 581 | 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] | 582 | 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] | 583 | enum pipe pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 584 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 585 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 586 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 587 | /* We should never land here with regular DP ports */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 588 | WARN_ON(!intel_dp_is_edp(intel_dp)); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 589 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 590 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 591 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 592 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 593 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 594 | return intel_dp->pps_pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 595 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 596 | pipe = vlv_find_free_pps(dev_priv); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 597 | |
| 598 | /* |
| 599 | * Didn't find one. This should not happen since there |
| 600 | * are two power sequencers and up to two eDP ports. |
| 601 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 602 | if (WARN_ON(pipe == INVALID_PIPE)) |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 603 | pipe = PIPE_A; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 604 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 605 | vlv_steal_power_sequencer(dev_priv, pipe); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 606 | intel_dp->pps_pipe = pipe; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 607 | |
| 608 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", |
| 609 | pipe_name(intel_dp->pps_pipe), |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 610 | port_name(intel_dig_port->base.port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 611 | |
| 612 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 613 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 614 | intel_dp_init_panel_power_sequencer_registers(intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 615 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 616 | /* |
| 617 | * Even vdd force doesn't work until we've made |
| 618 | * the power sequencer lock in on the port. |
| 619 | */ |
| 620 | vlv_power_sequencer_kick(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 621 | |
| 622 | return intel_dp->pps_pipe; |
| 623 | } |
| 624 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 625 | static int |
| 626 | bxt_power_sequencer_idx(struct intel_dp *intel_dp) |
| 627 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 628 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 629 | |
| 630 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 631 | |
| 632 | /* We should never land here with regular DP ports */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 633 | WARN_ON(!intel_dp_is_edp(intel_dp)); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 634 | |
| 635 | /* |
| 636 | * TODO: BXT has 2 PPS instances. The correct port->PPS instance |
| 637 | * mapping needs to be retrieved from VBT, for now just hard-code to |
| 638 | * use instance #0 always. |
| 639 | */ |
| 640 | if (!intel_dp->pps_reset) |
| 641 | return 0; |
| 642 | |
| 643 | intel_dp->pps_reset = false; |
| 644 | |
| 645 | /* |
| 646 | * Only the HW needs to be reprogrammed, the SW state is fixed and |
| 647 | * has been setup during connector init. |
| 648 | */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 649 | intel_dp_init_panel_power_sequencer_registers(intel_dp, false); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 654 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
| 655 | enum pipe pipe); |
| 656 | |
| 657 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, |
| 658 | enum pipe pipe) |
| 659 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 660 | return I915_READ(PP_STATUS(pipe)) & PP_ON; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, |
| 664 | enum pipe pipe) |
| 665 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 666 | return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, |
| 670 | enum pipe pipe) |
| 671 | { |
| 672 | return true; |
| 673 | } |
| 674 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 675 | static enum pipe |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 676 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
| 677 | enum port port, |
| 678 | vlv_pipe_check pipe_check) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 679 | { |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 680 | enum pipe pipe; |
| 681 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 682 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 683 | u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) & |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 684 | PANEL_PORT_SELECT_MASK; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 685 | |
| 686 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) |
| 687 | continue; |
| 688 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 689 | if (!pipe_check(dev_priv, pipe)) |
| 690 | continue; |
| 691 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 692 | return pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 693 | } |
| 694 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 695 | return INVALID_PIPE; |
| 696 | } |
| 697 | |
| 698 | static void |
| 699 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) |
| 700 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 701 | 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] | 702 | 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] | 703 | enum port port = intel_dig_port->base.port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 704 | |
| 705 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 706 | |
| 707 | /* try to find a pipe with this port selected */ |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 708 | /* first pick one where the panel is on */ |
| 709 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 710 | vlv_pipe_has_pp_on); |
| 711 | /* didn't find one? pick one where vdd is on */ |
| 712 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 713 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 714 | vlv_pipe_has_vdd_on); |
| 715 | /* didn't find one? pick one with just the correct port */ |
| 716 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 717 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 718 | vlv_pipe_any); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 719 | |
| 720 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ |
| 721 | if (intel_dp->pps_pipe == INVALID_PIPE) { |
| 722 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", |
| 723 | port_name(port)); |
| 724 | return; |
| 725 | } |
| 726 | |
| 727 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
| 728 | port_name(port), pipe_name(intel_dp->pps_pipe)); |
| 729 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 730 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 731 | intel_dp_init_panel_power_sequencer_registers(intel_dp, false); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 732 | } |
| 733 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 734 | void intel_power_sequencer_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 735 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 736 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 737 | struct intel_encoder *encoder; |
| 738 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 739 | 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] | 740 | !IS_GEN9_LP(dev_priv))) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 741 | return; |
| 742 | |
| 743 | /* |
| 744 | * We can't grab pps_mutex here due to deadlock with power_domain |
| 745 | * mutex when power_domain functions are called while holding pps_mutex. |
| 746 | * That also means that in order to use pps_pipe the code needs to |
| 747 | * hold both a power domain reference and pps_mutex, and the power domain |
| 748 | * reference get/put must be done while _not_ holding pps_mutex. |
| 749 | * pps_{lock,unlock}() do these steps in the correct order, so one |
| 750 | * should use them always. |
| 751 | */ |
| 752 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 753 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 754 | struct intel_dp *intel_dp; |
| 755 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 756 | if (encoder->type != INTEL_OUTPUT_DP && |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 757 | encoder->type != INTEL_OUTPUT_EDP && |
| 758 | encoder->type != INTEL_OUTPUT_DDI) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 759 | continue; |
| 760 | |
| 761 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 762 | |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 763 | /* Skip pure DVI/HDMI DDI encoders */ |
| 764 | if (!i915_mmio_reg_valid(intel_dp->output_reg)) |
| 765 | continue; |
| 766 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 767 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 768 | |
| 769 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 770 | continue; |
| 771 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 772 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 773 | intel_dp->pps_reset = true; |
| 774 | else |
| 775 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 776 | } |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 777 | } |
| 778 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 779 | struct pps_registers { |
| 780 | i915_reg_t pp_ctrl; |
| 781 | i915_reg_t pp_stat; |
| 782 | i915_reg_t pp_on; |
| 783 | i915_reg_t pp_off; |
| 784 | i915_reg_t pp_div; |
| 785 | }; |
| 786 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 787 | static void intel_pps_get_registers(struct intel_dp *intel_dp, |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 788 | struct pps_registers *regs) |
| 789 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 790 | 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] | 791 | int pps_idx = 0; |
| 792 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 793 | memset(regs, 0, sizeof(*regs)); |
| 794 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 795 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 796 | pps_idx = bxt_power_sequencer_idx(intel_dp); |
| 797 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 798 | pps_idx = vlv_power_sequencer_pipe(intel_dp); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 799 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 800 | regs->pp_ctrl = PP_CONTROL(pps_idx); |
| 801 | regs->pp_stat = PP_STATUS(pps_idx); |
| 802 | regs->pp_on = PP_ON_DELAYS(pps_idx); |
| 803 | regs->pp_off = PP_OFF_DELAYS(pps_idx); |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 804 | if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 805 | regs->pp_div = PP_DIVISOR(pps_idx); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 806 | } |
| 807 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 808 | static i915_reg_t |
| 809 | _pp_ctrl_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 810 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 811 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 812 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 813 | intel_pps_get_registers(intel_dp, ®s); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 814 | |
| 815 | return regs.pp_ctrl; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 816 | } |
| 817 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 818 | static i915_reg_t |
| 819 | _pp_stat_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 820 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 821 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 822 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 823 | intel_pps_get_registers(intel_dp, ®s); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 824 | |
| 825 | return regs.pp_stat; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 826 | } |
| 827 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 828 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
| 829 | This function only applicable when panel PM state is not to be tracked */ |
| 830 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, |
| 831 | void *unused) |
| 832 | { |
| 833 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), |
| 834 | edp_notifier); |
| 835 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 836 | struct drm_i915_private *dev_priv = to_i915(dev); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 837 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 838 | if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART) |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 839 | return 0; |
| 840 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 841 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 842 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 843 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 844 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 845 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 846 | u32 pp_div; |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 847 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 848 | pp_ctrl_reg = PP_CONTROL(pipe); |
| 849 | pp_div_reg = PP_DIVISOR(pipe); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 850 | pp_div = I915_READ(pp_div_reg); |
| 851 | pp_div &= PP_REFERENCE_DIVIDER_MASK; |
| 852 | |
| 853 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ |
| 854 | I915_WRITE(pp_div_reg, pp_div | 0x1F); |
| 855 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 856 | msleep(intel_dp->panel_power_cycle_delay); |
| 857 | } |
| 858 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 859 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 860 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 861 | return 0; |
| 862 | } |
| 863 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 864 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 865 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 866 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 867 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 868 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 869 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 870 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 871 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 872 | intel_dp->pps_pipe == INVALID_PIPE) |
| 873 | return false; |
| 874 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 875 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 878 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 879 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 880 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 881 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 882 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 883 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 884 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 885 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 886 | intel_dp->pps_pipe == INVALID_PIPE) |
| 887 | return false; |
| 888 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 889 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 892 | static void |
| 893 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 894 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 895 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 896 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 897 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 898 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 899 | return; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 900 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 901 | 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] | 902 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 903 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 904 | I915_READ(_pp_stat_reg(intel_dp)), |
| 905 | I915_READ(_pp_ctrl_reg(intel_dp))); |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 909 | static uint32_t |
| 910 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) |
| 911 | { |
| 912 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 913 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 914 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 915 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 916 | uint32_t status; |
| 917 | bool done; |
| 918 | |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 919 | #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] | 920 | if (has_aux_irq) |
Paulo Zanoni | b18ac46 | 2013-02-18 19:00:24 -0300 | [diff] [blame] | 921 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
Imre Deak | 3598706 | 2013-05-21 20:03:20 +0300 | [diff] [blame] | 922 | msecs_to_jiffies_timeout(10)); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 923 | else |
Imre Deak | 713a6b66 | 2016-06-28 13:37:33 +0300 | [diff] [blame] | 924 | done = wait_for(C, 10) == 0; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 925 | if (!done) |
| 926 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", |
| 927 | has_aux_irq); |
| 928 | #undef C |
| 929 | |
| 930 | return status; |
| 931 | } |
| 932 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 933 | 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] | 934 | { |
| 935 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 936 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 937 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 938 | if (index) |
| 939 | return 0; |
| 940 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 941 | /* |
| 942 | * 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] | 943 | * 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] | 944 | */ |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 945 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 949 | { |
| 950 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 951 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 952 | |
| 953 | if (index) |
| 954 | return 0; |
| 955 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 956 | /* |
| 957 | * The clock divider is based off the cdclk or PCH rawclk, and would |
| 958 | * like to run at 2MHz. So, take the cdclk or PCH rawclk value and |
| 959 | * divide by 2000 and use that |
| 960 | */ |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 961 | if (intel_dig_port->base.port == PORT_A) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 962 | return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 963 | else |
| 964 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | 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] | 968 | { |
| 969 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 970 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 971 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 972 | if (intel_dig_port->base.port != PORT_A && HAS_PCH_LPT_H(dev_priv)) { |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 973 | /* Workaround for non-ULT HSW */ |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 974 | switch (index) { |
| 975 | case 0: return 63; |
| 976 | case 1: return 72; |
| 977 | default: return 0; |
| 978 | } |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 979 | } |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 980 | |
| 981 | return ilk_get_aux_clock_divider(intel_dp, index); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 982 | } |
| 983 | |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 984 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 985 | { |
| 986 | /* |
| 987 | * SKL doesn't need us to program the AUX clock divider (Hardware will |
| 988 | * derive the clock from CDCLK automatically). We still implement the |
| 989 | * get_aux_clock_divider vfunc to plug-in into the existing code. |
| 990 | */ |
| 991 | return index ? 0 : 1; |
| 992 | } |
| 993 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 994 | static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 995 | bool has_aux_irq, |
| 996 | int send_bytes, |
| 997 | uint32_t aux_clock_divider) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 998 | { |
| 999 | 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] | 1000 | struct drm_i915_private *dev_priv = |
| 1001 | to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1002 | uint32_t precharge, timeout; |
| 1003 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 1004 | if (IS_GEN6(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1005 | precharge = 3; |
| 1006 | else |
| 1007 | precharge = 5; |
| 1008 | |
James Ausmus | 8f5f63d | 2017-10-12 14:30:37 -0700 | [diff] [blame] | 1009 | if (IS_BROADWELL(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1010 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
| 1011 | else |
| 1012 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; |
| 1013 | |
| 1014 | return DP_AUX_CH_CTL_SEND_BUSY | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1015 | DP_AUX_CH_CTL_DONE | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1016 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1017 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1018 | timeout | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1019 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1020 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 1021 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1022 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1025 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 1026 | bool has_aux_irq, |
| 1027 | int send_bytes, |
| 1028 | uint32_t unused) |
| 1029 | { |
| 1030 | return DP_AUX_CH_CTL_SEND_BUSY | |
| 1031 | DP_AUX_CH_CTL_DONE | |
| 1032 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
| 1033 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
James Ausmus | 6fa228b | 2017-10-12 14:30:36 -0700 | [diff] [blame] | 1034 | DP_AUX_CH_CTL_TIME_OUT_MAX | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1035 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
| 1036 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 1037 | DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1038 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); |
| 1039 | } |
| 1040 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1041 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1042 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
Daniel Vetter | bd9f74a | 2014-10-02 09:45:35 +0200 | [diff] [blame] | 1043 | const uint8_t *send, int send_bytes, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1044 | uint8_t *recv, int recv_size) |
| 1045 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1046 | 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] | 1047 | struct drm_i915_private *dev_priv = |
| 1048 | to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1049 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1050 | uint32_t aux_clock_divider; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1051 | int i, ret, recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1052 | uint32_t status; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1053 | int try, clock = 0; |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 1054 | bool has_aux_irq = HAS_AUX_IRQ(dev_priv); |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1055 | bool vdd; |
| 1056 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1057 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1058 | |
Ville Syrjälä | 72c3500 | 2014-08-18 22:16:00 +0300 | [diff] [blame] | 1059 | /* |
| 1060 | * We will be called with VDD already enabled for dpcd/edid/oui reads. |
| 1061 | * In such cases we want to leave VDD enabled and it's up to upper layers |
| 1062 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off |
| 1063 | * ourselves. |
| 1064 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 1065 | vdd = edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1066 | |
| 1067 | /* dp aux is extremely sensitive to irq latency, hence request the |
| 1068 | * lowest possible wakeup latency and so prevent the cpu from going into |
| 1069 | * deep sleep states. |
| 1070 | */ |
| 1071 | pm_qos_update_request(&dev_priv->pm_qos, 0); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1072 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 1073 | intel_dp_check_edp(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1074 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1075 | /* Try to wait for any previous AUX channel activity */ |
| 1076 | for (try = 0; try < 3; try++) { |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 1077 | status = I915_READ_NOTRACE(ch_ctl); |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1078 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 1079 | break; |
| 1080 | msleep(1); |
| 1081 | } |
| 1082 | |
| 1083 | if (try == 3) { |
Mika Kuoppala | 02196c7 | 2015-08-06 16:48:58 +0300 | [diff] [blame] | 1084 | static u32 last_status = -1; |
| 1085 | const u32 status = I915_READ(ch_ctl); |
| 1086 | |
| 1087 | if (status != last_status) { |
| 1088 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 1089 | status); |
| 1090 | last_status = status; |
| 1091 | } |
| 1092 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1093 | ret = -EBUSY; |
| 1094 | goto out; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1097 | /* Only 5 data registers! */ |
| 1098 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { |
| 1099 | ret = -E2BIG; |
| 1100 | goto out; |
| 1101 | } |
| 1102 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 1103 | while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) { |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 1104 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
| 1105 | has_aux_irq, |
| 1106 | send_bytes, |
| 1107 | aux_clock_divider); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1108 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1109 | /* Must try at least 3 times according to DP spec */ |
| 1110 | for (try = 0; try < 5; try++) { |
| 1111 | /* Load the send data into the aux channel data registers */ |
| 1112 | for (i = 0; i < send_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1113 | I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2], |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1114 | intel_dp_pack_aux(send + i, |
| 1115 | send_bytes - i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1116 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1117 | /* Send the command and wait for it to complete */ |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1118 | I915_WRITE(ch_ctl, send_ctl); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1119 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1120 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1121 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1122 | /* Clear done status and any errors */ |
| 1123 | I915_WRITE(ch_ctl, |
| 1124 | status | |
| 1125 | DP_AUX_CH_CTL_DONE | |
| 1126 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1127 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Adam Jackson | d7e96fe | 2011-07-26 15:39:46 -0400 | [diff] [blame] | 1128 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1129 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1130 | continue; |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 |
| 1133 | * 400us delay required for errors and timeouts |
| 1134 | * Timeout errors from the HW already meet this |
| 1135 | * requirement so skip to next iteration |
| 1136 | */ |
| 1137 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
| 1138 | usleep_range(400, 500); |
| 1139 | continue; |
| 1140 | } |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1141 | if (status & DP_AUX_CH_CTL_DONE) |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1142 | goto done; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1143 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1146 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1147 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1148 | ret = -EBUSY; |
| 1149 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1152 | done: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1153 | /* Check for timeout or receive error. |
| 1154 | * Timeouts occur when the sink is not connected |
| 1155 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1156 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1157 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1158 | ret = -EIO; |
| 1159 | goto out; |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1160 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1161 | |
| 1162 | /* Timeouts occur when the device isn't connected, so they're |
| 1163 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1164 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Chris Wilson | a5570fe | 2017-02-23 11:51:02 +0000 | [diff] [blame] | 1165 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1166 | ret = -ETIMEDOUT; |
| 1167 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /* Unload any bytes sent back from the other side */ |
| 1171 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 1172 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1173 | |
| 1174 | /* |
| 1175 | * By BSpec: "Message sizes of 0 or >20 are not allowed." |
| 1176 | * We have no idea of what happened so we return -EBUSY so |
| 1177 | * drm layer takes care for the necessary retries. |
| 1178 | */ |
| 1179 | if (recv_bytes == 0 || recv_bytes > 20) { |
| 1180 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", |
| 1181 | recv_bytes); |
| 1182 | /* |
| 1183 | * FIXME: This patch was created on top of a series that |
| 1184 | * organize the retries at drm level. There EBUSY should |
| 1185 | * also take care for 1ms wait before retrying. |
| 1186 | * That aux retries re-org is still needed and after that is |
| 1187 | * merged we remove this sleep from here. |
| 1188 | */ |
| 1189 | usleep_range(1000, 1500); |
| 1190 | ret = -EBUSY; |
| 1191 | goto out; |
| 1192 | } |
| 1193 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1194 | if (recv_bytes > recv_size) |
| 1195 | recv_bytes = recv_size; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1196 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1197 | for (i = 0; i < recv_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1198 | intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]), |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1199 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1200 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1201 | ret = recv_bytes; |
| 1202 | out: |
| 1203 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); |
| 1204 | |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1205 | if (vdd) |
| 1206 | edp_panel_vdd_off(intel_dp, false); |
| 1207 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1208 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1209 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1210 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1213 | #define BARE_ADDRESS_SIZE 3 |
| 1214 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1215 | static ssize_t |
| 1216 | 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] | 1217 | { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1218 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
| 1219 | uint8_t txbuf[20], rxbuf[20]; |
| 1220 | size_t txsize, rxsize; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1221 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1222 | |
Ville Syrjälä | d2d9cbb | 2015-03-19 11:44:06 +0200 | [diff] [blame] | 1223 | txbuf[0] = (msg->request << 4) | |
| 1224 | ((msg->address >> 16) & 0xf); |
| 1225 | txbuf[1] = (msg->address >> 8) & 0xff; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1226 | txbuf[2] = msg->address & 0xff; |
| 1227 | txbuf[3] = msg->size - 1; |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1228 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1229 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
| 1230 | case DP_AUX_NATIVE_WRITE: |
| 1231 | case DP_AUX_I2C_WRITE: |
Ville Syrjälä | c1e74122 | 2015-08-27 17:23:27 +0300 | [diff] [blame] | 1232 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1233 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1234 | rxsize = 2; /* 0 or 1 data bytes */ |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1235 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1236 | if (WARN_ON(txsize > 20)) |
| 1237 | return -E2BIG; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1238 | |
Ville Syrjälä | dd78809 | 2016-07-28 17:55:04 +0300 | [diff] [blame] | 1239 | WARN_ON(!msg->buffer != !msg->size); |
| 1240 | |
Imre Deak | d81a67c | 2016-01-29 14:52:26 +0200 | [diff] [blame] | 1241 | if (msg->buffer) |
| 1242 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1243 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1244 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1245 | if (ret > 0) { |
| 1246 | msg->reply = rxbuf[0] >> 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1247 | |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1248 | if (ret > 1) { |
| 1249 | /* Number of bytes written in a short write. */ |
| 1250 | ret = clamp_t(int, rxbuf[1], 0, msg->size); |
| 1251 | } else { |
| 1252 | /* Return payload size. */ |
| 1253 | ret = msg->size; |
| 1254 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1255 | } |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1256 | break; |
| 1257 | |
| 1258 | case DP_AUX_NATIVE_READ: |
| 1259 | case DP_AUX_I2C_READ: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1260 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1261 | rxsize = msg->size + 1; |
| 1262 | |
| 1263 | if (WARN_ON(rxsize > 20)) |
| 1264 | return -E2BIG; |
| 1265 | |
| 1266 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1267 | if (ret > 0) { |
| 1268 | msg->reply = rxbuf[0] >> 4; |
| 1269 | /* |
| 1270 | * Assume happy day, and copy the data. The caller is |
| 1271 | * expected to check msg->reply before touching it. |
| 1272 | * |
| 1273 | * Return payload size. |
| 1274 | */ |
| 1275 | ret--; |
| 1276 | memcpy(msg->buffer, rxbuf + 1, ret); |
| 1277 | } |
| 1278 | break; |
| 1279 | |
| 1280 | default: |
| 1281 | ret = -EINVAL; |
| 1282 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1283 | } |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1284 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1285 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1288 | static enum port intel_aux_port(struct drm_i915_private *dev_priv, |
| 1289 | enum port port) |
| 1290 | { |
| 1291 | const struct ddi_vbt_port_info *info = |
| 1292 | &dev_priv->vbt.ddi_port_info[port]; |
| 1293 | enum port aux_port; |
| 1294 | |
| 1295 | if (!info->alternate_aux_channel) { |
| 1296 | DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n", |
| 1297 | port_name(port), port_name(port)); |
| 1298 | return port; |
| 1299 | } |
| 1300 | |
| 1301 | switch (info->alternate_aux_channel) { |
| 1302 | case DP_AUX_A: |
| 1303 | aux_port = PORT_A; |
| 1304 | break; |
| 1305 | case DP_AUX_B: |
| 1306 | aux_port = PORT_B; |
| 1307 | break; |
| 1308 | case DP_AUX_C: |
| 1309 | aux_port = PORT_C; |
| 1310 | break; |
| 1311 | case DP_AUX_D: |
| 1312 | aux_port = PORT_D; |
| 1313 | break; |
| 1314 | default: |
| 1315 | MISSING_CASE(info->alternate_aux_channel); |
| 1316 | aux_port = PORT_A; |
| 1317 | break; |
| 1318 | } |
| 1319 | |
| 1320 | DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n", |
| 1321 | port_name(aux_port), port_name(port)); |
| 1322 | |
| 1323 | return aux_port; |
| 1324 | } |
| 1325 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1326 | static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1327 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1328 | { |
| 1329 | switch (port) { |
| 1330 | case PORT_B: |
| 1331 | case PORT_C: |
| 1332 | case PORT_D: |
| 1333 | return DP_AUX_CH_CTL(port); |
| 1334 | default: |
| 1335 | MISSING_CASE(port); |
| 1336 | return DP_AUX_CH_CTL(PORT_B); |
| 1337 | } |
| 1338 | } |
| 1339 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1340 | static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1341 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1342 | { |
| 1343 | switch (port) { |
| 1344 | case PORT_B: |
| 1345 | case PORT_C: |
| 1346 | case PORT_D: |
| 1347 | return DP_AUX_CH_DATA(port, index); |
| 1348 | default: |
| 1349 | MISSING_CASE(port); |
| 1350 | return DP_AUX_CH_DATA(PORT_B, index); |
| 1351 | } |
| 1352 | } |
| 1353 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1354 | static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1355 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1356 | { |
| 1357 | switch (port) { |
| 1358 | case PORT_A: |
| 1359 | return DP_AUX_CH_CTL(port); |
| 1360 | case PORT_B: |
| 1361 | case PORT_C: |
| 1362 | case PORT_D: |
| 1363 | return PCH_DP_AUX_CH_CTL(port); |
| 1364 | default: |
| 1365 | MISSING_CASE(port); |
| 1366 | return DP_AUX_CH_CTL(PORT_A); |
| 1367 | } |
| 1368 | } |
| 1369 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1370 | static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1371 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1372 | { |
| 1373 | switch (port) { |
| 1374 | case PORT_A: |
| 1375 | return DP_AUX_CH_DATA(port, index); |
| 1376 | case PORT_B: |
| 1377 | case PORT_C: |
| 1378 | case PORT_D: |
| 1379 | return PCH_DP_AUX_CH_DATA(port, index); |
| 1380 | default: |
| 1381 | MISSING_CASE(port); |
| 1382 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1383 | } |
| 1384 | } |
| 1385 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1386 | static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1387 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1388 | { |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1389 | switch (port) { |
| 1390 | case PORT_A: |
| 1391 | case PORT_B: |
| 1392 | case PORT_C: |
| 1393 | case PORT_D: |
| 1394 | return DP_AUX_CH_CTL(port); |
| 1395 | default: |
| 1396 | MISSING_CASE(port); |
| 1397 | return DP_AUX_CH_CTL(PORT_A); |
| 1398 | } |
| 1399 | } |
| 1400 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1401 | static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1402 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1403 | { |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1404 | switch (port) { |
| 1405 | case PORT_A: |
| 1406 | case PORT_B: |
| 1407 | case PORT_C: |
| 1408 | case PORT_D: |
| 1409 | return DP_AUX_CH_DATA(port, index); |
| 1410 | default: |
| 1411 | MISSING_CASE(port); |
| 1412 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1413 | } |
| 1414 | } |
| 1415 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1416 | static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1417 | enum port port) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1418 | { |
| 1419 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1420 | return skl_aux_ctl_reg(dev_priv, port); |
| 1421 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1422 | return ilk_aux_ctl_reg(dev_priv, port); |
| 1423 | else |
| 1424 | return g4x_aux_ctl_reg(dev_priv, port); |
| 1425 | } |
| 1426 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1427 | static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv, |
Ville Syrjälä | c8a89b0 | 2016-10-11 20:52:48 +0300 | [diff] [blame] | 1428 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1429 | { |
| 1430 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1431 | return skl_aux_data_reg(dev_priv, port, index); |
| 1432 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1433 | return ilk_aux_data_reg(dev_priv, port, index); |
| 1434 | else |
| 1435 | return g4x_aux_data_reg(dev_priv, port, index); |
| 1436 | } |
| 1437 | |
| 1438 | static void intel_aux_reg_init(struct intel_dp *intel_dp) |
| 1439 | { |
| 1440 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1441 | enum port port = intel_aux_port(dev_priv, |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1442 | dp_to_dig_port(intel_dp)->base.port); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1443 | int i; |
| 1444 | |
| 1445 | intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); |
| 1446 | for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++) |
| 1447 | intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i); |
| 1448 | } |
| 1449 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1450 | static void |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1451 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
| 1452 | { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1453 | kfree(intel_dp->aux.name); |
| 1454 | } |
| 1455 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1456 | static void |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 1457 | intel_dp_aux_init(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1458 | { |
Jani Nikula | 33ad662 | 2014-03-14 16:51:16 +0200 | [diff] [blame] | 1459 | 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] | 1460 | enum port port = intel_dig_port->base.port; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1461 | |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1462 | intel_aux_reg_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1463 | drm_dp_aux_init(&intel_dp->aux); |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 1464 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1465 | /* Failure to allocate our preferred name is not critical */ |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1466 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port)); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1467 | intel_dp->aux.transfer = intel_dp_aux_transfer; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1470 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1471 | { |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 1472 | 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] | 1473 | |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 1474 | return max_rate >= 540000; |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1475 | } |
| 1476 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 1477 | static void |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1478 | intel_dp_set_clock(struct intel_encoder *encoder, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1479 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1480 | { |
| 1481 | struct drm_device *dev = encoder->base.dev; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1482 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1483 | const struct dp_link_dpll *divisor = NULL; |
| 1484 | int i, count = 0; |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1485 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 1486 | if (IS_G4X(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1487 | divisor = gen4_dpll; |
| 1488 | count = ARRAY_SIZE(gen4_dpll); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1489 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1490 | divisor = pch_dpll; |
| 1491 | count = ARRAY_SIZE(pch_dpll); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1492 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1493 | divisor = chv_dpll; |
| 1494 | count = ARRAY_SIZE(chv_dpll); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 1495 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 1496 | divisor = vlv_dpll; |
| 1497 | count = ARRAY_SIZE(vlv_dpll); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1498 | } |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1499 | |
| 1500 | if (divisor && count) { |
| 1501 | for (i = 0; i < count; i++) { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1502 | if (pipe_config->port_clock == divisor[i].clock) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1503 | pipe_config->dpll = divisor[i].dpll; |
| 1504 | pipe_config->clock_set = true; |
| 1505 | break; |
| 1506 | } |
| 1507 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1508 | } |
| 1509 | } |
| 1510 | |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1511 | static void snprintf_int_array(char *str, size_t len, |
| 1512 | const int *array, int nelem) |
| 1513 | { |
| 1514 | int i; |
| 1515 | |
| 1516 | str[0] = '\0'; |
| 1517 | |
| 1518 | for (i = 0; i < nelem; i++) { |
Jani Nikula | b2f505b | 2015-05-18 16:01:45 +0300 | [diff] [blame] | 1519 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1520 | if (r >= len) |
| 1521 | return; |
| 1522 | str += r; |
| 1523 | len -= r; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | static void intel_dp_print_rates(struct intel_dp *intel_dp) |
| 1528 | { |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1529 | char str[128]; /* FIXME: too big for stack? */ |
| 1530 | |
| 1531 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 1532 | return; |
| 1533 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 1534 | snprintf_int_array(str, sizeof(str), |
| 1535 | intel_dp->source_rates, intel_dp->num_source_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1536 | DRM_DEBUG_KMS("source rates: %s\n", str); |
| 1537 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 1538 | snprintf_int_array(str, sizeof(str), |
| 1539 | intel_dp->sink_rates, intel_dp->num_sink_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1540 | DRM_DEBUG_KMS("sink rates: %s\n", str); |
| 1541 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1542 | snprintf_int_array(str, sizeof(str), |
| 1543 | intel_dp->common_rates, intel_dp->num_common_rates); |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1544 | DRM_DEBUG_KMS("common rates: %s\n", str); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1545 | } |
| 1546 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1547 | int |
| 1548 | intel_dp_max_link_rate(struct intel_dp *intel_dp) |
| 1549 | { |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1550 | int len; |
| 1551 | |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 1552 | 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] | 1553 | if (WARN_ON(len <= 0)) |
| 1554 | return 162000; |
| 1555 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1556 | return intel_dp->common_rates[len - 1]; |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1559 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
| 1560 | { |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 1561 | int i = intel_dp_rate_index(intel_dp->sink_rates, |
| 1562 | intel_dp->num_sink_rates, rate); |
Jani Nikula | b5c72b2 | 2017-03-28 17:59:02 +0300 | [diff] [blame] | 1563 | |
| 1564 | if (WARN_ON(i < 0)) |
| 1565 | i = 0; |
| 1566 | |
| 1567 | return i; |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 1570 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
| 1571 | uint8_t *link_bw, uint8_t *rate_select) |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1572 | { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 1573 | /* eDP 1.4 rate select method. */ |
| 1574 | if (intel_dp->use_rate_select) { |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1575 | *link_bw = 0; |
| 1576 | *rate_select = |
| 1577 | intel_dp_rate_select(intel_dp, port_clock); |
| 1578 | } else { |
| 1579 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); |
| 1580 | *rate_select = 0; |
| 1581 | } |
| 1582 | } |
| 1583 | |
Jani Nikula | f580bea | 2016-09-15 16:28:52 +0300 | [diff] [blame] | 1584 | static int intel_dp_compute_bpp(struct intel_dp *intel_dp, |
| 1585 | struct intel_crtc_state *pipe_config) |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1586 | { |
| 1587 | int bpp, bpc; |
| 1588 | |
| 1589 | bpp = pipe_config->pipe_bpp; |
| 1590 | bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports); |
| 1591 | |
| 1592 | if (bpc > 0) |
| 1593 | bpp = min(bpp, 3*bpc); |
| 1594 | |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 1595 | /* For DP Compliance we override the computed bpp for the pipe */ |
| 1596 | if (intel_dp->compliance.test_data.bpc != 0) { |
| 1597 | pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc; |
| 1598 | pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3; |
| 1599 | DRM_DEBUG_KMS("Setting pipe_bpp to %d\n", |
| 1600 | pipe_config->pipe_bpp); |
| 1601 | } |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1602 | return bpp; |
| 1603 | } |
| 1604 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 1605 | static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1, |
| 1606 | struct drm_display_mode *m2) |
| 1607 | { |
| 1608 | bool bres = false; |
| 1609 | |
| 1610 | if (m1 && m2) |
| 1611 | bres = (m1->hdisplay == m2->hdisplay && |
| 1612 | m1->hsync_start == m2->hsync_start && |
| 1613 | m1->hsync_end == m2->hsync_end && |
| 1614 | m1->htotal == m2->htotal && |
| 1615 | m1->vdisplay == m2->vdisplay && |
| 1616 | m1->vsync_start == m2->vsync_start && |
| 1617 | m1->vsync_end == m2->vsync_end && |
| 1618 | m1->vtotal == m2->vtotal); |
| 1619 | return bres; |
| 1620 | } |
| 1621 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1622 | bool |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1623 | intel_dp_compute_config(struct intel_encoder *encoder, |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 1624 | struct intel_crtc_state *pipe_config, |
| 1625 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1626 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1627 | 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] | 1628 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1629 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1630 | enum port port = encoder->port; |
Ander Conselvan de Oliveira | 84556d5 | 2015-03-20 16:18:10 +0200 | [diff] [blame] | 1631 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1632 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1633 | struct intel_digital_connector_state *intel_conn_state = |
| 1634 | to_intel_digital_connector_state(conn_state); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1635 | int lane_count, clock; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1636 | int min_lane_count = 1; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 1637 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
Todd Previte | 06ea66b | 2014-01-20 10:19:39 -0700 | [diff] [blame] | 1638 | /* Conveniently, the link BW constants become indices with a shift...*/ |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1639 | int min_clock = 0; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1640 | int max_clock; |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1641 | int bpp, mode_rate; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1642 | int link_avail, link_clock; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1643 | int common_len; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1644 | uint8_t link_bw, rate_select; |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1645 | bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc, |
| 1646 | DP_DPCD_QUIRK_LIMITED_M_N); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1647 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1648 | common_len = intel_dp_common_len_rate_limit(intel_dp, |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 1649 | intel_dp->max_link_rate); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1650 | |
| 1651 | /* No common link rates between source and sink */ |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1652 | WARN_ON(common_len <= 0); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1653 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1654 | max_clock = common_len - 1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1655 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1656 | 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] | 1657 | pipe_config->has_pch_encoder = true; |
| 1658 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1659 | pipe_config->has_drrs = false; |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 1660 | if (port == PORT_A) |
| 1661 | pipe_config->has_audio = false; |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1662 | else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO) |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 1663 | pipe_config->has_audio = intel_dp->has_audio; |
| 1664 | else |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1665 | pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1666 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1667 | if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 1668 | struct drm_display_mode *panel_mode = |
| 1669 | intel_connector->panel.alt_fixed_mode; |
| 1670 | struct drm_display_mode *req_mode = &pipe_config->base.mode; |
| 1671 | |
| 1672 | if (!intel_edp_compare_alt_mode(req_mode, panel_mode)) |
| 1673 | panel_mode = intel_connector->panel.fixed_mode; |
| 1674 | |
| 1675 | drm_mode_debug_printmodeline(panel_mode); |
| 1676 | |
| 1677 | intel_fixed_panel_mode(panel_mode, adjusted_mode); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1678 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1679 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1680 | int ret; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 1681 | ret = skl_update_scaler_crtc(pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1682 | if (ret) |
| 1683 | return ret; |
| 1684 | } |
| 1685 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 1686 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1687 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 1688 | conn_state->scaling_mode); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1689 | else |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 1690 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 1691 | conn_state->scaling_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 1692 | } |
| 1693 | |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 1694 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 1695 | return false; |
| 1696 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1697 | /* Use values requested by Compliance Test Request */ |
| 1698 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
Jani Nikula | ec990e2 | 2017-04-06 16:44:15 +0300 | [diff] [blame] | 1699 | int index; |
| 1700 | |
Manasi Navare | 140ef13 | 2017-06-08 13:41:03 -0700 | [diff] [blame] | 1701 | /* Validate the compliance test data since max values |
| 1702 | * might have changed due to link train fallback. |
| 1703 | */ |
| 1704 | if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate, |
| 1705 | intel_dp->compliance.test_lane_count)) { |
| 1706 | index = intel_dp_rate_index(intel_dp->common_rates, |
| 1707 | intel_dp->num_common_rates, |
| 1708 | intel_dp->compliance.test_link_rate); |
| 1709 | if (index >= 0) |
| 1710 | min_clock = max_clock = index; |
| 1711 | min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count; |
| 1712 | } |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1713 | } |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1714 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1715 | "max bw %d pixel clock %iKHz\n", |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1716 | max_lane_count, intel_dp->common_rates[max_clock], |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1717 | adjusted_mode->crtc_clock); |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1718 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1719 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
| 1720 | * bpc in between. */ |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1721 | bpp = intel_dp_compute_bpp(intel_dp, pipe_config); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1722 | if (intel_dp_is_edp(intel_dp)) { |
Thulasimani,Sivakumar | 22ce562 | 2015-07-31 11:05:27 +0530 | [diff] [blame] | 1723 | |
| 1724 | /* Get bpp from vbt only for panels that dont have bpp in edid */ |
| 1725 | if (intel_connector->base.display_info.bpc == 0 && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1726 | (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) { |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1727 | 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] | 1728 | dev_priv->vbt.edp.bpp); |
| 1729 | bpp = dev_priv->vbt.edp.bpp; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1730 | } |
| 1731 | |
Jani Nikula | 344c5bb | 2014-09-09 11:25:13 +0300 | [diff] [blame] | 1732 | /* |
| 1733 | * Use the maximum clock and number of lanes the eDP panel |
| 1734 | * advertizes being capable of. The panels are generally |
| 1735 | * designed to support only a single clock and lane |
| 1736 | * configuration, and typically these values correspond to the |
| 1737 | * native resolution of the panel. |
| 1738 | */ |
| 1739 | min_lane_count = max_lane_count; |
| 1740 | min_clock = max_clock; |
Imre Deak | 7984211 | 2013-07-18 17:44:13 +0300 | [diff] [blame] | 1741 | } |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1742 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1743 | for (; bpp >= 6*3; bpp -= 2*3) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1744 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
| 1745 | bpp); |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1746 | |
Dave Airlie | c693099 | 2014-07-14 11:04:39 +1000 | [diff] [blame] | 1747 | for (clock = min_clock; clock <= max_clock; clock++) { |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1748 | for (lane_count = min_lane_count; |
| 1749 | lane_count <= max_lane_count; |
| 1750 | lane_count <<= 1) { |
| 1751 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1752 | link_clock = intel_dp->common_rates[clock]; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1753 | link_avail = intel_dp_max_data_rate(link_clock, |
| 1754 | lane_count); |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 1755 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1756 | if (mode_rate <= link_avail) { |
| 1757 | goto found; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | return false; |
| 1764 | |
| 1765 | found: |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1766 | if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) { |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1767 | /* |
| 1768 | * See: |
| 1769 | * CEA-861-E - 5.1 Default Encoding Parameters |
| 1770 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry |
| 1771 | */ |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1772 | pipe_config->limited_color_range = |
Ville Syrjälä | c8127cf0 | 2017-01-11 16:18:35 +0200 | [diff] [blame] | 1773 | bpp != 18 && |
| 1774 | drm_default_rgb_quant_range(adjusted_mode) == |
| 1775 | HDMI_QUANTIZATION_RANGE_LIMITED; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1776 | } else { |
| 1777 | pipe_config->limited_color_range = |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1778 | intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1779 | } |
| 1780 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1781 | pipe_config->lane_count = lane_count; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1782 | |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1783 | pipe_config->pipe_bpp = bpp; |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1784 | pipe_config->port_clock = intel_dp->common_rates[clock]; |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1785 | |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1786 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
| 1787 | &link_bw, &rate_select); |
| 1788 | |
| 1789 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", |
| 1790 | link_bw, rate_select, pipe_config->lane_count, |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1791 | pipe_config->port_clock, bpp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1792 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
| 1793 | mode_rate, link_avail); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1794 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1795 | intel_link_compute_m_n(bpp, lane_count, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1796 | adjusted_mode->crtc_clock, |
| 1797 | pipe_config->port_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1798 | &pipe_config->dp_m_n, |
| 1799 | reduce_m_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1800 | |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1801 | if (intel_connector->panel.downclock_mode != NULL && |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 1802 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1803 | pipe_config->has_drrs = true; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1804 | intel_link_compute_m_n(bpp, lane_count, |
| 1805 | intel_connector->panel.downclock_mode->clock, |
| 1806 | pipe_config->port_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1807 | &pipe_config->dp_m2_n2, |
| 1808 | reduce_m_n); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1809 | } |
| 1810 | |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1811 | /* |
| 1812 | * DPLL0 VCO may need to be adjusted to get the correct |
| 1813 | * clock for eDP. This will affect cdclk as well. |
| 1814 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1815 | 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] | 1816 | int vco; |
| 1817 | |
| 1818 | switch (pipe_config->port_clock / 2) { |
| 1819 | case 108000: |
| 1820 | case 216000: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1821 | vco = 8640000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1822 | break; |
| 1823 | default: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1824 | vco = 8100000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1825 | break; |
| 1826 | } |
| 1827 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 1828 | 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] | 1829 | } |
| 1830 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1831 | if (!HAS_DDI(dev_priv)) |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1832 | intel_dp_set_clock(encoder, pipe_config); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1833 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 1834 | intel_psr_compute_config(intel_dp, pipe_config); |
| 1835 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1836 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1839 | 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] | 1840 | int link_rate, uint8_t lane_count, |
| 1841 | bool link_mst) |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1842 | { |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1843 | intel_dp->link_rate = link_rate; |
| 1844 | intel_dp->lane_count = lane_count; |
| 1845 | intel_dp->link_mst = link_mst; |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1846 | } |
| 1847 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1848 | static void intel_dp_prepare(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 1849 | const struct intel_crtc_state *pipe_config) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1850 | { |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1851 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1852 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1853 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1854 | enum port port = encoder->port; |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 1855 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1856 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1857 | |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1858 | intel_dp_set_link_params(intel_dp, pipe_config->port_clock, |
| 1859 | pipe_config->lane_count, |
| 1860 | intel_crtc_has_type(pipe_config, |
| 1861 | INTEL_OUTPUT_DP_MST)); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1862 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1863 | /* |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1864 | * There are four kinds of DP registers: |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1865 | * |
| 1866 | * IBX PCH |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1867 | * SNB CPU |
| 1868 | * IVB CPU |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1869 | * CPT PCH |
| 1870 | * |
| 1871 | * IBX PCH and CPU are the same for almost everything, |
| 1872 | * except that the CPU DP PLL is configured in this |
| 1873 | * register |
| 1874 | * |
| 1875 | * CPT PCH is quite different, having many bits moved |
| 1876 | * to the TRANS_DP_CTL register instead. That |
| 1877 | * configuration happens (oddly) in ironlake_pch_enable |
| 1878 | */ |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 1879 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1880 | /* Preserve the BIOS-computed detected bit. This is |
| 1881 | * supposed to be read-only. |
| 1882 | */ |
| 1883 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1884 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1885 | /* Handle DP bits in common between all three register formats */ |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1886 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1887 | intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1888 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1889 | /* Split out the IBX/CPU vs CPT settings */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1890 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1891 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1892 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1893 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1894 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1895 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1896 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
| 1897 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1898 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1899 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1900 | |
Daniel Vetter | 7c62a16 | 2013-06-01 17:16:20 +0200 | [diff] [blame] | 1901 | intel_dp->DP |= crtc->pipe << 29; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1902 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1903 | u32 trans_dp; |
| 1904 | |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1905 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1906 | |
| 1907 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 1908 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 1909 | trans_dp |= TRANS_DP_ENH_FRAMING; |
| 1910 | else |
| 1911 | trans_dp &= ~TRANS_DP_ENH_FRAMING; |
| 1912 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1913 | } else { |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 1914 | if (IS_G4X(dev_priv) && pipe_config->limited_color_range) |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1915 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1916 | |
| 1917 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1918 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1919 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1920 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1921 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
| 1922 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1923 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1924 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1925 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1926 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1927 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1928 | else if (crtc->pipe == PIPE_B) |
| 1929 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1930 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1933 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
| 1934 | #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] | 1935 | |
Paulo Zanoni | 1a5ef5b | 2013-12-19 14:29:43 -0200 | [diff] [blame] | 1936 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
| 1937 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1938 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1939 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
| 1940 | #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] | 1941 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 1942 | static void intel_pps_verify_state(struct intel_dp *intel_dp); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1943 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1944 | static void wait_panel_status(struct intel_dp *intel_dp, |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1945 | u32 mask, |
| 1946 | u32 value) |
| 1947 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 1948 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1949 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1950 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1951 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1952 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 1953 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 1954 | intel_pps_verify_state(intel_dp); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1955 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 1956 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 1957 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1958 | |
| 1959 | DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1960 | mask, value, |
| 1961 | I915_READ(pp_stat_reg), |
| 1962 | I915_READ(pp_ctrl_reg)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1963 | |
Chris Wilson | 9036ff0 | 2016-06-30 15:33:09 +0100 | [diff] [blame] | 1964 | if (intel_wait_for_register(dev_priv, |
| 1965 | pp_stat_reg, mask, value, |
| 1966 | 5000)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1967 | DRM_ERROR("Panel status timeout: status %08x control %08x\n", |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 1968 | I915_READ(pp_stat_reg), |
| 1969 | I915_READ(pp_ctrl_reg)); |
Chris Wilson | 54c136d | 2013-12-02 09:57:16 +0000 | [diff] [blame] | 1970 | |
| 1971 | DRM_DEBUG_KMS("Wait complete\n"); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1974 | static void wait_panel_on(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1975 | { |
| 1976 | DRM_DEBUG_KMS("Wait for panel power on\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1977 | wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1980 | static void wait_panel_off(struct intel_dp *intel_dp) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1981 | { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1982 | DRM_DEBUG_KMS("Wait for panel power off time\n"); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1983 | wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1984 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1985 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1986 | static void wait_panel_power_cycle(struct intel_dp *intel_dp) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1987 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1988 | ktime_t panel_power_on_time; |
| 1989 | s64 panel_power_off_duration; |
| 1990 | |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1991 | DRM_DEBUG_KMS("Wait for panel power cycle\n"); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1992 | |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 1993 | /* take the difference of currrent time and panel power off time |
| 1994 | * and then make panel wait for t11_t12 if needed. */ |
| 1995 | panel_power_on_time = ktime_get_boottime(); |
| 1996 | panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time); |
| 1997 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 1998 | /* When we disable the VDD override bit last we have to do the manual |
| 1999 | * wait. */ |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2000 | if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay) |
| 2001 | wait_remaining_ms_from_jiffies(jiffies, |
| 2002 | intel_dp->panel_power_cycle_delay - panel_power_off_duration); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2003 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2004 | wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2005 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2006 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2007 | static void wait_backlight_on(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2008 | { |
| 2009 | wait_remaining_ms_from_jiffies(intel_dp->last_power_on, |
| 2010 | intel_dp->backlight_on_delay); |
| 2011 | } |
| 2012 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2013 | static void edp_wait_backlight_off(struct intel_dp *intel_dp) |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2014 | { |
| 2015 | wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off, |
| 2016 | intel_dp->backlight_off_delay); |
| 2017 | } |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2018 | |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2019 | /* Read the current pp_control value, unlocking the register if it |
| 2020 | * is locked |
| 2021 | */ |
| 2022 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2023 | static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2024 | { |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2025 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2026 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2027 | u32 control; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2028 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2029 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2030 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2031 | control = I915_READ(_pp_ctrl_reg(intel_dp)); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 2032 | if (WARN_ON(!HAS_DDI(dev_priv) && |
| 2033 | (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 2034 | control &= ~PANEL_UNLOCK_MASK; |
| 2035 | control |= PANEL_UNLOCK_REGS; |
| 2036 | } |
Keith Packard | 832dd3c | 2011-11-01 19:34:06 -0700 | [diff] [blame] | 2037 | return control; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2040 | /* |
| 2041 | * Must be paired with edp_panel_vdd_off(). |
| 2042 | * Must hold pps_mutex around the whole on/off sequence. |
| 2043 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2044 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 2045 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2046 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2047 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2048 | 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] | 2049 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2050 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2051 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2052 | bool need_to_disable = !intel_dp->want_panel_vdd; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2053 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2054 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2055 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2056 | if (!intel_dp_is_edp(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2057 | return false; |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2058 | |
Egbert Eich | 2c623c1 | 2014-11-25 12:54:57 +0100 | [diff] [blame] | 2059 | cancel_delayed_work(&intel_dp->panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2060 | intel_dp->want_panel_vdd = true; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2061 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2062 | if (edp_have_panel_vdd(intel_dp)) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2063 | return need_to_disable; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2064 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2065 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2066 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2067 | DRM_DEBUG_KMS("Turning eDP port %c VDD on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2068 | port_name(intel_dig_port->base.port)); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2069 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2070 | if (!edp_have_panel_power(intel_dp)) |
| 2071 | wait_panel_power_cycle(intel_dp); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2072 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2073 | pp = ironlake_get_pp_control(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2074 | pp |= EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2075 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2076 | pp_stat_reg = _pp_stat_reg(intel_dp); |
| 2077 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2078 | |
| 2079 | I915_WRITE(pp_ctrl_reg, pp); |
| 2080 | POSTING_READ(pp_ctrl_reg); |
| 2081 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2082 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 2083 | /* |
| 2084 | * If the panel wasn't on, delay before accessing aux channel |
| 2085 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2086 | if (!edp_have_panel_power(intel_dp)) { |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2087 | 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] | 2088 | port_name(intel_dig_port->base.port)); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2089 | msleep(intel_dp->panel_power_up_delay); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2090 | } |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2091 | |
| 2092 | return need_to_disable; |
| 2093 | } |
| 2094 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2095 | /* |
| 2096 | * Must be paired with intel_edp_panel_vdd_off() or |
| 2097 | * intel_edp_panel_off(). |
| 2098 | * Nested calls to these functions are not allowed since |
| 2099 | * we drop the lock. Caller must use some higher level |
| 2100 | * locking to prevent nested calls from other threads. |
| 2101 | */ |
Daniel Vetter | b80d6c7 | 2014-03-19 15:54:37 +0100 | [diff] [blame] | 2102 | void intel_edp_panel_vdd_on(struct intel_dp *intel_dp) |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2103 | { |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2104 | bool vdd; |
Jani Nikula | adddaaf | 2014-03-14 16:51:13 +0200 | [diff] [blame] | 2105 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2106 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2107 | return; |
| 2108 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2109 | pps_lock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2110 | vdd = edp_panel_vdd_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2111 | pps_unlock(intel_dp); |
Ville Syrjälä | c695b6b | 2014-08-18 22:16:03 +0300 | [diff] [blame] | 2112 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2113 | 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] | 2114 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2115 | } |
| 2116 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2117 | static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2118 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2119 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2120 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2121 | struct intel_digital_port *intel_dig_port = |
| 2122 | dp_to_dig_port(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2123 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2124 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2125 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2126 | lockdep_assert_held(&dev_priv->pps_mutex); |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 2127 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2128 | WARN_ON(intel_dp->want_panel_vdd); |
Imre Deak | 4e6e1a5 | 2014-03-27 17:45:11 +0200 | [diff] [blame] | 2129 | |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2130 | if (!edp_have_panel_vdd(intel_dp)) |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2131 | return; |
Paulo Zanoni | b0665d5 | 2013-10-30 19:50:27 -0200 | [diff] [blame] | 2132 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2133 | DRM_DEBUG_KMS("Turning eDP port %c VDD off\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2134 | port_name(intel_dig_port->base.port)); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2135 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2136 | pp = ironlake_get_pp_control(intel_dp); |
| 2137 | pp &= ~EDP_FORCE_VDD; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2138 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2139 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
| 2140 | pp_stat_reg = _pp_stat_reg(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2141 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2142 | I915_WRITE(pp_ctrl_reg, pp); |
| 2143 | POSTING_READ(pp_ctrl_reg); |
Paulo Zanoni | 90791a5 | 2013-12-06 17:32:42 -0200 | [diff] [blame] | 2144 | |
Ville Syrjälä | be2c919 | 2014-08-18 22:16:01 +0300 | [diff] [blame] | 2145 | /* Make sure sequencer is idle before allowing subsequent activity */ |
| 2146 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", |
| 2147 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2148 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2149 | if ((pp & PANEL_POWER_ON) == 0) |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 2150 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | e9cb81a | 2013-11-21 13:47:23 -0200 | [diff] [blame] | 2151 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2152 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2155 | static void edp_panel_vdd_work(struct work_struct *__work) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2156 | { |
| 2157 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), |
| 2158 | struct intel_dp, panel_vdd_work); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2159 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2160 | pps_lock(intel_dp); |
Ville Syrjälä | 15e899a | 2014-08-18 22:16:02 +0300 | [diff] [blame] | 2161 | if (!intel_dp->want_panel_vdd) |
| 2162 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2163 | pps_unlock(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2164 | } |
| 2165 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2166 | static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) |
| 2167 | { |
| 2168 | unsigned long delay; |
| 2169 | |
| 2170 | /* |
| 2171 | * Queue the timer to fire a long time from now (relative to the power |
| 2172 | * down delay) to keep the panel power up across a sequence of |
| 2173 | * operations. |
| 2174 | */ |
| 2175 | delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5); |
| 2176 | schedule_delayed_work(&intel_dp->panel_vdd_work, delay); |
| 2177 | } |
| 2178 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 2179 | /* |
| 2180 | * Must be paired with edp_panel_vdd_on(). |
| 2181 | * Must hold pps_mutex around the whole on/off sequence. |
| 2182 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. |
| 2183 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2184 | 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] | 2185 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2186 | 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] | 2187 | |
| 2188 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2189 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2190 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2191 | return; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2192 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 2193 | 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] | 2194 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Keith Packard | f2e8b18 | 2011-11-01 20:01:35 -0700 | [diff] [blame] | 2195 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2196 | intel_dp->want_panel_vdd = false; |
| 2197 | |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2198 | if (sync) |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2199 | edp_panel_vdd_off_sync(intel_dp); |
Imre Deak | aba8689 | 2014-07-30 15:57:31 +0300 | [diff] [blame] | 2200 | else |
| 2201 | edp_panel_vdd_schedule_off(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2202 | } |
| 2203 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2204 | static void edp_panel_on(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2205 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2206 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2207 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2208 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2209 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2210 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2211 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2212 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2213 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2214 | return; |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2215 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2216 | DRM_DEBUG_KMS("Turn eDP port %c panel power on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2217 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2218 | |
Ville Syrjälä | e7a89ac | 2014-10-16 21:30:07 +0300 | [diff] [blame] | 2219 | if (WARN(edp_have_panel_power(intel_dp), |
| 2220 | "eDP port %c panel power already on\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2221 | port_name(dp_to_dig_port(intel_dp)->base.port))) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2222 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2223 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2224 | wait_panel_power_cycle(intel_dp); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2225 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2226 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2227 | pp = ironlake_get_pp_control(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2228 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2229 | /* ILK workaround: disable reset around power sequence */ |
| 2230 | pp &= ~PANEL_POWER_RESET; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2231 | I915_WRITE(pp_ctrl_reg, pp); |
| 2232 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2233 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2234 | |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2235 | pp |= PANEL_POWER_ON; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2236 | if (!IS_GEN5(dev_priv)) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2237 | pp |= PANEL_POWER_RESET; |
| 2238 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2239 | I915_WRITE(pp_ctrl_reg, pp); |
| 2240 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2241 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2242 | wait_panel_on(intel_dp); |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2243 | intel_dp->last_power_on = jiffies; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2244 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2245 | if (IS_GEN5(dev_priv)) { |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2246 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2247 | I915_WRITE(pp_ctrl_reg, pp); |
| 2248 | POSTING_READ(pp_ctrl_reg); |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 2249 | } |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2250 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2251 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2252 | void intel_edp_panel_on(struct intel_dp *intel_dp) |
| 2253 | { |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2254 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2255 | return; |
| 2256 | |
| 2257 | pps_lock(intel_dp); |
| 2258 | edp_panel_on(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2259 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2260 | } |
| 2261 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2262 | |
| 2263 | static void edp_panel_off(struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2264 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2265 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2266 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 2267 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2268 | i915_reg_t pp_ctrl_reg; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2269 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2270 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2271 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2272 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 2273 | return; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2274 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2275 | DRM_DEBUG_KMS("Turn eDP port %c panel power off\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2276 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 2277 | |
Ville Syrjälä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2278 | 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] | 2279 | port_name(dp_to_dig_port(intel_dp)->base.port)); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2280 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2281 | pp = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 35a3855 | 2012-08-12 22:17:14 +0200 | [diff] [blame] | 2282 | /* We need to switch off panel power _and_ force vdd, for otherwise some |
| 2283 | * panels get very unhappy and cease to work. */ |
Imre Deak | 5a162e2 | 2016-08-10 14:07:30 +0300 | [diff] [blame] | 2284 | pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | |
Patrik Jakobsson | b306415 | 2014-03-04 00:42:44 +0100 | [diff] [blame] | 2285 | EDP_BLC_ENABLE); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2286 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2287 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2288 | |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2289 | intel_dp->want_panel_vdd = false; |
| 2290 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2291 | I915_WRITE(pp_ctrl_reg, pp); |
| 2292 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2293 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2294 | wait_panel_off(intel_dp); |
Manasi Navare | cbacf02 | 2017-10-04 09:48:26 -0700 | [diff] [blame] | 2295 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Paulo Zanoni | 849e39f | 2014-03-07 20:05:20 -0300 | [diff] [blame] | 2296 | |
| 2297 | /* We got a reference when we enabled the VDD. */ |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 2298 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2299 | } |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2300 | |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2301 | void intel_edp_panel_off(struct intel_dp *intel_dp) |
| 2302 | { |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2303 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f0fb5b | 2014-10-16 21:27:32 +0300 | [diff] [blame] | 2304 | return; |
| 2305 | |
| 2306 | pps_lock(intel_dp); |
| 2307 | edp_panel_off(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2308 | pps_unlock(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2311 | /* Enable backlight in the panel power control. */ |
| 2312 | static void _intel_edp_backlight_on(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2313 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2314 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2315 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2316 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2317 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2318 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2319 | |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 2320 | /* |
| 2321 | * If we enable the backlight right away following a panel power |
| 2322 | * on, we may see slight flicker as the panel syncs with the eDP |
| 2323 | * link. So delay a bit to make sure the image is solid before |
| 2324 | * allowing it to appear. |
| 2325 | */ |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2326 | wait_backlight_on(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2327 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2328 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2329 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2330 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2331 | pp |= EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2332 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2333 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2334 | |
| 2335 | I915_WRITE(pp_ctrl_reg, pp); |
| 2336 | POSTING_READ(pp_ctrl_reg); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2337 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2338 | pps_unlock(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2339 | } |
| 2340 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2341 | /* Enable backlight PWM and backlight PP control. */ |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2342 | void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state, |
| 2343 | const struct drm_connector_state *conn_state) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2344 | { |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2345 | struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder); |
| 2346 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2347 | if (!intel_dp_is_edp(intel_dp)) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2348 | return; |
| 2349 | |
| 2350 | DRM_DEBUG_KMS("\n"); |
| 2351 | |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2352 | intel_panel_enable_backlight(crtc_state, conn_state); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2353 | _intel_edp_backlight_on(intel_dp); |
| 2354 | } |
| 2355 | |
| 2356 | /* Disable backlight in the panel power control. */ |
| 2357 | static void _intel_edp_backlight_off(struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2358 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 2359 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2360 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2361 | u32 pp; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2362 | i915_reg_t pp_ctrl_reg; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2363 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2364 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2365 | return; |
| 2366 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2367 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2368 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2369 | pp = ironlake_get_pp_control(intel_dp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2370 | pp &= ~EDP_BLC_ENABLE; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2371 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 2372 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 2373 | |
| 2374 | I915_WRITE(pp_ctrl_reg, pp); |
| 2375 | POSTING_READ(pp_ctrl_reg); |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2376 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2377 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2378 | |
Paulo Zanoni | dce56b3 | 2013-12-19 14:29:40 -0200 | [diff] [blame] | 2379 | intel_dp->last_backlight_off = jiffies; |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2380 | edp_wait_backlight_off(intel_dp); |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2381 | } |
Jesse Barnes | f7d2323 | 2014-03-31 11:13:56 -0700 | [diff] [blame] | 2382 | |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2383 | /* Disable backlight PP control and backlight PWM. */ |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2384 | 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] | 2385 | { |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2386 | struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder); |
| 2387 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2388 | if (!intel_dp_is_edp(intel_dp)) |
Jani Nikula | 1250d10 | 2014-08-12 17:11:39 +0300 | [diff] [blame] | 2389 | return; |
| 2390 | |
| 2391 | DRM_DEBUG_KMS("\n"); |
| 2392 | |
| 2393 | _intel_edp_backlight_off(intel_dp); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2394 | intel_panel_disable_backlight(old_conn_state); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2395 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2396 | |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2397 | /* |
| 2398 | * Hook for controlling the panel power control backlight through the bl_power |
| 2399 | * sysfs attribute. Take care to handle multiple calls. |
| 2400 | */ |
| 2401 | static void intel_edp_backlight_power(struct intel_connector *connector, |
| 2402 | bool enable) |
| 2403 | { |
| 2404 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2405 | bool is_enabled; |
| 2406 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2407 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 2408 | is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2409 | pps_unlock(intel_dp); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2410 | |
| 2411 | if (is_enabled == enable) |
| 2412 | return; |
| 2413 | |
Jani Nikula | 23ba937 | 2014-08-27 14:08:43 +0300 | [diff] [blame] | 2414 | DRM_DEBUG_KMS("panel power control backlight %s\n", |
| 2415 | enable ? "enable" : "disable"); |
Jani Nikula | 73580fb7 | 2014-08-12 17:11:41 +0300 | [diff] [blame] | 2416 | |
| 2417 | if (enable) |
| 2418 | _intel_edp_backlight_on(intel_dp); |
| 2419 | else |
| 2420 | _intel_edp_backlight_off(intel_dp); |
| 2421 | } |
| 2422 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2423 | static void assert_dp_port(struct intel_dp *intel_dp, bool state) |
| 2424 | { |
| 2425 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 2426 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 2427 | bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN; |
| 2428 | |
| 2429 | I915_STATE_WARN(cur_state != state, |
| 2430 | "DP port %c state assertion failure (expected %s, current %s)\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2431 | port_name(dig_port->base.port), |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2432 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2433 | } |
| 2434 | #define assert_dp_port_disabled(d) assert_dp_port((d), false) |
| 2435 | |
| 2436 | static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state) |
| 2437 | { |
| 2438 | bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE; |
| 2439 | |
| 2440 | I915_STATE_WARN(cur_state != state, |
| 2441 | "eDP PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 2442 | onoff(state), onoff(cur_state)); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2443 | } |
| 2444 | #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) |
| 2445 | #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) |
| 2446 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2447 | static void ironlake_edp_pll_on(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2448 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2449 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2450 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2451 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2452 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2453 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2454 | assert_dp_port_disabled(intel_dp); |
| 2455 | assert_edp_pll_disabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2456 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2457 | DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n", |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2458 | pipe_config->port_clock); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2459 | |
| 2460 | intel_dp->DP &= ~DP_PLL_FREQ_MASK; |
| 2461 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2462 | if (pipe_config->port_clock == 162000) |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2463 | intel_dp->DP |= DP_PLL_FREQ_162MHZ; |
| 2464 | else |
| 2465 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
| 2466 | |
| 2467 | I915_WRITE(DP_A, intel_dp->DP); |
| 2468 | POSTING_READ(DP_A); |
| 2469 | udelay(500); |
| 2470 | |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2471 | /* |
| 2472 | * [DevILK] Work around required when enabling DP PLL |
| 2473 | * while a pipe is enabled going to FDI: |
| 2474 | * 1. Wait for the start of vertical blank on the enabled pipe going to FDI |
| 2475 | * 2. Program DP PLL enable |
| 2476 | */ |
| 2477 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 2478 | intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe); |
Ville Syrjälä | 6b23f3e | 2016-04-01 21:53:19 +0300 | [diff] [blame] | 2479 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2480 | intel_dp->DP |= DP_PLL_ENABLE; |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2481 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2482 | I915_WRITE(DP_A, intel_dp->DP); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 2483 | POSTING_READ(DP_A); |
| 2484 | udelay(200); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2487 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp, |
| 2488 | const struct intel_crtc_state *old_crtc_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2489 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2490 | 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] | 2491 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2492 | |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2493 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 2494 | assert_dp_port_disabled(intel_dp); |
| 2495 | assert_edp_pll_enabled(dev_priv); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2496 | |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2497 | DRM_DEBUG_KMS("disabling eDP PLL\n"); |
| 2498 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2499 | intel_dp->DP &= ~DP_PLL_ENABLE; |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 2500 | |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2501 | I915_WRITE(DP_A, intel_dp->DP); |
Chris Wilson | 1af5fa1 | 2010-09-08 21:07:28 +0100 | [diff] [blame] | 2502 | POSTING_READ(DP_A); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2503 | udelay(200); |
| 2504 | } |
| 2505 | |
Ville Syrjälä | 857c416 | 2017-10-27 12:45:23 +0300 | [diff] [blame] | 2506 | static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp) |
| 2507 | { |
| 2508 | /* |
| 2509 | * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus |
| 2510 | * be capable of signalling downstream hpd with a long pulse. |
| 2511 | * Whether or not that means D3 is safe to use is not clear, |
| 2512 | * but let's assume so until proven otherwise. |
| 2513 | * |
| 2514 | * FIXME should really check all downstream ports... |
| 2515 | */ |
| 2516 | return intel_dp->dpcd[DP_DPCD_REV] == 0x11 && |
| 2517 | intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT && |
| 2518 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD; |
| 2519 | } |
| 2520 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2521 | /* If the sink supports it, try to set the power state appropriately */ |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2522 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2523 | { |
| 2524 | int ret, i; |
| 2525 | |
| 2526 | /* Should have a valid DPCD by this point */ |
| 2527 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 2528 | return; |
| 2529 | |
| 2530 | if (mode != DRM_MODE_DPMS_ON) { |
Ville Syrjälä | 857c416 | 2017-10-27 12:45:23 +0300 | [diff] [blame] | 2531 | if (downstream_hpd_needs_d0(intel_dp)) |
| 2532 | return; |
| 2533 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2534 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2535 | DP_SET_POWER_D3); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2536 | } else { |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2537 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
| 2538 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2539 | /* |
| 2540 | * When turning on, we need to retry for 1ms to give the sink |
| 2541 | * time to wake up. |
| 2542 | */ |
| 2543 | for (i = 0; i < 3; i++) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2544 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2545 | DP_SET_POWER_D0); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2546 | if (ret == 1) |
| 2547 | break; |
| 2548 | msleep(1); |
| 2549 | } |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2550 | |
| 2551 | if (ret == 1 && lspcon->active) |
| 2552 | lspcon_wait_pcon_mode(lspcon); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2553 | } |
Jani Nikula | f9cac72 | 2014-09-02 16:33:52 +0300 | [diff] [blame] | 2554 | |
| 2555 | if (ret != 1) |
| 2556 | DRM_DEBUG_KMS("failed to %s sink power state\n", |
| 2557 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2560 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
| 2561 | enum pipe *pipe) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2562 | { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2563 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2564 | enum port port = encoder->port; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2565 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2566 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2567 | u32 tmp; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2568 | bool ret; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2569 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2570 | if (!intel_display_power_get_if_enabled(dev_priv, |
| 2571 | encoder->power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2572 | return false; |
| 2573 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2574 | ret = false; |
| 2575 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2576 | tmp = I915_READ(intel_dp->output_reg); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2577 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2578 | if (!(tmp & DP_PORT_EN)) |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2579 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2580 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2581 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2582 | *pipe = PORT_TO_PIPE_CPT(tmp); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2583 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2584 | enum pipe p; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2585 | |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2586 | for_each_pipe(dev_priv, p) { |
| 2587 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); |
| 2588 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { |
| 2589 | *pipe = p; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2590 | ret = true; |
| 2591 | |
| 2592 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2593 | } |
| 2594 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2595 | |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2596 | 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] | 2597 | i915_mmio_reg_offset(intel_dp->output_reg)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2598 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2599 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); |
| 2600 | } else { |
| 2601 | *pipe = PORT_TO_PIPE(tmp); |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2602 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2603 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2604 | ret = true; |
| 2605 | |
| 2606 | out: |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2607 | intel_display_power_put(dev_priv, encoder->power_domain); |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2608 | |
| 2609 | return ret; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2610 | } |
| 2611 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2612 | static void intel_dp_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2613 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2614 | { |
| 2615 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2616 | u32 tmp, flags = 0; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2617 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2618 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2619 | enum port port = encoder->port; |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2620 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2621 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 2622 | if (encoder->type == INTEL_OUTPUT_EDP) |
| 2623 | pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP); |
| 2624 | else |
| 2625 | pipe_config->output_types |= BIT(INTEL_OUTPUT_DP); |
| 2626 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2627 | tmp = I915_READ(intel_dp->output_reg); |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 2628 | |
| 2629 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2630 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2631 | if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2632 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 2633 | |
| 2634 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2635 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2636 | else |
| 2637 | flags |= DRM_MODE_FLAG_NHSYNC; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2638 | |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2639 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2640 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2641 | else |
| 2642 | flags |= DRM_MODE_FLAG_NVSYNC; |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2643 | } else { |
| 2644 | if (tmp & DP_SYNC_HS_HIGH) |
| 2645 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2646 | else |
| 2647 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2648 | |
| 2649 | if (tmp & DP_SYNC_VS_HIGH) |
| 2650 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2651 | else |
| 2652 | flags |= DRM_MODE_FLAG_NVSYNC; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2653 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2654 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2655 | pipe_config->base.adjusted_mode.flags |= flags; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2656 | |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 2657 | if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235) |
Ville Syrjälä | 8c875fc | 2014-09-12 15:46:29 +0300 | [diff] [blame] | 2658 | pipe_config->limited_color_range = true; |
| 2659 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2660 | pipe_config->lane_count = |
| 2661 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; |
| 2662 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2663 | intel_dp_get_m_n(crtc, pipe_config); |
| 2664 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2665 | if (port == PORT_A) { |
Ville Syrjälä | b377e0d | 2015-10-29 21:25:59 +0200 | [diff] [blame] | 2666 | 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] | 2667 | pipe_config->port_clock = 162000; |
| 2668 | else |
| 2669 | pipe_config->port_clock = 270000; |
| 2670 | } |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2671 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 2672 | pipe_config->base.adjusted_mode.crtc_clock = |
| 2673 | intel_dotclock_calculate(pipe_config->port_clock, |
| 2674 | &pipe_config->dp_m_n); |
Daniel Vetter | 7f16e5c | 2013-11-04 16:28:47 +0100 | [diff] [blame] | 2675 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2676 | if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2677 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2678 | /* |
| 2679 | * This is a big fat ugly hack. |
| 2680 | * |
| 2681 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2682 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2683 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2684 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2685 | * max, not what it tells us to use. |
| 2686 | * |
| 2687 | * Note: This will still be broken if the eDP panel is not lit |
| 2688 | * up by the BIOS, and thus we can't get the mode at module |
| 2689 | * load. |
| 2690 | */ |
| 2691 | 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] | 2692 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2693 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2694 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2697 | static void intel_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2698 | const struct intel_crtc_state *old_crtc_state, |
| 2699 | const struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2700 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2701 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2702 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2703 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 8ec47de | 2017-10-30 20:46:53 +0200 | [diff] [blame] | 2704 | intel_audio_codec_disable(encoder, |
| 2705 | old_crtc_state, old_conn_state); |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2706 | |
| 2707 | /* Make sure the panel is off before trying to change the mode. But also |
| 2708 | * ensure that we have vdd while we switch off the panel. */ |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2709 | intel_edp_panel_vdd_on(intel_dp); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2710 | intel_edp_backlight_off(old_conn_state); |
Jani Nikula | fdbc3b1 | 2013-11-12 17:10:13 +0200 | [diff] [blame] | 2711 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2712 | intel_edp_panel_off(intel_dp); |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | static void g4x_disable_dp(struct intel_encoder *encoder, |
| 2716 | const struct intel_crtc_state *old_crtc_state, |
| 2717 | const struct drm_connector_state *old_conn_state) |
| 2718 | { |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2719 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2720 | |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2721 | /* disable the port before the pipe on g4x */ |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2722 | intel_dp_link_down(encoder, old_crtc_state); |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | static void ilk_disable_dp(struct intel_encoder *encoder, |
| 2726 | const struct intel_crtc_state *old_crtc_state, |
| 2727 | const struct drm_connector_state *old_conn_state) |
| 2728 | { |
| 2729 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
| 2730 | } |
| 2731 | |
| 2732 | static void vlv_disable_dp(struct intel_encoder *encoder, |
| 2733 | const struct intel_crtc_state *old_crtc_state, |
| 2734 | const struct drm_connector_state *old_conn_state) |
| 2735 | { |
| 2736 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2737 | |
| 2738 | intel_psr_disable(intel_dp, old_crtc_state); |
| 2739 | |
| 2740 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2743 | static void ilk_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2744 | const struct intel_crtc_state *old_crtc_state, |
| 2745 | const struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2746 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2747 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2748 | enum port port = encoder->port; |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2749 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2750 | intel_dp_link_down(encoder, old_crtc_state); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2751 | |
| 2752 | /* Only ilk+ has port A */ |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2753 | if (port == PORT_A) |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2754 | ironlake_edp_pll_off(intel_dp, old_crtc_state); |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2755 | } |
| 2756 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2757 | static void vlv_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2758 | const struct intel_crtc_state *old_crtc_state, |
| 2759 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2760 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2761 | intel_dp_link_down(encoder, old_crtc_state); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2762 | } |
| 2763 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2764 | static void chv_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2765 | const struct intel_crtc_state *old_crtc_state, |
| 2766 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2767 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2768 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2769 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2770 | intel_dp_link_down(encoder, old_crtc_state); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2771 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2772 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2773 | |
Ville Syrjälä | a8f327f | 2015-07-09 20:14:11 +0300 | [diff] [blame] | 2774 | /* Assert data lane reset */ |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 2775 | chv_data_lane_soft_reset(encoder, old_crtc_state, true); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2776 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2777 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2778 | } |
| 2779 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2780 | static void |
| 2781 | _intel_dp_set_link_train(struct intel_dp *intel_dp, |
| 2782 | uint32_t *DP, |
| 2783 | uint8_t dp_train_pat) |
| 2784 | { |
| 2785 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2786 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2787 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2788 | enum port port = intel_dig_port->base.port; |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2789 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2790 | if (dp_train_pat & DP_TRAINING_PATTERN_MASK) |
| 2791 | DRM_DEBUG_KMS("Using DP training pattern TPS%d\n", |
| 2792 | dp_train_pat & DP_TRAINING_PATTERN_MASK); |
| 2793 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 2794 | if (HAS_DDI(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2795 | uint32_t temp = I915_READ(DP_TP_CTL(port)); |
| 2796 | |
| 2797 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) |
| 2798 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2799 | else |
| 2800 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2801 | |
| 2802 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 2803 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2804 | case DP_TRAINING_PATTERN_DISABLE: |
| 2805 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; |
| 2806 | |
| 2807 | break; |
| 2808 | case DP_TRAINING_PATTERN_1: |
| 2809 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2810 | break; |
| 2811 | case DP_TRAINING_PATTERN_2: |
| 2812 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; |
| 2813 | break; |
| 2814 | case DP_TRAINING_PATTERN_3: |
| 2815 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; |
| 2816 | break; |
| 2817 | } |
| 2818 | I915_WRITE(DP_TP_CTL(port), temp); |
| 2819 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2820 | } else if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2821 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2822 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 2823 | |
| 2824 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2825 | case DP_TRAINING_PATTERN_DISABLE: |
| 2826 | *DP |= DP_LINK_TRAIN_OFF_CPT; |
| 2827 | break; |
| 2828 | case DP_TRAINING_PATTERN_1: |
| 2829 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; |
| 2830 | break; |
| 2831 | case DP_TRAINING_PATTERN_2: |
| 2832 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2833 | break; |
| 2834 | case DP_TRAINING_PATTERN_3: |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2835 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2836 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2837 | break; |
| 2838 | } |
| 2839 | |
| 2840 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2841 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2842 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 2843 | else |
| 2844 | *DP &= ~DP_LINK_TRAIN_MASK; |
| 2845 | |
| 2846 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2847 | case DP_TRAINING_PATTERN_DISABLE: |
| 2848 | *DP |= DP_LINK_TRAIN_OFF; |
| 2849 | break; |
| 2850 | case DP_TRAINING_PATTERN_1: |
| 2851 | *DP |= DP_LINK_TRAIN_PAT_1; |
| 2852 | break; |
| 2853 | case DP_TRAINING_PATTERN_2: |
| 2854 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2855 | break; |
| 2856 | case DP_TRAINING_PATTERN_3: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2857 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2858 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; |
| 2859 | } else { |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2860 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2861 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2862 | } |
| 2863 | break; |
| 2864 | } |
| 2865 | } |
| 2866 | } |
| 2867 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2868 | static void intel_dp_enable_port(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2869 | const struct intel_crtc_state *old_crtc_state) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2870 | { |
| 2871 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2872 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2873 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2874 | /* enable with pattern 1 (as per spec) */ |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2875 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2876 | 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] | 2877 | |
| 2878 | /* |
| 2879 | * Magic for VLV/CHV. We _must_ first set up the register |
| 2880 | * without actually enabling the port, and then do another |
| 2881 | * write to enable the port. Otherwise link training will |
| 2882 | * fail when the power sequencer is freshly used for this port. |
| 2883 | */ |
| 2884 | intel_dp->DP |= DP_PORT_EN; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2885 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2886 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2887 | |
| 2888 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 2889 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2890 | } |
| 2891 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2892 | static void intel_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2893 | const struct intel_crtc_state *pipe_config, |
| 2894 | const struct drm_connector_state *conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2895 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2896 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2897 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2898 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2899 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2900 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2901 | enum pipe pipe = crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2902 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 2903 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
| 2904 | return; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2905 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2906 | pps_lock(intel_dp); |
| 2907 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2908 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 2909 | vlv_init_panel_power_sequencer(encoder, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2910 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2911 | intel_dp_enable_port(intel_dp, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2912 | |
| 2913 | edp_panel_vdd_on(intel_dp); |
| 2914 | edp_panel_on(intel_dp); |
| 2915 | edp_panel_vdd_off(intel_dp, true); |
| 2916 | |
| 2917 | pps_unlock(intel_dp); |
| 2918 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2919 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2920 | unsigned int lane_mask = 0x0; |
| 2921 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2922 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2923 | lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2924 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 2925 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
| 2926 | lane_mask); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2927 | } |
Ville Syrjälä | 61234fa | 2014-10-16 21:27:34 +0300 | [diff] [blame] | 2928 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2929 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 2930 | intel_dp_start_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2931 | intel_dp_stop_link_train(intel_dp); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2932 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2933 | if (pipe_config->has_audio) { |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2934 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2935 | pipe_name(pipe)); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2936 | intel_audio_codec_enable(encoder, pipe_config, conn_state); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2937 | } |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2938 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2939 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2940 | static void g4x_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2941 | const struct intel_crtc_state *pipe_config, |
| 2942 | const struct drm_connector_state *conn_state) |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 2943 | { |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2944 | intel_enable_dp(encoder, pipe_config, conn_state); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2945 | intel_edp_backlight_on(pipe_config, conn_state); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2946 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2947 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2948 | static void vlv_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2949 | const struct intel_crtc_state *pipe_config, |
| 2950 | const struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2951 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2952 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2953 | |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2954 | intel_edp_backlight_on(pipe_config, conn_state); |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 2955 | intel_psr_enable(intel_dp, pipe_config); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2956 | } |
| 2957 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2958 | static void g4x_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2959 | const struct intel_crtc_state *pipe_config, |
| 2960 | const struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2961 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2962 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 2963 | enum port port = encoder->port; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2964 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2965 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 2966 | |
Daniel Vetter | d41f1ef | 2014-04-24 23:54:53 +0200 | [diff] [blame] | 2967 | /* Only ilk+ has port A */ |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2968 | if (port == PORT_A) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2969 | ironlake_edp_pll_on(intel_dp, pipe_config); |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2970 | } |
| 2971 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2972 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
| 2973 | { |
| 2974 | 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] | 2975 | 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] | 2976 | enum pipe pipe = intel_dp->pps_pipe; |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 2977 | i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2978 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2979 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 2980 | |
Ville Syrjälä | d158694 | 2017-02-08 19:52:54 +0200 | [diff] [blame] | 2981 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 2982 | return; |
| 2983 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2984 | edp_panel_vdd_off_sync(intel_dp); |
| 2985 | |
| 2986 | /* |
| 2987 | * VLV seems to get confused when multiple power seqeuencers |
| 2988 | * have the same port selected (even if only one has power/vdd |
| 2989 | * enabled). The failure manifests as vlv_wait_port_ready() failing |
| 2990 | * CHV on the other hand doesn't seem to mind having the same port |
| 2991 | * selected in multiple power seqeuencers, but let's clear the |
| 2992 | * port select always when logically disconnecting a power sequencer |
| 2993 | * from a port. |
| 2994 | */ |
| 2995 | 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] | 2996 | pipe_name(pipe), port_name(intel_dig_port->base.port)); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2997 | I915_WRITE(pp_on_reg, 0); |
| 2998 | POSTING_READ(pp_on_reg); |
| 2999 | |
| 3000 | intel_dp->pps_pipe = INVALID_PIPE; |
| 3001 | } |
| 3002 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 3003 | 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] | 3004 | enum pipe pipe) |
| 3005 | { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3006 | struct intel_encoder *encoder; |
| 3007 | |
| 3008 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 3009 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 3010 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3011 | struct intel_dp *intel_dp; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 3012 | enum port port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3013 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3014 | if (encoder->type != INTEL_OUTPUT_DP && |
| 3015 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3016 | continue; |
| 3017 | |
| 3018 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3019 | port = dp_to_dig_port(intel_dp)->base.port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3020 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3021 | WARN(intel_dp->active_pipe == pipe, |
| 3022 | "stealing pipe %c power sequencer from active (e)DP port %c\n", |
| 3023 | pipe_name(pipe), port_name(port)); |
| 3024 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3025 | if (intel_dp->pps_pipe != pipe) |
| 3026 | continue; |
| 3027 | |
| 3028 | 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] | 3029 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3030 | |
| 3031 | /* make sure vdd is off before we steal it */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3032 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3033 | } |
| 3034 | } |
| 3035 | |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3036 | static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder, |
| 3037 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3038 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 3039 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3040 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3041 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3042 | |
| 3043 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 3044 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3045 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 3046 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3047 | if (intel_dp->pps_pipe != INVALID_PIPE && |
| 3048 | intel_dp->pps_pipe != crtc->pipe) { |
| 3049 | /* |
| 3050 | * If another power sequencer was being used on this |
| 3051 | * port previously make sure to turn off vdd there while |
| 3052 | * we still have control of it. |
| 3053 | */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3054 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3055 | } |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3056 | |
| 3057 | /* |
| 3058 | * We may be stealing the power |
| 3059 | * sequencer from another port. |
| 3060 | */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 3061 | vlv_steal_power_sequencer(dev_priv, crtc->pipe); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3062 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3063 | intel_dp->active_pipe = crtc->pipe; |
| 3064 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3065 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3066 | return; |
| 3067 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3068 | /* now it's all ours */ |
| 3069 | intel_dp->pps_pipe = crtc->pipe; |
| 3070 | |
| 3071 | 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] | 3072 | pipe_name(intel_dp->pps_pipe), port_name(encoder->port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3073 | |
| 3074 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 3075 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 3076 | intel_dp_init_panel_power_sequencer_registers(intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3077 | } |
| 3078 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3079 | static void vlv_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3080 | const struct intel_crtc_state *pipe_config, |
| 3081 | const struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3082 | { |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3083 | vlv_phy_pre_encoder_enable(encoder, pipe_config); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3084 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3085 | intel_enable_dp(encoder, pipe_config, conn_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3088 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3089 | const struct intel_crtc_state *pipe_config, |
| 3090 | const struct drm_connector_state *conn_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3091 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3092 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 3093 | |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3094 | vlv_phy_pre_pll_enable(encoder, pipe_config); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3097 | static void chv_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3098 | const struct intel_crtc_state *pipe_config, |
| 3099 | const struct drm_connector_state *conn_state) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3100 | { |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3101 | chv_phy_pre_encoder_enable(encoder, pipe_config); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3102 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3103 | intel_enable_dp(encoder, pipe_config, conn_state); |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 3104 | |
| 3105 | /* Second common lane will stay alive on its own now */ |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3106 | chv_phy_release_cl2_override(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3107 | } |
| 3108 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3109 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3110 | const struct intel_crtc_state *pipe_config, |
| 3111 | const struct drm_connector_state *conn_state) |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3112 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3113 | intel_dp_prepare(encoder, pipe_config); |
Ville Syrjälä | 625695f | 2014-06-28 02:04:02 +0300 | [diff] [blame] | 3114 | |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3115 | chv_phy_pre_pll_enable(encoder, pipe_config); |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3116 | } |
| 3117 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3118 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder, |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3119 | const struct intel_crtc_state *old_crtc_state, |
| 3120 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3121 | { |
Ville Syrjälä | 2e1029c | 2017-10-31 22:51:18 +0200 | [diff] [blame] | 3122 | chv_phy_post_pll_disable(encoder, old_crtc_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3123 | } |
| 3124 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3125 | /* |
| 3126 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 3127 | * link status information |
| 3128 | */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3129 | bool |
Keith Packard | 93f62da | 2011-11-01 19:45:03 -0700 | [diff] [blame] | 3130 | 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] | 3131 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3132 | return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status, |
| 3133 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3134 | } |
| 3135 | |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3136 | static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp) |
| 3137 | { |
| 3138 | uint8_t psr_caps = 0; |
| 3139 | |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3140 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1) |
| 3141 | return false; |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3142 | return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED; |
| 3143 | } |
| 3144 | |
| 3145 | static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) |
| 3146 | { |
| 3147 | uint8_t dprx = 0; |
| 3148 | |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3149 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST, |
| 3150 | &dprx) != 1) |
| 3151 | return false; |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3152 | return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED; |
| 3153 | } |
| 3154 | |
Chris Wilson | a76f73d | 2017-01-14 10:51:13 +0000 | [diff] [blame] | 3155 | static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp) |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3156 | { |
| 3157 | uint8_t alpm_caps = 0; |
| 3158 | |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3159 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, |
| 3160 | &alpm_caps) != 1) |
| 3161 | return false; |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3162 | return alpm_caps & DP_ALPM_CAP; |
| 3163 | } |
| 3164 | |
Paulo Zanoni | 1100244 | 2014-06-13 18:45:41 -0300 | [diff] [blame] | 3165 | /* These are source-specific values. */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3166 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3167 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3168 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3169 | 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] | 3170 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3171 | |
Ville Syrjälä | 7d4f37b | 2017-10-16 17:57:00 +0300 | [diff] [blame] | 3172 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | ffe5111 | 2017-02-23 19:49:01 +0200 | [diff] [blame] | 3173 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3174 | return intel_ddi_dp_voltage_max(encoder); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3175 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3176 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3177 | else if (IS_GEN7(dev_priv) && port == PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3178 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3179 | else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3180 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3181 | else |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3182 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3183 | } |
| 3184 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3185 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3186 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
| 3187 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3188 | 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] | 3189 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3190 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3191 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3192 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 3193 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3194 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3195 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3196 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3197 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3198 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3199 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
| 3200 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3201 | default: |
| 3202 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
| 3203 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3204 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3205 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3206 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3207 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3208 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3209 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3210 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3211 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3212 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3213 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3214 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3215 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3216 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3217 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3218 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3219 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3220 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3221 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3222 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3223 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3224 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3225 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3226 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3227 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3228 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3229 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3230 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3231 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3232 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3233 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3234 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3235 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3236 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3237 | } |
| 3238 | } else { |
| 3239 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3240 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3241 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3242 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3243 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3244 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3245 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3246 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3247 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3248 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3249 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3250 | } |
| 3251 | } |
| 3252 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3253 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3254 | { |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3255 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3256 | unsigned long demph_reg_value, preemph_reg_value, |
| 3257 | uniqtranscale_reg_value; |
| 3258 | uint8_t train_set = intel_dp->train_set[0]; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3259 | |
| 3260 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3261 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3262 | preemph_reg_value = 0x0004000; |
| 3263 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3264 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3265 | demph_reg_value = 0x2B405555; |
| 3266 | uniqtranscale_reg_value = 0x552AB83A; |
| 3267 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3268 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3269 | demph_reg_value = 0x2B404040; |
| 3270 | uniqtranscale_reg_value = 0x5548B83A; |
| 3271 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3272 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3273 | demph_reg_value = 0x2B245555; |
| 3274 | uniqtranscale_reg_value = 0x5560B83A; |
| 3275 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3276 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3277 | demph_reg_value = 0x2B405555; |
| 3278 | uniqtranscale_reg_value = 0x5598DA3A; |
| 3279 | break; |
| 3280 | default: |
| 3281 | return 0; |
| 3282 | } |
| 3283 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3284 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3285 | preemph_reg_value = 0x0002000; |
| 3286 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3287 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3288 | demph_reg_value = 0x2B404040; |
| 3289 | uniqtranscale_reg_value = 0x5552B83A; |
| 3290 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3291 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3292 | demph_reg_value = 0x2B404848; |
| 3293 | uniqtranscale_reg_value = 0x5580B83A; |
| 3294 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3295 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3296 | demph_reg_value = 0x2B404040; |
| 3297 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3298 | break; |
| 3299 | default: |
| 3300 | return 0; |
| 3301 | } |
| 3302 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3303 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3304 | preemph_reg_value = 0x0000000; |
| 3305 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3306 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3307 | demph_reg_value = 0x2B305555; |
| 3308 | uniqtranscale_reg_value = 0x5570B83A; |
| 3309 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3310 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3311 | demph_reg_value = 0x2B2B4040; |
| 3312 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3313 | break; |
| 3314 | default: |
| 3315 | return 0; |
| 3316 | } |
| 3317 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3318 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3319 | preemph_reg_value = 0x0006000; |
| 3320 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3321 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3322 | demph_reg_value = 0x1B405555; |
| 3323 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3324 | break; |
| 3325 | default: |
| 3326 | return 0; |
| 3327 | } |
| 3328 | break; |
| 3329 | default: |
| 3330 | return 0; |
| 3331 | } |
| 3332 | |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3333 | vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value, |
| 3334 | uniqtranscale_reg_value, 0); |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3335 | |
| 3336 | return 0; |
| 3337 | } |
| 3338 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3339 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3340 | { |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3341 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3342 | u32 deemph_reg_value, margin_reg_value; |
| 3343 | bool uniq_trans_scale = false; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3344 | uint8_t train_set = intel_dp->train_set[0]; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3345 | |
| 3346 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3347 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3348 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3349 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3350 | deemph_reg_value = 128; |
| 3351 | margin_reg_value = 52; |
| 3352 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3353 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3354 | deemph_reg_value = 128; |
| 3355 | margin_reg_value = 77; |
| 3356 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3357 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3358 | deemph_reg_value = 128; |
| 3359 | margin_reg_value = 102; |
| 3360 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3361 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3362 | deemph_reg_value = 128; |
| 3363 | margin_reg_value = 154; |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3364 | uniq_trans_scale = true; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3365 | break; |
| 3366 | default: |
| 3367 | return 0; |
| 3368 | } |
| 3369 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3370 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3371 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3372 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3373 | deemph_reg_value = 85; |
| 3374 | margin_reg_value = 78; |
| 3375 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3376 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3377 | deemph_reg_value = 85; |
| 3378 | margin_reg_value = 116; |
| 3379 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3380 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3381 | deemph_reg_value = 85; |
| 3382 | margin_reg_value = 154; |
| 3383 | break; |
| 3384 | default: |
| 3385 | return 0; |
| 3386 | } |
| 3387 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3388 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3389 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3390 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3391 | deemph_reg_value = 64; |
| 3392 | margin_reg_value = 104; |
| 3393 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3394 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3395 | deemph_reg_value = 64; |
| 3396 | margin_reg_value = 154; |
| 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_3: |
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 = 43; |
| 3406 | margin_reg_value = 154; |
| 3407 | break; |
| 3408 | default: |
| 3409 | return 0; |
| 3410 | } |
| 3411 | break; |
| 3412 | default: |
| 3413 | return 0; |
| 3414 | } |
| 3415 | |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3416 | chv_set_phy_signal_level(encoder, deemph_reg_value, |
| 3417 | margin_reg_value, uniq_trans_scale); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3418 | |
| 3419 | return 0; |
| 3420 | } |
| 3421 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3422 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3423 | gen4_signal_levels(uint8_t train_set) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3424 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3425 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3426 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3427 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3428 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3429 | default: |
| 3430 | signal_levels |= DP_VOLTAGE_0_4; |
| 3431 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3432 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3433 | signal_levels |= DP_VOLTAGE_0_6; |
| 3434 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3435 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3436 | signal_levels |= DP_VOLTAGE_0_8; |
| 3437 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3438 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3439 | signal_levels |= DP_VOLTAGE_1_2; |
| 3440 | break; |
| 3441 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3442 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3443 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3444 | default: |
| 3445 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 3446 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3447 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3448 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 3449 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3450 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3451 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 3452 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3453 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3454 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 3455 | break; |
| 3456 | } |
| 3457 | return signal_levels; |
| 3458 | } |
| 3459 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3460 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 3461 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3462 | gen6_edp_signal_levels(uint8_t train_set) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3463 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3464 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3465 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3466 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3467 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3468 | 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] | 3469 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3470 | 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] | 3471 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3472 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 3473 | 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] | 3474 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3475 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 3476 | 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] | 3477 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3478 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3479 | 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] | 3480 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3481 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3482 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3483 | "0x%x\n", signal_levels); |
| 3484 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3488 | /* Gen7's DP voltage swing and pre-emphasis control */ |
| 3489 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3490 | gen7_edp_signal_levels(uint8_t train_set) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3491 | { |
| 3492 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3493 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3494 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3495 | 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] | 3496 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3497 | 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] | 3498 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
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_2: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3500 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
| 3501 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3502 | 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] | 3503 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3504 | 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] | 3505 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
| 3506 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3507 | 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] | 3508 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3509 | 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] | 3510 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
| 3511 | |
| 3512 | default: |
| 3513 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3514 | "0x%x\n", signal_levels); |
| 3515 | return EDP_LINK_TRAIN_500MV_0DB_IVB; |
| 3516 | } |
| 3517 | } |
| 3518 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3519 | void |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3520 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3521 | { |
| 3522 | 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] | 3523 | enum port port = intel_dig_port->base.port; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3524 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3525 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3526 | uint32_t signal_levels, mask = 0; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3527 | uint8_t train_set = intel_dp->train_set[0]; |
| 3528 | |
Rodrigo Vivi | d509af6 | 2017-08-29 16:22:24 -0700 | [diff] [blame] | 3529 | if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
| 3530 | signal_levels = bxt_signal_levels(intel_dp); |
| 3531 | } else if (HAS_DDI(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3532 | signal_levels = ddi_signal_levels(intel_dp); |
Rodrigo Vivi | d509af6 | 2017-08-29 16:22:24 -0700 | [diff] [blame] | 3533 | mask = DDI_BUF_EMP_MASK; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3534 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3535 | signal_levels = chv_signal_levels(intel_dp); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 3536 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3537 | signal_levels = vlv_signal_levels(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3538 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3539 | signal_levels = gen7_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3540 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3541 | } else if (IS_GEN6(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3542 | signal_levels = gen6_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3543 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
| 3544 | } else { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3545 | signal_levels = gen4_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3546 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
| 3547 | } |
| 3548 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 3549 | if (mask) |
| 3550 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); |
| 3551 | |
| 3552 | DRM_DEBUG_KMS("Using vswing level %d\n", |
| 3553 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); |
| 3554 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", |
| 3555 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> |
| 3556 | DP_TRAIN_PRE_EMPHASIS_SHIFT); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3557 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3558 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3559 | |
| 3560 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 3561 | POSTING_READ(intel_dp->output_reg); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3562 | } |
| 3563 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3564 | void |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3565 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
| 3566 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3567 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 3568 | 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] | 3569 | struct drm_i915_private *dev_priv = |
| 3570 | to_i915(intel_dig_port->base.base.dev); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3571 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3572 | _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] | 3573 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3574 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3575 | POSTING_READ(intel_dp->output_reg); |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3576 | } |
| 3577 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3578 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3579 | { |
| 3580 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3581 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3582 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 3583 | enum port port = intel_dig_port->base.port; |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3584 | uint32_t val; |
| 3585 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3586 | if (!HAS_DDI(dev_priv)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3587 | return; |
| 3588 | |
| 3589 | val = I915_READ(DP_TP_CTL(port)); |
| 3590 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 3591 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; |
| 3592 | I915_WRITE(DP_TP_CTL(port), val); |
| 3593 | |
| 3594 | /* |
| 3595 | * On PORT_A we can have only eDP in SST mode. There the only reason |
| 3596 | * we need to set idle transmission mode is to work around a HW issue |
| 3597 | * where we enable the pipe while not in idle link-training mode. |
| 3598 | * In this case there is requirement to wait for a minimum number of |
| 3599 | * idle patterns to be sent. |
| 3600 | */ |
| 3601 | if (port == PORT_A) |
| 3602 | return; |
| 3603 | |
Chris Wilson | a767017 | 2016-06-30 15:33:10 +0100 | [diff] [blame] | 3604 | if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port), |
| 3605 | DP_TP_STATUS_IDLE_DONE, |
| 3606 | DP_TP_STATUS_IDLE_DONE, |
| 3607 | 1)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3608 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); |
| 3609 | } |
| 3610 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3611 | static void |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3612 | intel_dp_link_down(struct intel_encoder *encoder, |
| 3613 | const struct intel_crtc_state *old_crtc_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3614 | { |
Ville Syrjälä | adc1030 | 2017-10-31 22:51:14 +0200 | [diff] [blame] | 3615 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 3616 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 3617 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 3618 | enum port port = encoder->port; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3619 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3620 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3621 | if (WARN_ON(HAS_DDI(dev_priv))) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 3622 | return; |
| 3623 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 3624 | 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] | 3625 | return; |
| 3626 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3627 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3628 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3629 | if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3630 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3631 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3632 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3633 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3634 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | aad3d14 | 2014-06-28 02:04:25 +0300 | [diff] [blame] | 3635 | DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 3636 | else |
| 3637 | DP &= ~DP_LINK_TRAIN_MASK; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3638 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3639 | } |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3640 | I915_WRITE(intel_dp->output_reg, DP); |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 3641 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3642 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3643 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
| 3644 | I915_WRITE(intel_dp->output_reg, DP); |
| 3645 | POSTING_READ(intel_dp->output_reg); |
| 3646 | |
| 3647 | /* |
| 3648 | * HW workaround for IBX, we need to move the port |
| 3649 | * to transcoder A after disabling it to allow the |
| 3650 | * matching HDMI port to be enabled on transcoder A. |
| 3651 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3652 | 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] | 3653 | /* |
| 3654 | * We get CPU/PCH FIFO underruns on the other pipe when |
| 3655 | * doing the workaround. Sweep them under the rug. |
| 3656 | */ |
| 3657 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3658 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3659 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3660 | /* always enable with pattern 1 (as per spec) */ |
| 3661 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); |
| 3662 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; |
| 3663 | I915_WRITE(intel_dp->output_reg, DP); |
| 3664 | POSTING_READ(intel_dp->output_reg); |
| 3665 | |
| 3666 | DP &= ~DP_PORT_EN; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3667 | I915_WRITE(intel_dp->output_reg, DP); |
Daniel Vetter | 0ca0968 | 2014-11-24 16:54:11 +0100 | [diff] [blame] | 3668 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3669 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3670 | intel_wait_for_vblank_if_active(dev_priv, PIPE_A); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3671 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
| 3672 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3673 | } |
| 3674 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 3675 | msleep(intel_dp->panel_power_down_delay); |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 3676 | |
| 3677 | intel_dp->DP = DP; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3678 | |
| 3679 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 3680 | pps_lock(intel_dp); |
| 3681 | intel_dp->active_pipe = INVALID_PIPE; |
| 3682 | pps_unlock(intel_dp); |
| 3683 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
Imre Deak | 24e807e | 2016-10-24 19:33:28 +0300 | [diff] [blame] | 3686 | bool |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3687 | intel_dp_read_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3688 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3689 | if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, |
| 3690 | sizeof(intel_dp->dpcd)) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3691 | return false; /* aux transfer failed */ |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3692 | |
Andy Shevchenko | a8e9815 | 2014-09-01 14:12:01 +0300 | [diff] [blame] | 3693 | 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] | 3694 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3695 | return intel_dp->dpcd[DP_DPCD_REV] != 0; |
| 3696 | } |
| 3697 | |
| 3698 | static bool |
| 3699 | intel_edp_init_dpcd(struct intel_dp *intel_dp) |
| 3700 | { |
| 3701 | struct drm_i915_private *dev_priv = |
| 3702 | to_i915(dp_to_dig_port(intel_dp)->base.base.dev); |
| 3703 | |
| 3704 | /* this function is meant to be called only once */ |
| 3705 | WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0); |
| 3706 | |
| 3707 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3708 | return false; |
| 3709 | |
Jani Nikula | 84c3675 | 2017-05-18 14:10:23 +0300 | [diff] [blame] | 3710 | drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, |
| 3711 | drm_dp_is_branch(intel_dp->dpcd)); |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 3712 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3713 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 3714 | dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
| 3715 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 3716 | |
| 3717 | /* Check if the panel supports PSR */ |
| 3718 | drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT, |
| 3719 | intel_dp->psr_dpcd, |
| 3720 | sizeof(intel_dp->psr_dpcd)); |
| 3721 | if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) { |
| 3722 | dev_priv->psr.sink_support = true; |
| 3723 | DRM_DEBUG_KMS("Detected EDP PSR Panel.\n"); |
| 3724 | } |
| 3725 | |
| 3726 | if (INTEL_GEN(dev_priv) >= 9 && |
| 3727 | (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) { |
| 3728 | uint8_t frame_sync_cap; |
| 3729 | |
| 3730 | dev_priv->psr.sink_support = true; |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3731 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3732 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP, |
| 3733 | &frame_sync_cap) != 1) |
| 3734 | frame_sync_cap = 0; |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3735 | dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false; |
| 3736 | /* PSR2 needs frame sync as well */ |
| 3737 | dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync; |
| 3738 | DRM_DEBUG_KMS("PSR2 %s on sink", |
| 3739 | dev_priv->psr.psr2_support ? "supported" : "not supported"); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3740 | |
| 3741 | if (dev_priv->psr.psr2_support) { |
| 3742 | dev_priv->psr.y_cord_support = |
| 3743 | intel_dp_get_y_cord_status(intel_dp); |
| 3744 | dev_priv->psr.colorimetry_support = |
| 3745 | intel_dp_get_colorimetry_status(intel_dp); |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3746 | dev_priv->psr.alpm = |
| 3747 | intel_dp_get_alpm_status(intel_dp); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3748 | } |
| 3749 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3750 | } |
| 3751 | |
Jani Nikula | 0501a3b | 2017-10-26 17:29:31 +0300 | [diff] [blame] | 3752 | /* |
| 3753 | * Read the eDP display control registers. |
| 3754 | * |
| 3755 | * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in |
| 3756 | * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it |
| 3757 | * set, but require eDP 1.4+ detection (e.g. for supported link rates |
| 3758 | * method). The display control registers should read zero if they're |
| 3759 | * not supported anyway. |
| 3760 | */ |
| 3761 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, |
Dan Carpenter | f7170e2 | 2016-10-13 11:55:08 +0300 | [diff] [blame] | 3762 | intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == |
| 3763 | sizeof(intel_dp->edp_dpcd)) |
Jani Nikula | e6ed2a1 | 2017-10-26 17:29:32 +0300 | [diff] [blame] | 3764 | 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] | 3765 | intel_dp->edp_dpcd); |
| 3766 | |
Jani Nikula | e6ed2a1 | 2017-10-26 17:29:32 +0300 | [diff] [blame] | 3767 | /* Read the eDP 1.4+ supported link rates. */ |
| 3768 | if (intel_dp->edp_dpcd[0] >= DP_EDP_14) { |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3769 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
| 3770 | int i; |
| 3771 | |
| 3772 | drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES, |
| 3773 | sink_rates, sizeof(sink_rates)); |
| 3774 | |
| 3775 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
| 3776 | int val = le16_to_cpu(sink_rates[i]); |
| 3777 | |
| 3778 | if (val == 0) |
| 3779 | break; |
| 3780 | |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 3781 | /* Value read multiplied by 200kHz gives the per-lane |
| 3782 | * link rate in kHz. The source rates are, however, |
| 3783 | * stored in terms of LS_Clk kHz. The full conversion |
| 3784 | * back to symbols is |
| 3785 | * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) |
| 3786 | */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3787 | intel_dp->sink_rates[i] = (val * 200) / 10; |
| 3788 | } |
| 3789 | intel_dp->num_sink_rates = i; |
| 3790 | } |
| 3791 | |
Jani Nikula | e6ed2a1 | 2017-10-26 17:29:32 +0300 | [diff] [blame] | 3792 | /* |
| 3793 | * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available, |
| 3794 | * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise. |
| 3795 | */ |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3796 | if (intel_dp->num_sink_rates) |
| 3797 | intel_dp->use_rate_select = true; |
| 3798 | else |
| 3799 | intel_dp_set_sink_rates(intel_dp); |
| 3800 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 3801 | intel_dp_set_common_rates(intel_dp); |
| 3802 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3803 | return true; |
| 3804 | } |
| 3805 | |
| 3806 | |
| 3807 | static bool |
| 3808 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
| 3809 | { |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3810 | u8 sink_count; |
| 3811 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3812 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3813 | return false; |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3814 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3815 | /* Don't clobber cached eDP rates. */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3816 | if (!intel_dp_is_edp(intel_dp)) { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3817 | intel_dp_set_sink_rates(intel_dp); |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 3818 | intel_dp_set_common_rates(intel_dp); |
| 3819 | } |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3820 | |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3821 | 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] | 3822 | return false; |
| 3823 | |
| 3824 | /* |
| 3825 | * Sink count can change between short pulse hpd hence |
| 3826 | * a member variable in intel_dp will track any changes |
| 3827 | * between short pulse interrupts. |
| 3828 | */ |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3829 | intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count); |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3830 | |
| 3831 | /* |
| 3832 | * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that |
| 3833 | * a dongle is present but no display. Unless we require to know |
| 3834 | * if a dongle is present or not, we don't need to update |
| 3835 | * downstream port information. So, an early return here saves |
| 3836 | * time from performing other operations which are not required. |
| 3837 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3838 | if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3839 | return false; |
| 3840 | |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 3841 | if (!drm_dp_is_branch(intel_dp->dpcd)) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3842 | return true; /* native DP sink */ |
| 3843 | |
| 3844 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) |
| 3845 | return true; /* no per-port downstream info */ |
| 3846 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3847 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
| 3848 | intel_dp->downstream_ports, |
| 3849 | DP_MAX_DOWNSTREAM_PORTS) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3850 | return false; /* downstream port status fetch failed */ |
| 3851 | |
| 3852 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3855 | static bool |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3856 | intel_dp_can_mst(struct intel_dp *intel_dp) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3857 | { |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3858 | u8 mstm_cap; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3859 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3860 | if (!i915_modparams.enable_dp_mst) |
Nathan Schulte | 7cc9613 | 2016-03-15 10:14:05 -0500 | [diff] [blame] | 3861 | return false; |
| 3862 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3863 | if (!intel_dp->can_mst) |
| 3864 | return false; |
| 3865 | |
| 3866 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) |
| 3867 | return false; |
| 3868 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3869 | 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] | 3870 | return false; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3871 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3872 | return mstm_cap & DP_MST_CAP; |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | static void |
| 3876 | intel_dp_configure_mst(struct intel_dp *intel_dp) |
| 3877 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3878 | if (!i915_modparams.enable_dp_mst) |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3879 | return; |
| 3880 | |
| 3881 | if (!intel_dp->can_mst) |
| 3882 | return; |
| 3883 | |
| 3884 | intel_dp->is_mst = intel_dp_can_mst(intel_dp); |
| 3885 | |
| 3886 | if (intel_dp->is_mst) |
| 3887 | DRM_DEBUG_KMS("Sink is MST capable\n"); |
| 3888 | else |
| 3889 | DRM_DEBUG_KMS("Sink is not MST capable\n"); |
| 3890 | |
| 3891 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 3892 | intel_dp->is_mst); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3893 | } |
| 3894 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3895 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp) |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3896 | { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3897 | 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] | 3898 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3899 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3900 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3901 | int ret = 0; |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3902 | int count = 0; |
| 3903 | int attempts = 10; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3904 | |
| 3905 | 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] | 3906 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3907 | ret = -EIO; |
| 3908 | goto out; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3909 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3910 | |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3911 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3912 | buf & ~DP_TEST_SINK_START) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3913 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3914 | ret = -EIO; |
| 3915 | goto out; |
| 3916 | } |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3917 | |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3918 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3919 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3920 | |
| 3921 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3922 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3923 | ret = -EIO; |
| 3924 | goto out; |
| 3925 | } |
| 3926 | count = buf & DP_TEST_COUNT_MASK; |
| 3927 | } while (--attempts && count); |
| 3928 | |
| 3929 | if (attempts == 0) { |
Rodrigo Vivi | dc5a903 | 2016-01-29 14:44:59 -0800 | [diff] [blame] | 3930 | 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] | 3931 | ret = -ETIMEDOUT; |
| 3932 | } |
| 3933 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3934 | out: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3935 | hsw_enable_ips(intel_crtc); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3936 | return ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp) |
| 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); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3943 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 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) { |
| 3957 | ret = intel_dp_sink_crc_stop(intel_dp); |
| 3958 | if (ret) |
| 3959 | return ret; |
| 3960 | } |
| 3961 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3962 | hsw_disable_ips(intel_crtc); |
| 3963 | |
| 3964 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
| 3965 | buf | DP_TEST_SINK_START) < 0) { |
| 3966 | hsw_enable_ips(intel_crtc); |
| 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 | |
| 3974 | int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc) |
| 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); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3978 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 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 | |
| 3983 | ret = intel_dp_sink_crc_start(intel_dp); |
| 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: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 4011 | intel_dp_sink_crc_stop(intel_dp); |
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 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4278 | static void |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4279 | intel_dp_retrain_link(struct intel_dp *intel_dp) |
| 4280 | { |
| 4281 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 4282 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4283 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 4284 | |
| 4285 | /* Suppress underruns caused by re-training */ |
| 4286 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
| 4287 | if (crtc->config->has_pch_encoder) |
| 4288 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4289 | intel_crtc_pch_transcoder(crtc), false); |
| 4290 | |
| 4291 | intel_dp_start_link_train(intel_dp); |
| 4292 | intel_dp_stop_link_train(intel_dp); |
| 4293 | |
| 4294 | /* Keep underrun reporting disabled until things are stable */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4295 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4296 | |
| 4297 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 4298 | if (crtc->config->has_pch_encoder) |
| 4299 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4300 | intel_crtc_pch_transcoder(crtc), true); |
| 4301 | } |
| 4302 | |
| 4303 | static void |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4304 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
| 4305 | { |
| 4306 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
| 4307 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
| 4308 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 4309 | |
| 4310 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 4311 | |
| 4312 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
| 4313 | DRM_ERROR("Failed to get link status\n"); |
| 4314 | return; |
| 4315 | } |
| 4316 | |
| 4317 | if (!intel_encoder->base.crtc) |
| 4318 | return; |
| 4319 | |
| 4320 | if (!to_intel_crtc(intel_encoder->base.crtc)->active) |
| 4321 | return; |
| 4322 | |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 4323 | /* |
| 4324 | * Validate the cached values of intel_dp->link_rate and |
| 4325 | * intel_dp->lane_count before attempting to retrain. |
| 4326 | */ |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 4327 | if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate, |
| 4328 | intel_dp->lane_count)) |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4329 | return; |
| 4330 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4331 | /* Retrain if Channel EQ or CR not ok */ |
| 4332 | if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) { |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4333 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
| 4334 | intel_encoder->base.name); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4335 | |
| 4336 | intel_dp_retrain_link(intel_dp); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4340 | /* |
| 4341 | * According to DP spec |
| 4342 | * 5.1.2: |
| 4343 | * 1. Read DPCD |
| 4344 | * 2. Configure link according to Receiver Capabilities |
| 4345 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 4346 | * 4. Check link status on receipt of hot-plug interrupt |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4347 | * |
| 4348 | * intel_dp_short_pulse - handles short pulse interrupts |
| 4349 | * when full detection is not required. |
| 4350 | * Returns %true if short pulse is handled and full detection |
| 4351 | * is NOT required and %false otherwise. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4352 | */ |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4353 | static bool |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4354 | intel_dp_short_pulse(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4355 | { |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4356 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4357 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4358 | u8 sink_irq_vector = 0; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4359 | u8 old_sink_count = intel_dp->sink_count; |
| 4360 | bool ret; |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4361 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4362 | /* |
| 4363 | * Clearing compliance test variables to allow capturing |
| 4364 | * of values for next automated test request. |
| 4365 | */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4366 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4367 | |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4368 | /* |
| 4369 | * Now read the DPCD to see if it's actually running |
| 4370 | * If the current value of sink count doesn't match with |
| 4371 | * the value that was stored earlier or dpcd read failed |
| 4372 | * we need to do full detection |
| 4373 | */ |
| 4374 | ret = intel_dp_get_dpcd(intel_dp); |
| 4375 | |
| 4376 | if ((old_sink_count != intel_dp->sink_count) || !ret) { |
| 4377 | /* No need to proceed if we are going to do full detect */ |
| 4378 | return false; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4381 | /* Try to read the source of the interrupt */ |
| 4382 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4383 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4384 | sink_irq_vector != 0) { |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4385 | /* Clear interrupt source */ |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4386 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4387 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4388 | sink_irq_vector); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4389 | |
| 4390 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4391 | intel_dp_handle_test_request(intel_dp); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4392 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4393 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4394 | } |
| 4395 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4396 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4397 | intel_dp_check_link_status(intel_dp); |
| 4398 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4399 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 4400 | DRM_DEBUG_KMS("Link Training Compliance Test requested\n"); |
| 4401 | /* Send a Hotplug Uevent to userspace to start modeset */ |
| 4402 | drm_kms_helper_hotplug_event(intel_encoder->base.dev); |
| 4403 | } |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4404 | |
| 4405 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4406 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4407 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4408 | /* XXX this is probably wrong for multiple downstream ports */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4409 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4410 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4411 | { |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4412 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4413 | uint8_t *dpcd = intel_dp->dpcd; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4414 | uint8_t type; |
| 4415 | |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4416 | if (lspcon->active) |
| 4417 | lspcon_resume(lspcon); |
| 4418 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4419 | if (!intel_dp_get_dpcd(intel_dp)) |
| 4420 | return connector_status_disconnected; |
| 4421 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4422 | if (intel_dp_is_edp(intel_dp)) |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 4423 | return connector_status_connected; |
| 4424 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4425 | /* if there's no downstream port, we're done */ |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 4426 | if (!drm_dp_is_branch(dpcd)) |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4427 | return connector_status_connected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4428 | |
| 4429 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4430 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 4431 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4432 | |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 4433 | return intel_dp->sink_count ? |
| 4434 | connector_status_connected : connector_status_disconnected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4435 | } |
| 4436 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4437 | if (intel_dp_can_mst(intel_dp)) |
| 4438 | return connector_status_connected; |
| 4439 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4440 | /* If no HPD, poke DDC gently */ |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 4441 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4442 | return connector_status_connected; |
| 4443 | |
| 4444 | /* Well we tried, say unknown for unreliable port types */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4445 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 4446 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 4447 | if (type == DP_DS_PORT_TYPE_VGA || |
| 4448 | type == DP_DS_PORT_TYPE_NON_EDID) |
| 4449 | return connector_status_unknown; |
| 4450 | } else { |
| 4451 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
| 4452 | DP_DWN_STRM_PORT_TYPE_MASK; |
| 4453 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || |
| 4454 | type == DP_DWN_STRM_PORT_TYPE_OTHER) |
| 4455 | return connector_status_unknown; |
| 4456 | } |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4457 | |
| 4458 | /* Anything else is out of spec, warn and ignore */ |
| 4459 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4460 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | static enum drm_connector_status |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4464 | edp_detect(struct intel_dp *intel_dp) |
| 4465 | { |
| 4466 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4467 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4468 | enum drm_connector_status status; |
| 4469 | |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4470 | status = intel_panel_detect(dev_priv); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4471 | if (status == connector_status_unknown) |
| 4472 | status = connector_status_connected; |
| 4473 | |
| 4474 | return status; |
| 4475 | } |
| 4476 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4477 | static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4478 | struct intel_digital_port *port) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4479 | { |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4480 | u32 bit; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 4481 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4482 | switch (port->base.port) { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4483 | case PORT_B: |
| 4484 | bit = SDE_PORTB_HOTPLUG; |
| 4485 | break; |
| 4486 | case PORT_C: |
| 4487 | bit = SDE_PORTC_HOTPLUG; |
| 4488 | break; |
| 4489 | case PORT_D: |
| 4490 | bit = SDE_PORTD_HOTPLUG; |
| 4491 | break; |
| 4492 | default: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4493 | MISSING_CASE(port->base.port); |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4494 | return false; |
| 4495 | } |
| 4496 | |
| 4497 | return I915_READ(SDEISR) & bit; |
| 4498 | } |
| 4499 | |
| 4500 | static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4501 | struct intel_digital_port *port) |
| 4502 | { |
| 4503 | u32 bit; |
| 4504 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4505 | switch (port->base.port) { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4506 | case PORT_B: |
| 4507 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 4508 | break; |
| 4509 | case PORT_C: |
| 4510 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 4511 | break; |
| 4512 | case PORT_D: |
| 4513 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 4514 | break; |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4515 | default: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4516 | MISSING_CASE(port->base.port); |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4517 | return false; |
| 4518 | } |
| 4519 | |
| 4520 | return I915_READ(SDEISR) & bit; |
| 4521 | } |
| 4522 | |
| 4523 | static bool spt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4524 | struct intel_digital_port *port) |
| 4525 | { |
| 4526 | u32 bit; |
| 4527 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4528 | switch (port->base.port) { |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4529 | case PORT_A: |
| 4530 | bit = SDE_PORTA_HOTPLUG_SPT; |
| 4531 | break; |
Jani Nikula | a78695d | 2015-09-18 15:54:50 +0300 | [diff] [blame] | 4532 | case PORT_E: |
| 4533 | bit = SDE_PORTE_HOTPLUG_SPT; |
| 4534 | break; |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4535 | default: |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4536 | return cpt_digital_port_connected(dev_priv, port); |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4537 | } |
Damien Lespiau | 1b46963 | 2012-12-13 16:09:01 +0000 | [diff] [blame] | 4538 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4539 | return I915_READ(SDEISR) & bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4540 | } |
| 4541 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4542 | static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv, |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4543 | struct intel_digital_port *port) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4544 | { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4545 | u32 bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4546 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4547 | switch (port->base.port) { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4548 | case PORT_B: |
| 4549 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; |
| 4550 | break; |
| 4551 | case PORT_C: |
| 4552 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; |
| 4553 | break; |
| 4554 | case PORT_D: |
| 4555 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; |
| 4556 | break; |
| 4557 | default: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4558 | MISSING_CASE(port->base.port); |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4559 | return false; |
| 4560 | } |
| 4561 | |
| 4562 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 4563 | } |
| 4564 | |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4565 | static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4566 | struct intel_digital_port *port) |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4567 | { |
| 4568 | u32 bit; |
| 4569 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4570 | switch (port->base.port) { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4571 | case PORT_B: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4572 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4573 | break; |
| 4574 | case PORT_C: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4575 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4576 | break; |
| 4577 | case PORT_D: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4578 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4579 | break; |
| 4580 | default: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4581 | MISSING_CASE(port->base.port); |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4582 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4585 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
Dave Airlie | 2a592be | 2014-09-01 16:58:12 +1000 | [diff] [blame] | 4586 | } |
| 4587 | |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4588 | static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4589 | struct intel_digital_port *port) |
| 4590 | { |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4591 | if (port->base.port == PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4592 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG; |
| 4593 | else |
| 4594 | return ibx_digital_port_connected(dev_priv, port); |
| 4595 | } |
| 4596 | |
| 4597 | static bool snb_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4598 | struct intel_digital_port *port) |
| 4599 | { |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4600 | if (port->base.port == PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4601 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG; |
| 4602 | else |
| 4603 | return cpt_digital_port_connected(dev_priv, port); |
| 4604 | } |
| 4605 | |
| 4606 | static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4607 | struct intel_digital_port *port) |
| 4608 | { |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4609 | if (port->base.port == PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4610 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB; |
| 4611 | else |
| 4612 | return cpt_digital_port_connected(dev_priv, port); |
| 4613 | } |
| 4614 | |
| 4615 | static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4616 | struct intel_digital_port *port) |
| 4617 | { |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4618 | if (port->base.port == PORT_A) |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4619 | return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG; |
| 4620 | else |
| 4621 | return cpt_digital_port_connected(dev_priv, port); |
| 4622 | } |
| 4623 | |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4624 | static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv, |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4625 | struct intel_digital_port *intel_dig_port) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4626 | { |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4627 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 4628 | enum port port; |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4629 | u32 bit; |
| 4630 | |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 4631 | port = intel_hpd_pin_to_port(intel_encoder->hpd_pin); |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4632 | switch (port) { |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4633 | case PORT_A: |
| 4634 | bit = BXT_DE_PORT_HP_DDIA; |
| 4635 | break; |
| 4636 | case PORT_B: |
| 4637 | bit = BXT_DE_PORT_HP_DDIB; |
| 4638 | break; |
| 4639 | case PORT_C: |
| 4640 | bit = BXT_DE_PORT_HP_DDIC; |
| 4641 | break; |
| 4642 | default: |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4643 | MISSING_CASE(port); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4644 | return false; |
| 4645 | } |
| 4646 | |
| 4647 | return I915_READ(GEN8_DE_PORT_ISR) & bit; |
| 4648 | } |
| 4649 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4650 | /* |
| 4651 | * intel_digital_port_connected - is the specified port connected? |
| 4652 | * @dev_priv: i915 private structure |
| 4653 | * @port: the port to test |
| 4654 | * |
| 4655 | * Return %true if @port is connected, %false otherwise. |
| 4656 | */ |
Imre Deak | 390b4e0 | 2017-01-27 11:39:19 +0200 | [diff] [blame] | 4657 | bool intel_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4658 | struct intel_digital_port *port) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4659 | { |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4660 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 4661 | if (IS_GM45(dev_priv)) |
| 4662 | return gm45_digital_port_connected(dev_priv, port); |
| 4663 | else |
| 4664 | return g4x_digital_port_connected(dev_priv, port); |
| 4665 | } |
| 4666 | |
| 4667 | if (IS_GEN5(dev_priv)) |
| 4668 | return ilk_digital_port_connected(dev_priv, port); |
| 4669 | else if (IS_GEN6(dev_priv)) |
| 4670 | return snb_digital_port_connected(dev_priv, port); |
| 4671 | else if (IS_GEN7(dev_priv)) |
| 4672 | return ivb_digital_port_connected(dev_priv, port); |
| 4673 | else if (IS_GEN8(dev_priv)) |
| 4674 | return bdw_digital_port_connected(dev_priv, port); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4675 | else if (IS_GEN9_LP(dev_priv)) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4676 | return bxt_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4677 | else |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4678 | return spt_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4679 | } |
| 4680 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4681 | static struct edid * |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4682 | intel_dp_get_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4683 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4684 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4685 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4686 | /* use cached edid if we have one */ |
| 4687 | if (intel_connector->edid) { |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4688 | /* invalid edid */ |
| 4689 | if (IS_ERR(intel_connector->edid)) |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4690 | return NULL; |
| 4691 | |
Jani Nikula | 55e9ede | 2013-10-01 10:38:54 +0300 | [diff] [blame] | 4692 | return drm_edid_duplicate(intel_connector->edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4693 | } else |
| 4694 | return drm_get_edid(&intel_connector->base, |
| 4695 | &intel_dp->aux.ddc); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4698 | static void |
| 4699 | intel_dp_set_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4700 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4701 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4702 | struct edid *edid; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4703 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4704 | intel_dp_unset_edid(intel_dp); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4705 | edid = intel_dp_get_edid(intel_dp); |
| 4706 | intel_connector->detect_edid = edid; |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4707 | |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 4708 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4709 | } |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4710 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4711 | static void |
| 4712 | intel_dp_unset_edid(struct intel_dp *intel_dp) |
| 4713 | { |
| 4714 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4715 | |
| 4716 | kfree(intel_connector->detect_edid); |
| 4717 | intel_connector->detect_edid = NULL; |
| 4718 | |
| 4719 | intel_dp->has_audio = false; |
| 4720 | } |
| 4721 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4722 | static int |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4723 | intel_dp_long_pulse(struct intel_connector *intel_connector) |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4724 | { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4725 | struct drm_connector *connector = &intel_connector->base; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4726 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 4727 | struct drm_device *dev = connector->dev; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4728 | enum drm_connector_status status; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4729 | u8 sink_irq_vector = 0; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4730 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4731 | WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex)); |
| 4732 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4733 | intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4734 | |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4735 | /* Can't disconnect eDP, but you can close the lid... */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4736 | if (intel_dp_is_edp(intel_dp)) |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4737 | status = edp_detect(intel_dp); |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4738 | else if (intel_digital_port_connected(to_i915(dev), |
| 4739 | dp_to_dig_port(intel_dp))) |
| 4740 | status = intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4741 | else |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4742 | status = connector_status_disconnected; |
| 4743 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4744 | if (status == connector_status_disconnected) { |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4745 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4746 | |
jim.bride@linux.intel.com | 0e505a0 | 2016-04-11 10:11:24 -0700 | [diff] [blame] | 4747 | if (intel_dp->is_mst) { |
| 4748 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4749 | intel_dp->is_mst, |
| 4750 | intel_dp->mst_mgr.mst_state); |
| 4751 | intel_dp->is_mst = false; |
| 4752 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4753 | intel_dp->is_mst); |
| 4754 | } |
| 4755 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4756 | goto out; |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4757 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4758 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4759 | if (intel_dp->reset_link_params) { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 4760 | /* Initial max link lane count */ |
| 4761 | 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] | 4762 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 4763 | /* Initial max link rate */ |
| 4764 | intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp); |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4765 | |
| 4766 | intel_dp->reset_link_params = false; |
| 4767 | } |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4768 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4769 | intel_dp_print_rates(intel_dp); |
| 4770 | |
Jani Nikula | 84c3675 | 2017-05-18 14:10:23 +0300 | [diff] [blame] | 4771 | drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, |
| 4772 | drm_dp_is_branch(intel_dp->dpcd)); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 4773 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4774 | intel_dp_configure_mst(intel_dp); |
| 4775 | |
| 4776 | if (intel_dp->is_mst) { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4777 | /* |
| 4778 | * If we are in MST mode then this connector |
| 4779 | * won't appear connected or have anything |
| 4780 | * with EDID on it |
| 4781 | */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4782 | status = connector_status_disconnected; |
| 4783 | goto out; |
Ville Syrjälä | 1a36147 | 2017-04-12 22:30:17 +0300 | [diff] [blame] | 4784 | } else { |
| 4785 | /* |
| 4786 | * If display is now connected check links status, |
| 4787 | * there has been known issues of link loss triggerring |
| 4788 | * long pulse. |
| 4789 | * |
| 4790 | * Some sinks (eg. ASUS PB287Q) seem to perform some |
| 4791 | * weird HPD ping pong during modesets. So we can apparently |
| 4792 | * end up with HPD going low during a modeset, and then |
| 4793 | * going back up soon after. And once that happens we must |
| 4794 | * retrain the link to get a picture. That's in case no |
| 4795 | * userspace component reacted to intermittent HPD dip. |
| 4796 | */ |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4797 | intel_dp_check_link_status(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4798 | } |
| 4799 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4800 | /* |
| 4801 | * Clearing NACK and defer counts to get their exact values |
| 4802 | * while reading EDID which are required by Compliance tests |
| 4803 | * 4.2.2.4 and 4.2.2.5 |
| 4804 | */ |
| 4805 | intel_dp->aux.i2c_nack_count = 0; |
| 4806 | intel_dp->aux.i2c_defer_count = 0; |
| 4807 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4808 | intel_dp_set_edid(intel_dp); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4809 | if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4810 | status = connector_status_connected; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4811 | intel_dp->detect_done = true; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4812 | |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4813 | /* Try to read the source of the interrupt */ |
| 4814 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4815 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4816 | sink_irq_vector != 0) { |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4817 | /* Clear interrupt source */ |
| 4818 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4819 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4820 | sink_irq_vector); |
| 4821 | |
| 4822 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
| 4823 | intel_dp_handle_test_request(intel_dp); |
| 4824 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4825 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4826 | } |
| 4827 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4828 | out: |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4829 | if (status != connector_status_connected && !intel_dp->is_mst) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4830 | intel_dp_unset_edid(intel_dp); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4831 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4832 | intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain); |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4833 | return status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4834 | } |
| 4835 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4836 | static int |
| 4837 | intel_dp_detect(struct drm_connector *connector, |
| 4838 | struct drm_modeset_acquire_ctx *ctx, |
| 4839 | bool force) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4840 | { |
| 4841 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4842 | int status = connector->status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4843 | |
| 4844 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4845 | connector->base.id, connector->name); |
| 4846 | |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4847 | /* If full detect is not performed yet, do a full detect */ |
| 4848 | if (!intel_dp->detect_done) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4849 | status = intel_dp_long_pulse(intel_dp->attached_connector); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4850 | |
| 4851 | intel_dp->detect_done = false; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4852 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4853 | return status; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4856 | static void |
| 4857 | intel_dp_force(struct drm_connector *connector) |
| 4858 | { |
| 4859 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 4860 | 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] | 4861 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4862 | |
| 4863 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4864 | connector->base.id, connector->name); |
| 4865 | intel_dp_unset_edid(intel_dp); |
| 4866 | |
| 4867 | if (connector->status != connector_status_connected) |
| 4868 | return; |
| 4869 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4870 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4871 | |
| 4872 | intel_dp_set_edid(intel_dp); |
| 4873 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4874 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4875 | } |
| 4876 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4877 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 4878 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4879 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4880 | struct edid *edid; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4881 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4882 | edid = intel_connector->detect_edid; |
| 4883 | if (edid) { |
| 4884 | int ret = intel_connector_update_modes(connector, edid); |
| 4885 | if (ret) |
| 4886 | return ret; |
| 4887 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4888 | |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4889 | /* if eDP has no EDID, fall back to fixed mode */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4890 | if (intel_dp_is_edp(intel_attached_dp(connector)) && |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4891 | intel_connector->panel.fixed_mode) { |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4892 | struct drm_display_mode *mode; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4893 | |
| 4894 | mode = drm_mode_duplicate(connector->dev, |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4895 | intel_connector->panel.fixed_mode); |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4896 | if (mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4897 | drm_mode_probed_add(connector, mode); |
| 4898 | return 1; |
| 4899 | } |
| 4900 | } |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4901 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4902 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4905 | static int |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4906 | intel_dp_connector_register(struct drm_connector *connector) |
| 4907 | { |
| 4908 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 4909 | int ret; |
| 4910 | |
| 4911 | ret = intel_connector_register(connector); |
| 4912 | if (ret) |
| 4913 | return ret; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4914 | |
| 4915 | i915_debugfs_connector_add(connector); |
| 4916 | |
| 4917 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
| 4918 | intel_dp->aux.name, connector->kdev->kobj.name); |
| 4919 | |
| 4920 | intel_dp->aux.dev = connector->kdev; |
| 4921 | return drm_dp_aux_register(&intel_dp->aux); |
| 4922 | } |
| 4923 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4924 | static void |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4925 | intel_dp_connector_unregister(struct drm_connector *connector) |
| 4926 | { |
| 4927 | drm_dp_aux_unregister(&intel_attached_dp(connector)->aux); |
| 4928 | intel_connector_unregister(connector); |
| 4929 | } |
| 4930 | |
| 4931 | static void |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 4932 | intel_dp_connector_destroy(struct drm_connector *connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4933 | { |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4934 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4935 | |
Chris Wilson | 10e972d | 2014-09-04 21:43:45 +0100 | [diff] [blame] | 4936 | kfree(intel_connector->detect_edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4937 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4938 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 4939 | kfree(intel_connector->edid); |
| 4940 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4941 | /* |
| 4942 | * Can't call intel_dp_is_edp() since the encoder may have been |
| 4943 | * destroyed already. |
| 4944 | */ |
Paulo Zanoni | acd8db10 | 2013-06-12 17:27:23 -0300 | [diff] [blame] | 4945 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4946 | intel_panel_fini(&intel_connector->panel); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4947 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4948 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 4949 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4950 | } |
| 4951 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 4952 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4953 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4954 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 4955 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4956 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4957 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4958 | if (intel_dp_is_edp(intel_dp)) { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4959 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4960 | /* |
| 4961 | * vdd might still be enabled do to the delayed vdd off. |
| 4962 | * Make sure vdd is actually turned off here. |
| 4963 | */ |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4964 | pps_lock(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 4965 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4966 | pps_unlock(intel_dp); |
| 4967 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 4968 | if (intel_dp->edp_notifier.notifier_call) { |
| 4969 | unregister_reboot_notifier(&intel_dp->edp_notifier); |
| 4970 | intel_dp->edp_notifier.notifier_call = NULL; |
| 4971 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4972 | } |
Chris Wilson | 9968188 | 2016-06-20 09:29:17 +0100 | [diff] [blame] | 4973 | |
| 4974 | intel_dp_aux_fini(intel_dp); |
| 4975 | |
Imre Deak | c8bd0e4 | 2014-12-12 17:57:38 +0200 | [diff] [blame] | 4976 | drm_encoder_cleanup(encoder); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4977 | kfree(intel_dig_port); |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4978 | } |
| 4979 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 4980 | void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4981 | { |
| 4982 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 4983 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4984 | if (!intel_dp_is_edp(intel_dp)) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4985 | return; |
| 4986 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4987 | /* |
| 4988 | * vdd might still be enabled do to the delayed vdd off. |
| 4989 | * Make sure vdd is actually turned off here. |
| 4990 | */ |
Ville Syrjälä | afa4e53 | 2014-11-25 15:43:48 +0200 | [diff] [blame] | 4991 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4992 | pps_lock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4993 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4994 | pps_unlock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4995 | } |
| 4996 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4997 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
| 4998 | { |
| 4999 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 5000 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5001 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5002 | |
| 5003 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5004 | |
| 5005 | if (!edp_have_panel_vdd(intel_dp)) |
| 5006 | return; |
| 5007 | |
| 5008 | /* |
| 5009 | * The VDD bit needs a power domain reference, so if the bit is |
| 5010 | * already enabled when we boot or resume, grab this reference and |
| 5011 | * schedule a vdd off, so we don't hold on to the reference |
| 5012 | * indefinitely. |
| 5013 | */ |
| 5014 | 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] | 5015 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5016 | |
| 5017 | edp_panel_vdd_schedule_off(intel_dp); |
| 5018 | } |
| 5019 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5020 | static enum pipe vlv_active_pipe(struct intel_dp *intel_dp) |
| 5021 | { |
| 5022 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 5023 | |
| 5024 | if ((intel_dp->DP & DP_PORT_EN) == 0) |
| 5025 | return INVALID_PIPE; |
| 5026 | |
| 5027 | if (IS_CHERRYVIEW(dev_priv)) |
| 5028 | return DP_PORT_TO_PIPE_CHV(intel_dp->DP); |
| 5029 | else |
| 5030 | return PORT_TO_PIPE(intel_dp->DP); |
| 5031 | } |
| 5032 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 5033 | void intel_dp_encoder_reset(struct drm_encoder *encoder) |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5034 | { |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5035 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5036 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 5037 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5038 | |
| 5039 | if (!HAS_DDI(dev_priv)) |
| 5040 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5041 | |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5042 | if (lspcon->active) |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 5043 | lspcon_resume(lspcon); |
| 5044 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5045 | intel_dp->reset_link_params = true; |
| 5046 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5047 | pps_lock(intel_dp); |
| 5048 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5049 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5050 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 5051 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5052 | if (intel_dp_is_edp(intel_dp)) { |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5053 | /* Reinit the power sequencer, in case BIOS did something with it. */ |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5054 | intel_dp_pps_init(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5055 | intel_edp_panel_vdd_sanitize(intel_dp); |
| 5056 | } |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5057 | |
| 5058 | pps_unlock(intel_dp); |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5059 | } |
| 5060 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5061 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 5062 | .force = intel_dp_force, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5063 | .fill_modes = drm_helper_probe_single_connector_modes, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5064 | .atomic_get_property = intel_digital_connector_atomic_get_property, |
| 5065 | .atomic_set_property = intel_digital_connector_atomic_set_property, |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5066 | .late_register = intel_dp_connector_register, |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 5067 | .early_unregister = intel_dp_connector_unregister, |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 5068 | .destroy = intel_dp_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 5069 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5070 | .atomic_duplicate_state = intel_digital_connector_duplicate_state, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5071 | }; |
| 5072 | |
| 5073 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 5074 | .detect_ctx = intel_dp_detect, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5075 | .get_modes = intel_dp_get_modes, |
| 5076 | .mode_valid = intel_dp_mode_valid, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5077 | .atomic_check = intel_digital_connector_atomic_check, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5078 | }; |
| 5079 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5080 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5081 | .reset = intel_dp_encoder_reset, |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5082 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5083 | }; |
| 5084 | |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5085 | enum irqreturn |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5086 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
| 5087 | { |
| 5088 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5089 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5090 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5091 | enum irqreturn ret = IRQ_NONE; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5092 | |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5093 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
| 5094 | /* |
| 5095 | * vdd off can generate a long pulse on eDP which |
| 5096 | * would require vdd on to handle it, and thus we |
| 5097 | * would end up in an endless cycle of |
| 5098 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." |
| 5099 | */ |
| 5100 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5101 | port_name(intel_dig_port->base.port)); |
Ville Syrjälä | a8b3d52f8 | 2015-02-10 14:11:46 +0200 | [diff] [blame] | 5102 | return IRQ_HANDLED; |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5103 | } |
| 5104 | |
Ville Syrjälä | 26fbb77 | 2014-08-11 18:37:37 +0300 | [diff] [blame] | 5105 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5106 | port_name(intel_dig_port->base.port), |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5107 | long_hpd ? "long" : "short"); |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5108 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5109 | if (long_hpd) { |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5110 | intel_dp->reset_link_params = true; |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5111 | intel_dp->detect_done = false; |
| 5112 | return IRQ_NONE; |
| 5113 | } |
| 5114 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5115 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5116 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5117 | if (intel_dp->is_mst) { |
| 5118 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) { |
| 5119 | /* |
| 5120 | * If we were in MST mode, and device is not |
| 5121 | * there, get out of MST mode |
| 5122 | */ |
| 5123 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 5124 | intel_dp->is_mst, intel_dp->mst_mgr.mst_state); |
| 5125 | intel_dp->is_mst = false; |
| 5126 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 5127 | intel_dp->is_mst); |
| 5128 | intel_dp->detect_done = false; |
| 5129 | goto put_power; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5130 | } |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5131 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5132 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5133 | if (!intel_dp->is_mst) { |
| 5134 | if (!intel_dp_short_pulse(intel_dp)) { |
| 5135 | intel_dp->detect_done = false; |
| 5136 | goto put_power; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 5137 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5138 | } |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5139 | |
| 5140 | ret = IRQ_HANDLED; |
| 5141 | |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5142 | put_power: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5143 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5144 | |
| 5145 | return ret; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5146 | } |
| 5147 | |
Rodrigo Vivi | 477ec32 | 2015-08-06 15:51:39 +0800 | [diff] [blame] | 5148 | /* check the VBT to see whether the eDP is on another port */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 5149 | 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] | 5150 | { |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5151 | /* |
| 5152 | * eDP not supported on g4x. so bail out early just |
| 5153 | * for a bit extra safety in case the VBT is bonkers. |
| 5154 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5155 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5156 | return false; |
| 5157 | |
Imre Deak | a98d9c1 | 2016-12-21 12:17:24 +0200 | [diff] [blame] | 5158 | if (INTEL_GEN(dev_priv) < 9 && port == PORT_A) |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5159 | return true; |
| 5160 | |
Jani Nikula | 951d9ef | 2016-03-16 12:43:31 +0200 | [diff] [blame] | 5161 | return intel_bios_is_port_edp(dev_priv, port); |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 5162 | } |
| 5163 | |
Maarten Lankhorst | 200819a | 2017-04-10 12:51:10 +0200 | [diff] [blame] | 5164 | static void |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5165 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 5166 | { |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5167 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
| 5168 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 5169 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 5170 | intel_attach_broadcast_rgb_property(connector); |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5171 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5172 | if (intel_dp_is_edp(intel_dp)) { |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5173 | u32 allowed_scalers; |
| 5174 | |
| 5175 | allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN); |
| 5176 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 5177 | allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER); |
| 5178 | |
| 5179 | drm_connector_attach_scaling_mode_property(connector, allowed_scalers); |
| 5180 | |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 5181 | connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT; |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5182 | |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5183 | } |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5184 | } |
| 5185 | |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5186 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
| 5187 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 5188 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5189 | intel_dp->last_power_on = jiffies; |
| 5190 | intel_dp->last_backlight_off = jiffies; |
| 5191 | } |
| 5192 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5193 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5194 | 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] | 5195 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5196 | 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] | 5197 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5198 | struct pps_registers regs; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5199 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5200 | intel_pps_get_registers(intel_dp, ®s); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5201 | |
| 5202 | /* Workaround: Need to write PP_CONTROL with the unlock key as |
| 5203 | * the very first thing. */ |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5204 | pp_ctl = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5205 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5206 | pp_on = I915_READ(regs.pp_on); |
| 5207 | pp_off = I915_READ(regs.pp_off); |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5208 | if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5209 | I915_WRITE(regs.pp_ctrl, pp_ctl); |
| 5210 | pp_div = I915_READ(regs.pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5211 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5212 | |
| 5213 | /* Pull timing values out of registers */ |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5214 | seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 5215 | PANEL_POWER_UP_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5216 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5217 | seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 5218 | PANEL_LIGHT_ON_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5219 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5220 | seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 5221 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5222 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5223 | seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 5224 | PANEL_POWER_DOWN_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5225 | |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5226 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) { |
Manasi Navare | 12c8ca9 | 2017-06-26 12:21:45 -0700 | [diff] [blame] | 5227 | seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> |
| 5228 | BXT_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5229 | } else { |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5230 | seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5231 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5232 | } |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | static void |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5236 | intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq) |
| 5237 | { |
| 5238 | DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 5239 | state_name, |
| 5240 | seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12); |
| 5241 | } |
| 5242 | |
| 5243 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5244 | intel_pps_verify_state(struct intel_dp *intel_dp) |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5245 | { |
| 5246 | struct edp_power_seq hw; |
| 5247 | struct edp_power_seq *sw = &intel_dp->pps_delays; |
| 5248 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5249 | intel_pps_readout_hw_state(intel_dp, &hw); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5250 | |
| 5251 | if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 || |
| 5252 | hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) { |
| 5253 | DRM_ERROR("PPS state mismatch\n"); |
| 5254 | intel_pps_dump_state("sw", sw); |
| 5255 | intel_pps_dump_state("hw", &hw); |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5260 | intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp) |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5261 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5262 | 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] | 5263 | struct edp_power_seq cur, vbt, spec, |
| 5264 | *final = &intel_dp->pps_delays; |
| 5265 | |
| 5266 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5267 | |
| 5268 | /* already initialized? */ |
| 5269 | if (final->t11_t12 != 0) |
| 5270 | return; |
| 5271 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5272 | intel_pps_readout_hw_state(intel_dp, &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5273 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5274 | intel_pps_dump_state("cur", &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5275 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 5276 | vbt = dev_priv->vbt.edp.pps; |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 5277 | /* On Toshiba Satellite P50-C-18C system the VBT T12 delay |
| 5278 | * of 500ms appears to be too short. Ocassionally the panel |
| 5279 | * just fails to power back on. Increasing the delay to 800ms |
| 5280 | * seems sufficient to avoid this problem. |
| 5281 | */ |
| 5282 | if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) { |
Manasi Navare | c02b8fb | 2017-10-03 16:37:25 -0700 | [diff] [blame] | 5283 | vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10); |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 5284 | DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n", |
| 5285 | vbt.t11_t12); |
| 5286 | } |
Manasi Navare | 770a17a | 2017-06-26 12:21:44 -0700 | [diff] [blame] | 5287 | /* T11_T12 delay is special and actually in units of 100ms, but zero |
| 5288 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5289 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5290 | * too. */ |
| 5291 | vbt.t11_t12 += 100 * 10; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5292 | |
| 5293 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of |
| 5294 | * our hw here, which are all in 100usec. */ |
| 5295 | spec.t1_t3 = 210 * 10; |
| 5296 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ |
| 5297 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ |
| 5298 | spec.t10 = 500 * 10; |
| 5299 | /* This one is special and actually in units of 100ms, but zero |
| 5300 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5301 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5302 | * too. */ |
| 5303 | spec.t11_t12 = (510 + 100) * 10; |
| 5304 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5305 | intel_pps_dump_state("vbt", &vbt); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5306 | |
| 5307 | /* Use the max of the register settings and vbt. If both are |
| 5308 | * unset, fall back to the spec limits. */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5309 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5310 | spec.field : \ |
| 5311 | max(cur.field, vbt.field)) |
| 5312 | assign_final(t1_t3); |
| 5313 | assign_final(t8); |
| 5314 | assign_final(t9); |
| 5315 | assign_final(t10); |
| 5316 | assign_final(t11_t12); |
| 5317 | #undef assign_final |
| 5318 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5319 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5320 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 5321 | intel_dp->backlight_on_delay = get_delay(t8); |
| 5322 | intel_dp->backlight_off_delay = get_delay(t9); |
| 5323 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 5324 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 5325 | #undef get_delay |
| 5326 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5327 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 5328 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 5329 | intel_dp->panel_power_cycle_delay); |
| 5330 | |
| 5331 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 5332 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5333 | |
| 5334 | /* |
| 5335 | * We override the HW backlight delays to 1 because we do manual waits |
| 5336 | * on them. For T8, even BSpec recommends doing it. For T9, if we |
| 5337 | * don't do this, we'll end up waiting for the backlight off delay |
| 5338 | * twice: once when we do the manual sleep, and once when we disable |
| 5339 | * the panel and wait for the PP_STATUS bit to become zero. |
| 5340 | */ |
| 5341 | final->t8 = 1; |
| 5342 | final->t9 = 1; |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5343 | } |
| 5344 | |
| 5345 | static void |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5346 | 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] | 5347 | bool force_disable_vdd) |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5348 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5349 | 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] | 5350 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 5351 | int div = dev_priv->rawclk_freq / 1000; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5352 | struct pps_registers regs; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5353 | enum port port = dp_to_dig_port(intel_dp)->base.port; |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5354 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5355 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 5356 | lockdep_assert_held(&dev_priv->pps_mutex); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5357 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5358 | intel_pps_get_registers(intel_dp, ®s); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5359 | |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5360 | /* |
| 5361 | * On some VLV machines the BIOS can leave the VDD |
| 5362 | * enabled even on power seqeuencers which aren't |
| 5363 | * hooked up to any port. This would mess up the |
| 5364 | * power domain tracking the first time we pick |
| 5365 | * one of these power sequencers for use since |
| 5366 | * edp_panel_vdd_on() would notice that the VDD was |
| 5367 | * already on and therefore wouldn't grab the power |
| 5368 | * domain reference. Disable VDD first to avoid this. |
| 5369 | * This also avoids spuriously turning the VDD on as |
| 5370 | * soon as the new power seqeuencer gets initialized. |
| 5371 | */ |
| 5372 | if (force_disable_vdd) { |
| 5373 | u32 pp = ironlake_get_pp_control(intel_dp); |
| 5374 | |
| 5375 | WARN(pp & PANEL_POWER_ON, "Panel power already on\n"); |
| 5376 | |
| 5377 | if (pp & EDP_FORCE_VDD) |
| 5378 | DRM_DEBUG_KMS("VDD already on, disabling first\n"); |
| 5379 | |
| 5380 | pp &= ~EDP_FORCE_VDD; |
| 5381 | |
| 5382 | I915_WRITE(regs.pp_ctrl, pp); |
| 5383 | } |
| 5384 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5385 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5386 | (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT); |
| 5387 | pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5388 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5389 | /* Compute the divisor for the pp clock, simply match the Bspec |
| 5390 | * formula. */ |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5391 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5392 | pp_div = I915_READ(regs.pp_ctrl); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5393 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; |
Manasi Navare | 12c8ca9 | 2017-06-26 12:21:45 -0700 | [diff] [blame] | 5394 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5395 | << BXT_POWER_CYCLE_DELAY_SHIFT); |
| 5396 | } else { |
| 5397 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 5398 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
| 5399 | << PANEL_POWER_CYCLE_DELAY_SHIFT); |
| 5400 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5401 | |
| 5402 | /* Haswell doesn't have any port selection bits for the panel |
| 5403 | * power sequencer any more. */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5404 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5405 | port_sel = PANEL_PORT_SELECT_VLV(port); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5406 | } 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] | 5407 | if (port == PORT_A) |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5408 | port_sel = PANEL_PORT_SELECT_DPA; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5409 | else |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5410 | port_sel = PANEL_PORT_SELECT_DPD; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5411 | } |
| 5412 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5413 | pp_on |= port_sel; |
| 5414 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5415 | I915_WRITE(regs.pp_on, pp_on); |
| 5416 | I915_WRITE(regs.pp_off, pp_off); |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5417 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5418 | I915_WRITE(regs.pp_ctrl, pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5419 | else |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5420 | I915_WRITE(regs.pp_div, pp_div); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5421 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5422 | 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] | 5423 | I915_READ(regs.pp_on), |
| 5424 | I915_READ(regs.pp_off), |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5425 | (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ? |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5426 | (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) : |
| 5427 | I915_READ(regs.pp_div)); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 5428 | } |
| 5429 | |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5430 | static void intel_dp_pps_init(struct intel_dp *intel_dp) |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5431 | { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5432 | 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] | 5433 | |
| 5434 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5435 | vlv_initial_power_sequencer_setup(intel_dp); |
| 5436 | } else { |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5437 | intel_dp_init_panel_power_sequencer(intel_dp); |
| 5438 | intel_dp_init_panel_power_sequencer_registers(intel_dp, false); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5439 | } |
| 5440 | } |
| 5441 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5442 | /** |
| 5443 | * 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] | 5444 | * @dev_priv: i915 device |
Maarten Lankhorst | e896402 | 2016-08-25 11:07:02 +0200 | [diff] [blame] | 5445 | * @crtc_state: a pointer to the active intel_crtc_state |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5446 | * @refresh_rate: RR to be programmed |
| 5447 | * |
| 5448 | * This function gets called when refresh rate (RR) has to be changed from |
| 5449 | * one frequency to another. Switches can be between high and low RR |
| 5450 | * supported by the panel or to any other RR based on media playback (in |
| 5451 | * this case, RR value needs to be passed from user space). |
| 5452 | * |
| 5453 | * The caller of this function needs to take a lock on dev_priv->drrs. |
| 5454 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5455 | 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] | 5456 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5457 | int refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5458 | { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5459 | struct intel_encoder *encoder; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5460 | struct intel_digital_port *dig_port = NULL; |
| 5461 | struct intel_dp *intel_dp = dev_priv->drrs.dp; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5462 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5463 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5464 | |
| 5465 | if (refresh_rate <= 0) { |
| 5466 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); |
| 5467 | return; |
| 5468 | } |
| 5469 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5470 | if (intel_dp == NULL) { |
| 5471 | DRM_DEBUG_KMS("DRRS not supported.\n"); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5472 | return; |
| 5473 | } |
| 5474 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5475 | dig_port = dp_to_dig_port(intel_dp); |
| 5476 | encoder = &dig_port->base; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5477 | |
| 5478 | if (!intel_crtc) { |
| 5479 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); |
| 5480 | return; |
| 5481 | } |
| 5482 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5483 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5484 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
| 5485 | return; |
| 5486 | } |
| 5487 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5488 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
| 5489 | refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5490 | index = DRRS_LOW_RR; |
| 5491 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5492 | if (index == dev_priv->drrs.refresh_rate_type) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5493 | DRM_DEBUG_KMS( |
| 5494 | "DRRS requested for previously set RR...ignoring\n"); |
| 5495 | return; |
| 5496 | } |
| 5497 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5498 | if (!crtc_state->base.active) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5499 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); |
| 5500 | return; |
| 5501 | } |
| 5502 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5503 | if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) { |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5504 | switch (index) { |
| 5505 | case DRRS_HIGH_RR: |
| 5506 | intel_dp_set_m_n(intel_crtc, M1_N1); |
| 5507 | break; |
| 5508 | case DRRS_LOW_RR: |
| 5509 | intel_dp_set_m_n(intel_crtc, M2_N2); |
| 5510 | break; |
| 5511 | case DRRS_MAX_RR: |
| 5512 | default: |
| 5513 | DRM_ERROR("Unsupported refreshrate type\n"); |
| 5514 | } |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5515 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 5516 | i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5517 | u32 val; |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5518 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5519 | val = I915_READ(reg); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5520 | if (index > DRRS_HIGH_RR) { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5521 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5522 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5523 | else |
| 5524 | val |= PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5525 | } else { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5526 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5527 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5528 | else |
| 5529 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5530 | } |
| 5531 | I915_WRITE(reg, val); |
| 5532 | } |
| 5533 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5534 | dev_priv->drrs.refresh_rate_type = index; |
| 5535 | |
| 5536 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); |
| 5537 | } |
| 5538 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5539 | /** |
| 5540 | * intel_edp_drrs_enable - init drrs struct if supported |
| 5541 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5542 | * @crtc_state: A pointer to the active crtc state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5543 | * |
| 5544 | * Initializes frontbuffer_bits and drrs.dp |
| 5545 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5546 | void intel_edp_drrs_enable(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5547 | const struct intel_crtc_state *crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5548 | { |
| 5549 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5550 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5551 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5552 | if (!crtc_state->has_drrs) { |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5553 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); |
| 5554 | return; |
| 5555 | } |
| 5556 | |
Radhakrishna Sripada | da83ef8 | 2017-09-14 11:16:41 -0700 | [diff] [blame] | 5557 | if (dev_priv->psr.enabled) { |
| 5558 | DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n"); |
| 5559 | return; |
| 5560 | } |
| 5561 | |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5562 | mutex_lock(&dev_priv->drrs.mutex); |
| 5563 | if (WARN_ON(dev_priv->drrs.dp)) { |
| 5564 | DRM_ERROR("DRRS already enabled\n"); |
| 5565 | goto unlock; |
| 5566 | } |
| 5567 | |
| 5568 | dev_priv->drrs.busy_frontbuffer_bits = 0; |
| 5569 | |
| 5570 | dev_priv->drrs.dp = intel_dp; |
| 5571 | |
| 5572 | unlock: |
| 5573 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5574 | } |
| 5575 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5576 | /** |
| 5577 | * intel_edp_drrs_disable - Disable DRRS |
| 5578 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5579 | * @old_crtc_state: Pointer to old crtc_state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5580 | * |
| 5581 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5582 | void intel_edp_drrs_disable(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5583 | const struct intel_crtc_state *old_crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5584 | { |
| 5585 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5586 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5587 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5588 | if (!old_crtc_state->has_drrs) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5589 | return; |
| 5590 | |
| 5591 | mutex_lock(&dev_priv->drrs.mutex); |
| 5592 | if (!dev_priv->drrs.dp) { |
| 5593 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5594 | return; |
| 5595 | } |
| 5596 | |
| 5597 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5598 | intel_dp_set_drrs_state(dev_priv, old_crtc_state, |
| 5599 | intel_dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5600 | |
| 5601 | dev_priv->drrs.dp = NULL; |
| 5602 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5603 | |
| 5604 | cancel_delayed_work_sync(&dev_priv->drrs.work); |
| 5605 | } |
| 5606 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5607 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
| 5608 | { |
| 5609 | struct drm_i915_private *dev_priv = |
| 5610 | container_of(work, typeof(*dev_priv), drrs.work.work); |
| 5611 | struct intel_dp *intel_dp; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5612 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5613 | mutex_lock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5614 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5615 | intel_dp = dev_priv->drrs.dp; |
| 5616 | |
| 5617 | if (!intel_dp) |
| 5618 | goto unlock; |
| 5619 | |
| 5620 | /* |
| 5621 | * The delayed work can race with an invalidate hence we need to |
| 5622 | * recheck. |
| 5623 | */ |
| 5624 | |
| 5625 | if (dev_priv->drrs.busy_frontbuffer_bits) |
| 5626 | goto unlock; |
| 5627 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5628 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) { |
| 5629 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 5630 | |
| 5631 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5632 | intel_dp->attached_connector->panel.downclock_mode->vrefresh); |
| 5633 | } |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5634 | |
| 5635 | unlock: |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5636 | mutex_unlock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5637 | } |
| 5638 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5639 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5640 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5641 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5642 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5643 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5644 | * This function gets called everytime rendering on the given planes start. |
| 5645 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5646 | * |
| 5647 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5648 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5649 | void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv, |
| 5650 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5651 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5652 | struct drm_crtc *crtc; |
| 5653 | enum pipe pipe; |
| 5654 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5655 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5656 | return; |
| 5657 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5658 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5659 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5660 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5661 | if (!dev_priv->drrs.dp) { |
| 5662 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5663 | return; |
| 5664 | } |
| 5665 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5666 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5667 | pipe = to_intel_crtc(crtc)->pipe; |
| 5668 | |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5669 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 5670 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; |
| 5671 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5672 | /* invalidate means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5673 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5674 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5675 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5676 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5677 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5678 | } |
| 5679 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5680 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5681 | * intel_edp_drrs_flush - Restart Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5682 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5683 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5684 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5685 | * This function gets called every time rendering on the given planes has |
| 5686 | * completed or flip on a crtc is completed. So DRRS should be upclocked |
| 5687 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, |
| 5688 | * if no other planes are dirty. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5689 | * |
| 5690 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5691 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5692 | void intel_edp_drrs_flush(struct drm_i915_private *dev_priv, |
| 5693 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5694 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5695 | struct drm_crtc *crtc; |
| 5696 | enum pipe pipe; |
| 5697 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5698 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5699 | return; |
| 5700 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5701 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5702 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5703 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5704 | if (!dev_priv->drrs.dp) { |
| 5705 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5706 | return; |
| 5707 | } |
| 5708 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5709 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5710 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5711 | |
| 5712 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5713 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 5714 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5715 | /* flush means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5716 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5717 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5718 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5719 | |
| 5720 | /* |
| 5721 | * flush also means no more activity hence schedule downclock, if all |
| 5722 | * other fbs are quiescent too |
| 5723 | */ |
| 5724 | if (!dev_priv->drrs.busy_frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5725 | schedule_delayed_work(&dev_priv->drrs.work, |
| 5726 | msecs_to_jiffies(1000)); |
| 5727 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5728 | } |
| 5729 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5730 | /** |
| 5731 | * DOC: Display Refresh Rate Switching (DRRS) |
| 5732 | * |
| 5733 | * Display Refresh Rate Switching (DRRS) is a power conservation feature |
| 5734 | * which enables swtching between low and high refresh rates, |
| 5735 | * dynamically, based on the usage scenario. This feature is applicable |
| 5736 | * for internal panels. |
| 5737 | * |
| 5738 | * Indication that the panel supports DRRS is given by the panel EDID, which |
| 5739 | * would list multiple refresh rates for one resolution. |
| 5740 | * |
| 5741 | * DRRS is of 2 types - static and seamless. |
| 5742 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset |
| 5743 | * (may appear as a blink on screen) and is used in dock-undock scenario. |
| 5744 | * Seamless DRRS involves changing RR without any visual effect to the user |
| 5745 | * and can be used during normal system usage. This is done by programming |
| 5746 | * certain registers. |
| 5747 | * |
| 5748 | * Support for static/seamless DRRS may be indicated in the VBT based on |
| 5749 | * inputs from the panel spec. |
| 5750 | * |
| 5751 | * DRRS saves power by switching to low RR based on usage scenarios. |
| 5752 | * |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 5753 | * The implementation is based on frontbuffer tracking implementation. When |
| 5754 | * there is a disturbance on the screen triggered by user activity or a periodic |
| 5755 | * system activity, DRRS is disabled (RR is changed to high RR). When there is |
| 5756 | * no movement on screen, after a timeout of 1 second, a switch to low RR is |
| 5757 | * made. |
| 5758 | * |
| 5759 | * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate() |
| 5760 | * and intel_edp_drrs_flush() are called. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5761 | * |
| 5762 | * DRRS can be further extended to support other internal panels and also |
| 5763 | * the scenario of video playback wherein RR is set based on the rate |
| 5764 | * requested by userspace. |
| 5765 | */ |
| 5766 | |
| 5767 | /** |
| 5768 | * intel_dp_drrs_init - Init basic DRRS work and mutex. |
| 5769 | * @intel_connector: eDP connector |
| 5770 | * @fixed_mode: preferred mode of panel |
| 5771 | * |
| 5772 | * This function is called only once at driver load to initialize basic |
| 5773 | * DRRS stuff. |
| 5774 | * |
| 5775 | * Returns: |
| 5776 | * Downclock mode if panel supports it, else return NULL. |
| 5777 | * DRRS support is determined by the presence of downclock mode (apart |
| 5778 | * from VBT setting). |
| 5779 | */ |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5780 | static struct drm_display_mode * |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5781 | intel_dp_drrs_init(struct intel_connector *intel_connector, |
| 5782 | struct drm_display_mode *fixed_mode) |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5783 | { |
| 5784 | struct drm_connector *connector = &intel_connector->base; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5785 | struct drm_device *dev = connector->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5786 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5787 | struct drm_display_mode *downclock_mode = NULL; |
| 5788 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5789 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
| 5790 | mutex_init(&dev_priv->drrs.mutex); |
| 5791 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5792 | if (INTEL_GEN(dev_priv) <= 6) { |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5793 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); |
| 5794 | return NULL; |
| 5795 | } |
| 5796 | |
| 5797 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5798 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5799 | return NULL; |
| 5800 | } |
| 5801 | |
| 5802 | downclock_mode = intel_find_panel_downclock |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 5803 | (dev_priv, fixed_mode, connector); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5804 | |
| 5805 | if (!downclock_mode) { |
Ramalingam C | a1d2634 | 2015-02-23 17:38:33 +0530 | [diff] [blame] | 5806 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5807 | return NULL; |
| 5808 | } |
| 5809 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5810 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5811 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5812 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5813 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5814 | return downclock_mode; |
| 5815 | } |
| 5816 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5817 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5818 | struct intel_connector *intel_connector) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5819 | { |
| 5820 | struct drm_connector *connector = &intel_connector->base; |
| 5821 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5822 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5823 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5824 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5825 | struct drm_display_mode *fixed_mode = NULL; |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5826 | struct drm_display_mode *alt_fixed_mode = NULL; |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5827 | struct drm_display_mode *downclock_mode = NULL; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5828 | bool has_dpcd; |
| 5829 | struct drm_display_mode *scan; |
| 5830 | struct edid *edid; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5831 | enum pipe pipe = INVALID_PIPE; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5832 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5833 | if (!intel_dp_is_edp(intel_dp)) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5834 | return true; |
| 5835 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 5836 | /* |
| 5837 | * On IBX/CPT we may get here with LVDS already registered. Since the |
| 5838 | * driver uses the only internal power sequencer available for both |
| 5839 | * eDP and LVDS bail out early in this case to prevent interfering |
| 5840 | * with an already powered-on LVDS power sequencer. |
| 5841 | */ |
| 5842 | if (intel_get_lvds_encoder(dev)) { |
| 5843 | WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))); |
| 5844 | DRM_INFO("LVDS was detected, not registering eDP\n"); |
| 5845 | |
| 5846 | return false; |
| 5847 | } |
| 5848 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5849 | pps_lock(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5850 | |
| 5851 | intel_dp_init_panel_power_timestamps(intel_dp); |
Ville Syrjälä | 46bd838 | 2017-10-31 22:51:22 +0200 | [diff] [blame^] | 5852 | intel_dp_pps_init(intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5853 | intel_edp_panel_vdd_sanitize(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5854 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5855 | pps_unlock(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5856 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5857 | /* Cache DPCD and EDID for edp. */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5858 | has_dpcd = intel_edp_init_dpcd(intel_dp); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5859 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5860 | if (!has_dpcd) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5861 | /* if this fails, presume the device is a ghost */ |
| 5862 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5863 | goto out_vdd_off; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5864 | } |
| 5865 | |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5866 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 5867 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5868 | if (edid) { |
| 5869 | if (drm_add_edid_modes(connector, edid)) { |
| 5870 | drm_mode_connector_update_edid_property(connector, |
| 5871 | edid); |
| 5872 | drm_edid_to_eld(connector, edid); |
| 5873 | } else { |
| 5874 | kfree(edid); |
| 5875 | edid = ERR_PTR(-EINVAL); |
| 5876 | } |
| 5877 | } else { |
| 5878 | edid = ERR_PTR(-ENOENT); |
| 5879 | } |
| 5880 | intel_connector->edid = edid; |
| 5881 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5882 | /* prefer fixed mode from EDID if available, save an alt mode also */ |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5883 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 5884 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 5885 | fixed_mode = drm_mode_duplicate(dev, scan); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5886 | downclock_mode = intel_dp_drrs_init( |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5887 | intel_connector, fixed_mode); |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5888 | } else if (!alt_fixed_mode) { |
| 5889 | alt_fixed_mode = drm_mode_duplicate(dev, scan); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5890 | } |
| 5891 | } |
| 5892 | |
| 5893 | /* fallback to VBT if available for eDP */ |
| 5894 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { |
| 5895 | fixed_mode = drm_mode_duplicate(dev, |
| 5896 | dev_priv->vbt.lfp_lvds_vbt_mode); |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5897 | if (fixed_mode) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5898 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5899 | connector->display_info.width_mm = fixed_mode->width_mm; |
| 5900 | connector->display_info.height_mm = fixed_mode->height_mm; |
| 5901 | } |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5902 | } |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5903 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5904 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5905 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5906 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
| 5907 | register_reboot_notifier(&intel_dp->edp_notifier); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5908 | |
| 5909 | /* |
| 5910 | * Figure out the current pipe for the initial backlight setup. |
| 5911 | * If the current pipe isn't valid, try the PPS pipe, and if that |
| 5912 | * fails just assume pipe A. |
| 5913 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5914 | pipe = vlv_active_pipe(intel_dp); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5915 | |
| 5916 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5917 | pipe = intel_dp->pps_pipe; |
| 5918 | |
| 5919 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5920 | pipe = PIPE_A; |
| 5921 | |
| 5922 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", |
| 5923 | pipe_name(pipe)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5924 | } |
| 5925 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5926 | intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode, |
| 5927 | downclock_mode); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 5928 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5929 | intel_panel_setup_backlight(connector, pipe); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5930 | |
| 5931 | return true; |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5932 | |
| 5933 | out_vdd_off: |
| 5934 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 5935 | /* |
| 5936 | * vdd might still be enabled do to the delayed vdd off. |
| 5937 | * Make sure vdd is actually turned off here. |
| 5938 | */ |
| 5939 | pps_lock(intel_dp); |
| 5940 | edp_panel_vdd_off_sync(intel_dp); |
| 5941 | pps_unlock(intel_dp); |
| 5942 | |
| 5943 | return false; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5944 | } |
| 5945 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5946 | /* Set up the hotplug pin and aux power domain. */ |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5947 | static void |
| 5948 | intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port) |
| 5949 | { |
| 5950 | struct intel_encoder *encoder = &intel_dig_port->base; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5951 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5952 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5953 | encoder->hpd_pin = intel_hpd_pin(encoder->port); |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 5954 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5955 | switch (encoder->port) { |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5956 | case PORT_A: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5957 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5958 | break; |
| 5959 | case PORT_B: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5960 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5961 | break; |
| 5962 | case PORT_C: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5963 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5964 | break; |
| 5965 | case PORT_D: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5966 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5967 | break; |
| 5968 | case PORT_E: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5969 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5970 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5971 | break; |
| 5972 | default: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 5973 | MISSING_CASE(encoder->port); |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5974 | } |
| 5975 | } |
| 5976 | |
Manasi Navare | 9301397 | 2017-04-06 16:44:19 +0300 | [diff] [blame] | 5977 | static void intel_dp_modeset_retry_work_fn(struct work_struct *work) |
| 5978 | { |
| 5979 | struct intel_connector *intel_connector; |
| 5980 | struct drm_connector *connector; |
| 5981 | |
| 5982 | intel_connector = container_of(work, typeof(*intel_connector), |
| 5983 | modeset_retry_work); |
| 5984 | connector = &intel_connector->base; |
| 5985 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, |
| 5986 | connector->name); |
| 5987 | |
| 5988 | /* Grab the locks before changing connector property*/ |
| 5989 | mutex_lock(&connector->dev->mode_config.mutex); |
| 5990 | /* Set connector link status to BAD and send a Uevent to notify |
| 5991 | * userspace to do a modeset. |
| 5992 | */ |
| 5993 | drm_mode_connector_set_link_status_property(connector, |
| 5994 | DRM_MODE_LINK_STATUS_BAD); |
| 5995 | mutex_unlock(&connector->dev->mode_config.mutex); |
| 5996 | /* Send Hotplug uevent so userspace can reprobe */ |
| 5997 | drm_kms_helper_hotplug_event(connector->dev); |
| 5998 | } |
| 5999 | |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6000 | bool |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6001 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
| 6002 | struct intel_connector *intel_connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6003 | { |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6004 | struct drm_connector *connector = &intel_connector->base; |
| 6005 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 6006 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 6007 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6008 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 6009 | enum port port = intel_encoder->port; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6010 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6011 | |
Manasi Navare | 9301397 | 2017-04-06 16:44:19 +0300 | [diff] [blame] | 6012 | /* Initialize the work for modeset in case of link train failure */ |
| 6013 | INIT_WORK(&intel_connector->modeset_retry_work, |
| 6014 | intel_dp_modeset_retry_work_fn); |
| 6015 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6016 | if (WARN(intel_dig_port->max_lanes < 1, |
| 6017 | "Not enough lanes (%d) for DP on port %c\n", |
| 6018 | intel_dig_port->max_lanes, port_name(port))) |
| 6019 | return false; |
| 6020 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 6021 | intel_dp_set_source_rates(intel_dp); |
| 6022 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 6023 | intel_dp->reset_link_params = true; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 6024 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6025 | intel_dp->active_pipe = INVALID_PIPE; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 6026 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6027 | /* intel_dp vfuncs */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6028 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 6029 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6030 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6031 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 6032 | else if (HAS_PCH_SPLIT(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6033 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; |
| 6034 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 6035 | intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider; |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6036 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6037 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 6038 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; |
| 6039 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 6040 | intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl; |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 6041 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6042 | if (HAS_DDI(dev_priv)) |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 6043 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; |
| 6044 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 6045 | /* Preserve the current hw state. */ |
| 6046 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 6047 | intel_dp->attached_connector = intel_connector; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 6048 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 6049 | if (intel_dp_is_port_edp(dev_priv, port)) |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 6050 | type = DRM_MODE_CONNECTOR_eDP; |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 6051 | else |
| 6052 | type = DRM_MODE_CONNECTOR_DisplayPort; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6053 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6054 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 6055 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 6056 | |
Imre Deak | f7d2490 | 2013-05-08 13:14:05 +0300 | [diff] [blame] | 6057 | /* |
| 6058 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but |
| 6059 | * for DP the encoder type can be set by the caller to |
| 6060 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. |
| 6061 | */ |
| 6062 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 6063 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 6064 | |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6065 | /* eDP only on port B and/or C on vlv/chv */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6066 | if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6067 | intel_dp_is_edp(intel_dp) && |
| 6068 | port != PORT_B && port != PORT_C)) |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6069 | return false; |
| 6070 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 6071 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
| 6072 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", |
| 6073 | port_name(port)); |
| 6074 | |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6075 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6076 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 6077 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6078 | connector->interlace_allowed = true; |
| 6079 | connector->doublescan_allowed = 0; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 6080 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 6081 | intel_dp_init_connector_port_info(intel_dig_port); |
| 6082 | |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 6083 | intel_dp_aux_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6084 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 6085 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 6086 | edp_panel_vdd_work); |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 6087 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6088 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6089 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6090 | if (HAS_DDI(dev_priv)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 6091 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 6092 | else |
| 6093 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
| 6094 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6095 | /* init MST on ports that can support it */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6096 | if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) && |
Jani Nikula | 0c9b371 | 2015-05-18 17:10:01 +0300 | [diff] [blame] | 6097 | (port == PORT_B || port == PORT_C || port == PORT_D)) |
| 6098 | intel_dp_mst_encoder_init(intel_dig_port, |
| 6099 | intel_connector->base.base.id); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6100 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 6101 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6102 | intel_dp_aux_fini(intel_dp); |
| 6103 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
| 6104 | goto fail; |
Paulo Zanoni | b2f246a | 2013-06-12 17:27:26 -0300 | [diff] [blame] | 6105 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 6106 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 6107 | intel_dp_add_properties(intel_dp, connector); |
| 6108 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6109 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 6110 | * 0xd. Failure to do so will result in spurious interrupts being |
| 6111 | * generated on the port when a cable is not attached. |
| 6112 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6113 | if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6114 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 6115 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 6116 | } |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6117 | |
| 6118 | return true; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6119 | |
| 6120 | fail: |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6121 | drm_connector_cleanup(connector); |
| 6122 | |
| 6123 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6124 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6125 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6126 | bool intel_dp_init(struct drm_i915_private *dev_priv, |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6127 | i915_reg_t output_reg, |
| 6128 | enum port port) |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6129 | { |
| 6130 | struct intel_digital_port *intel_dig_port; |
| 6131 | struct intel_encoder *intel_encoder; |
| 6132 | struct drm_encoder *encoder; |
| 6133 | struct intel_connector *intel_connector; |
| 6134 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 6135 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6136 | if (!intel_dig_port) |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6137 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6138 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6139 | intel_connector = intel_connector_alloc(); |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6140 | if (!intel_connector) |
| 6141 | goto err_connector_alloc; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6142 | |
| 6143 | intel_encoder = &intel_dig_port->base; |
| 6144 | encoder = &intel_encoder->base; |
| 6145 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6146 | if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, |
| 6147 | &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, |
| 6148 | "DP %c", port_name(port))) |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6149 | goto err_encoder_init; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6150 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 6151 | intel_encoder->compute_config = intel_dp_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6152 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 6153 | intel_encoder->get_config = intel_dp_get_config; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 6154 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6155 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 6156 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 6157 | intel_encoder->pre_enable = chv_pre_enable_dp; |
| 6158 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6159 | intel_encoder->disable = vlv_disable_dp; |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 6160 | intel_encoder->post_disable = chv_post_disable_dp; |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6161 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6162 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6163 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6164 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
| 6165 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6166 | intel_encoder->disable = vlv_disable_dp; |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 6167 | intel_encoder->post_disable = vlv_post_disable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6168 | } else if (INTEL_GEN(dev_priv) >= 5) { |
| 6169 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6170 | intel_encoder->enable = g4x_enable_dp; |
| 6171 | intel_encoder->disable = ilk_disable_dp; |
| 6172 | intel_encoder->post_disable = ilk_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6173 | } else { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6174 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6175 | intel_encoder->enable = g4x_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6176 | intel_encoder->disable = g4x_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6177 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6178 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6179 | intel_dig_port->dp.output_reg = output_reg; |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6180 | intel_dig_port->max_lanes = 4; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6181 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 6182 | intel_encoder->type = INTEL_OUTPUT_DP; |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6183 | intel_encoder->power_domain = intel_port_to_power_domain(port); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6184 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 882ec38 | 2014-04-28 14:07:43 +0300 | [diff] [blame] | 6185 | if (port == PORT_D) |
| 6186 | intel_encoder->crtc_mask = 1 << 2; |
| 6187 | else |
| 6188 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
| 6189 | } else { |
| 6190 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 6191 | } |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 6192 | intel_encoder->cloneable = 0; |
Pandiyan, Dhinakaran | 03cdc1d | 2016-09-19 18:24:38 -0700 | [diff] [blame] | 6193 | intel_encoder->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6194 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6195 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6196 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6197 | |
Ville Syrjälä | 385e4de | 2017-08-18 16:49:55 +0300 | [diff] [blame] | 6198 | if (port != PORT_A) |
| 6199 | intel_infoframe_init(intel_dig_port); |
| 6200 | |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6201 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
| 6202 | goto err_init_connector; |
| 6203 | |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6204 | return true; |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6205 | |
| 6206 | err_init_connector: |
| 6207 | drm_encoder_cleanup(encoder); |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6208 | err_encoder_init: |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6209 | kfree(intel_connector); |
| 6210 | err_connector_alloc: |
| 6211 | kfree(intel_dig_port); |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6212 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6213 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6214 | |
| 6215 | void intel_dp_mst_suspend(struct drm_device *dev) |
| 6216 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6217 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6218 | int i; |
| 6219 | |
| 6220 | /* disable MST */ |
| 6221 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6222 | 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] | 6223 | |
| 6224 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6225 | continue; |
| 6226 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6227 | if (intel_dig_port->dp.is_mst) |
| 6228 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | void intel_dp_mst_resume(struct drm_device *dev) |
| 6233 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6234 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6235 | int i; |
| 6236 | |
| 6237 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6238 | 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] | 6239 | int ret; |
| 6240 | |
| 6241 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6242 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6243 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6244 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); |
| 6245 | if (ret) |
| 6246 | intel_dp_check_mst_status(&intel_dig_port->dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6247 | } |
| 6248 | } |