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 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 132 | static void intel_dp_link_down(struct intel_dp *intel_dp); |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 133 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 134 | static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 135 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 136 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 137 | enum pipe pipe); |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 138 | static void intel_dp_unset_edid(struct intel_dp *intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 139 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 140 | /* update sink rates from dpcd */ |
| 141 | static void intel_dp_set_sink_rates(struct intel_dp *intel_dp) |
| 142 | { |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 143 | int i, max_rate; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 144 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 145 | 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] | 146 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 147 | for (i = 0; i < ARRAY_SIZE(default_rates); i++) { |
| 148 | if (default_rates[i] > max_rate) |
| 149 | break; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 150 | intel_dp->sink_rates[i] = default_rates[i]; |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 151 | } |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 152 | |
Jani Nikula | a8a0888 | 2017-10-09 12:29:59 +0300 | [diff] [blame] | 153 | intel_dp->num_sink_rates = i; |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 154 | } |
| 155 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 156 | /* Theoretical max between source and sink */ |
| 157 | static int intel_dp_max_common_rate(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 158 | { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 159 | return intel_dp->common_rates[intel_dp->num_common_rates - 1]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 162 | /* Theoretical max between source and sink */ |
| 163 | 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] | 164 | { |
| 165 | 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] | 166 | int source_max = intel_dig_port->max_lanes; |
| 167 | int sink_max = drm_dp_max_lane_count(intel_dp->dpcd); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 168 | |
| 169 | return min(source_max, sink_max); |
| 170 | } |
| 171 | |
Jani Nikula | 3d65a73 | 2017-04-06 16:44:14 +0300 | [diff] [blame] | 172 | int intel_dp_max_lane_count(struct intel_dp *intel_dp) |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 173 | { |
| 174 | return intel_dp->max_link_lane_count; |
| 175 | } |
| 176 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 177 | int |
Keith Packard | c898261 | 2012-01-25 08:16:25 -0800 | [diff] [blame] | 178 | intel_dp_link_required(int pixel_clock, int bpp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 179 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 180 | /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */ |
| 181 | return DIV_ROUND_UP(pixel_clock * bpp, 8); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Dhinakaran Pandiyan | 22a2c8e | 2016-11-15 12:59:06 -0800 | [diff] [blame] | 184 | int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 185 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 186 | { |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 187 | /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the |
| 188 | * link rate that is generally expressed in Gbps. Since, 8 bits of data |
| 189 | * is transmitted every LS_Clk per lane, there is no need to account for |
| 190 | * the channel encoding that is done in the PHY layer here. |
| 191 | */ |
| 192 | |
| 193 | return max_link_clock * max_lanes; |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 194 | } |
| 195 | |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 196 | static int |
| 197 | intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp) |
| 198 | { |
| 199 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 200 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 201 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 202 | int max_dotclk = dev_priv->max_dotclk_freq; |
| 203 | int ds_max_dotclk; |
| 204 | |
| 205 | int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 206 | |
| 207 | if (type != DP_DS_PORT_TYPE_VGA) |
| 208 | return max_dotclk; |
| 209 | |
| 210 | ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd, |
| 211 | intel_dp->downstream_ports); |
| 212 | |
| 213 | if (ds_max_dotclk != 0) |
| 214 | max_dotclk = min(max_dotclk, ds_max_dotclk); |
| 215 | |
| 216 | return max_dotclk; |
| 217 | } |
| 218 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 219 | static void |
| 220 | intel_dp_set_source_rates(struct intel_dp *intel_dp) |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 221 | { |
| 222 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 223 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 224 | enum port port = dig_port->port; |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 225 | const int *source_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 226 | int size; |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 227 | u32 voltage; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 228 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 229 | /* This should only be done once */ |
| 230 | WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates); |
| 231 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 232 | if (IS_GEN9_LP(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 233 | source_rates = bxt_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 234 | size = ARRAY_SIZE(bxt_rates); |
Rodrigo Vivi | d907b66 | 2017-08-10 15:40:08 -0700 | [diff] [blame] | 235 | } else if (IS_CANNONLAKE(dev_priv)) { |
| 236 | source_rates = cnl_rates; |
| 237 | size = ARRAY_SIZE(cnl_rates); |
| 238 | voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; |
| 239 | if (port == PORT_A || port == PORT_D || |
| 240 | voltage == VOLTAGE_INFO_0_85V) |
| 241 | size -= 2; |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 242 | } else if (IS_GEN9_BC(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 243 | source_rates = skl_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 244 | size = ARRAY_SIZE(skl_rates); |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 245 | } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) || |
| 246 | IS_BROADWELL(dev_priv)) { |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 247 | source_rates = default_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 248 | size = ARRAY_SIZE(default_rates); |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 249 | } else { |
| 250 | source_rates = default_rates; |
| 251 | size = ARRAY_SIZE(default_rates) - 1; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 254 | intel_dp->source_rates = source_rates; |
| 255 | intel_dp->num_source_rates = size; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static int intersect_rates(const int *source_rates, int source_len, |
| 259 | const int *sink_rates, int sink_len, |
| 260 | int *common_rates) |
| 261 | { |
| 262 | int i = 0, j = 0, k = 0; |
| 263 | |
| 264 | while (i < source_len && j < sink_len) { |
| 265 | if (source_rates[i] == sink_rates[j]) { |
| 266 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
| 267 | return k; |
| 268 | common_rates[k] = source_rates[i]; |
| 269 | ++k; |
| 270 | ++i; |
| 271 | ++j; |
| 272 | } else if (source_rates[i] < sink_rates[j]) { |
| 273 | ++i; |
| 274 | } else { |
| 275 | ++j; |
| 276 | } |
| 277 | } |
| 278 | return k; |
| 279 | } |
| 280 | |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 281 | /* return index of rate in rates array, or -1 if not found */ |
| 282 | static int intel_dp_rate_index(const int *rates, int len, int rate) |
| 283 | { |
| 284 | int i; |
| 285 | |
| 286 | for (i = 0; i < len; i++) |
| 287 | if (rate == rates[i]) |
| 288 | return i; |
| 289 | |
| 290 | return -1; |
| 291 | } |
| 292 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 293 | 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] | 294 | { |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 295 | 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] | 296 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 297 | intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates, |
| 298 | intel_dp->num_source_rates, |
| 299 | intel_dp->sink_rates, |
| 300 | intel_dp->num_sink_rates, |
| 301 | intel_dp->common_rates); |
| 302 | |
| 303 | /* Paranoia, there should always be something in common. */ |
| 304 | if (WARN_ON(intel_dp->num_common_rates == 0)) { |
| 305 | intel_dp->common_rates[0] = default_rates[0]; |
| 306 | intel_dp->num_common_rates = 1; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* get length of common rates potentially limited by max_rate */ |
| 311 | static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp, |
| 312 | int max_rate) |
| 313 | { |
| 314 | const int *common_rates = intel_dp->common_rates; |
| 315 | int i, common_len = intel_dp->num_common_rates; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 316 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 317 | /* Limit results by potentially reduced max rate */ |
| 318 | for (i = 0; i < common_len; i++) { |
| 319 | if (common_rates[common_len - i - 1] <= max_rate) |
| 320 | return common_len - i; |
| 321 | } |
| 322 | |
| 323 | return 0; |
Navare, Manasi D | 40dba34 | 2016-10-26 16:25:55 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 326 | static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate, |
| 327 | uint8_t lane_count) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 328 | { |
| 329 | /* |
| 330 | * FIXME: we need to synchronize the current link parameters with |
| 331 | * hardware readout. Currently fast link training doesn't work on |
| 332 | * boot-up. |
| 333 | */ |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 334 | if (link_rate == 0 || |
| 335 | link_rate > intel_dp->max_link_rate) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 336 | return false; |
| 337 | |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 338 | if (lane_count == 0 || |
| 339 | lane_count > intel_dp_max_lane_count(intel_dp)) |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 340 | return false; |
| 341 | |
| 342 | return true; |
| 343 | } |
| 344 | |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 345 | int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, |
| 346 | int link_rate, uint8_t lane_count) |
| 347 | { |
Jani Nikula | b1810a7 | 2017-04-06 16:44:11 +0300 | [diff] [blame] | 348 | int index; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 349 | |
Jani Nikula | b1810a7 | 2017-04-06 16:44:11 +0300 | [diff] [blame] | 350 | index = intel_dp_rate_index(intel_dp->common_rates, |
| 351 | intel_dp->num_common_rates, |
| 352 | link_rate); |
| 353 | if (index > 0) { |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 354 | intel_dp->max_link_rate = intel_dp->common_rates[index - 1]; |
| 355 | intel_dp->max_link_lane_count = lane_count; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 356 | } else if (lane_count > 1) { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 357 | intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp); |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 358 | intel_dp->max_link_lane_count = lane_count >> 1; |
Manasi Navare | fdb14d3 | 2016-12-08 19:05:12 -0800 | [diff] [blame] | 359 | } else { |
| 360 | DRM_ERROR("Link Training Unsuccessful\n"); |
| 361 | return -1; |
| 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 367 | static enum drm_mode_status |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 368 | intel_dp_mode_valid(struct drm_connector *connector, |
| 369 | struct drm_display_mode *mode) |
| 370 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 371 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 372 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 373 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 374 | int target_clock = mode->clock; |
| 375 | int max_rate, mode_rate, max_lanes, max_link_clock; |
Mika Kahola | 70ec064 | 2016-09-09 14:10:55 +0300 | [diff] [blame] | 376 | int max_dotclk; |
| 377 | |
| 378 | max_dotclk = intel_dp_downstream_max_dotclock(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 379 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 380 | if (intel_dp_is_edp(intel_dp) && fixed_mode) { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 381 | if (mode->hdisplay > fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 382 | return MODE_PANEL; |
| 383 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 384 | if (mode->vdisplay > fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 385 | return MODE_PANEL; |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 386 | |
| 387 | target_clock = fixed_mode->clock; |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 390 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 391 | max_lanes = intel_dp_max_lane_count(intel_dp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 392 | |
| 393 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); |
| 394 | mode_rate = intel_dp_link_required(target_clock, 18); |
| 395 | |
Mika Kahola | 799487f | 2016-02-02 15:16:38 +0200 | [diff] [blame] | 396 | if (mode_rate > max_rate || target_clock > max_dotclk) |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 397 | return MODE_CLOCK_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 398 | |
| 399 | if (mode->clock < 10000) |
| 400 | return MODE_CLOCK_LOW; |
| 401 | |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 402 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 403 | return MODE_H_ILLEGAL; |
| 404 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 405 | return MODE_OK; |
| 406 | } |
| 407 | |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 408 | 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] | 409 | { |
| 410 | int i; |
| 411 | uint32_t v = 0; |
| 412 | |
| 413 | if (src_bytes > 4) |
| 414 | src_bytes = 4; |
| 415 | for (i = 0; i < src_bytes; i++) |
| 416 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 417 | return v; |
| 418 | } |
| 419 | |
Damien Lespiau | c2af70e | 2015-02-10 19:32:23 +0000 | [diff] [blame] | 420 | 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] | 421 | { |
| 422 | int i; |
| 423 | if (dst_bytes > 4) |
| 424 | dst_bytes = 4; |
| 425 | for (i = 0; i < dst_bytes; i++) |
| 426 | dst[i] = src >> ((3-i) * 8); |
| 427 | } |
| 428 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 429 | static void |
| 430 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 431 | struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 432 | static void |
| 433 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 434 | struct intel_dp *intel_dp, |
| 435 | bool force_disable_vdd); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 436 | static void |
| 437 | intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 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", |
| 480 | pipe_name(pipe), port_name(intel_dig_port->port))) |
| 481 | return; |
| 482 | |
| 483 | DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n", |
| 484 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 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 | { |
| 581 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 582 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 583 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 584 | enum pipe pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 585 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 586 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 587 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 588 | /* We should never land here with regular DP ports */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 589 | WARN_ON(!intel_dp_is_edp(intel_dp)); |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 590 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 591 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE && |
| 592 | intel_dp->active_pipe != intel_dp->pps_pipe); |
| 593 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 594 | if (intel_dp->pps_pipe != INVALID_PIPE) |
| 595 | return intel_dp->pps_pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 596 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 597 | pipe = vlv_find_free_pps(dev_priv); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * Didn't find one. This should not happen since there |
| 601 | * are two power sequencers and up to two eDP ports. |
| 602 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 603 | if (WARN_ON(pipe == INVALID_PIPE)) |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 604 | pipe = PIPE_A; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 605 | |
Ville Syrjälä | a8c3344 | 2014-10-16 21:29:59 +0300 | [diff] [blame] | 606 | vlv_steal_power_sequencer(dev, pipe); |
| 607 | intel_dp->pps_pipe = pipe; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 608 | |
| 609 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", |
| 610 | pipe_name(intel_dp->pps_pipe), |
| 611 | port_name(intel_dig_port->port)); |
| 612 | |
| 613 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 614 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 615 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 616 | |
Ville Syrjälä | 961a0db | 2014-10-16 21:29:42 +0300 | [diff] [blame] | 617 | /* |
| 618 | * Even vdd force doesn't work until we've made |
| 619 | * the power sequencer lock in on the port. |
| 620 | */ |
| 621 | vlv_power_sequencer_kick(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 622 | |
| 623 | return intel_dp->pps_pipe; |
| 624 | } |
| 625 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 626 | static int |
| 627 | bxt_power_sequencer_idx(struct intel_dp *intel_dp) |
| 628 | { |
| 629 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 630 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 631 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 632 | |
| 633 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 634 | |
| 635 | /* We should never land here with regular DP ports */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 636 | WARN_ON(!intel_dp_is_edp(intel_dp)); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 637 | |
| 638 | /* |
| 639 | * TODO: BXT has 2 PPS instances. The correct port->PPS instance |
| 640 | * mapping needs to be retrieved from VBT, for now just hard-code to |
| 641 | * use instance #0 always. |
| 642 | */ |
| 643 | if (!intel_dp->pps_reset) |
| 644 | return 0; |
| 645 | |
| 646 | intel_dp->pps_reset = false; |
| 647 | |
| 648 | /* |
| 649 | * Only the HW needs to be reprogrammed, the SW state is fixed and |
| 650 | * has been setup during connector init. |
| 651 | */ |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 652 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 657 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
| 658 | enum pipe pipe); |
| 659 | |
| 660 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, |
| 661 | enum pipe pipe) |
| 662 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 663 | return I915_READ(PP_STATUS(pipe)) & PP_ON; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, |
| 667 | enum pipe pipe) |
| 668 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 669 | return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD; |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, |
| 673 | enum pipe pipe) |
| 674 | { |
| 675 | return true; |
| 676 | } |
| 677 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 678 | static enum pipe |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 679 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
| 680 | enum port port, |
| 681 | vlv_pipe_check pipe_check) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 682 | { |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 683 | enum pipe pipe; |
| 684 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 685 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 686 | u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) & |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 687 | PANEL_PORT_SELECT_MASK; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 688 | |
| 689 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) |
| 690 | continue; |
| 691 | |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 692 | if (!pipe_check(dev_priv, pipe)) |
| 693 | continue; |
| 694 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 695 | return pipe; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 696 | } |
| 697 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 698 | return INVALID_PIPE; |
| 699 | } |
| 700 | |
| 701 | static void |
| 702 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) |
| 703 | { |
| 704 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 705 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 706 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 707 | enum port port = intel_dig_port->port; |
| 708 | |
| 709 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 710 | |
| 711 | /* try to find a pipe with this port selected */ |
Ville Syrjälä | 6491ab2 | 2014-08-18 22:16:06 +0300 | [diff] [blame] | 712 | /* first pick one where the panel is on */ |
| 713 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 714 | vlv_pipe_has_pp_on); |
| 715 | /* didn't find one? pick one where vdd is on */ |
| 716 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 717 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 718 | vlv_pipe_has_vdd_on); |
| 719 | /* didn't find one? pick one with just the correct port */ |
| 720 | if (intel_dp->pps_pipe == INVALID_PIPE) |
| 721 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, |
| 722 | vlv_pipe_any); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 723 | |
| 724 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ |
| 725 | if (intel_dp->pps_pipe == INVALID_PIPE) { |
| 726 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", |
| 727 | port_name(port)); |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
| 732 | port_name(port), pipe_name(intel_dp->pps_pipe)); |
| 733 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 734 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 735 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 736 | } |
| 737 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 738 | void intel_power_sequencer_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 739 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 740 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 741 | struct intel_encoder *encoder; |
| 742 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 743 | 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] | 744 | !IS_GEN9_LP(dev_priv))) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 745 | return; |
| 746 | |
| 747 | /* |
| 748 | * We can't grab pps_mutex here due to deadlock with power_domain |
| 749 | * mutex when power_domain functions are called while holding pps_mutex. |
| 750 | * That also means that in order to use pps_pipe the code needs to |
| 751 | * hold both a power domain reference and pps_mutex, and the power domain |
| 752 | * reference get/put must be done while _not_ holding pps_mutex. |
| 753 | * pps_{lock,unlock}() do these steps in the correct order, so one |
| 754 | * should use them always. |
| 755 | */ |
| 756 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 757 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 758 | struct intel_dp *intel_dp; |
| 759 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 760 | if (encoder->type != INTEL_OUTPUT_DP && |
| 761 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 762 | continue; |
| 763 | |
| 764 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 765 | |
| 766 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 767 | |
| 768 | if (encoder->type != INTEL_OUTPUT_EDP) |
| 769 | continue; |
| 770 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 771 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 772 | intel_dp->pps_reset = true; |
| 773 | else |
| 774 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 775 | } |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 776 | } |
| 777 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 778 | struct pps_registers { |
| 779 | i915_reg_t pp_ctrl; |
| 780 | i915_reg_t pp_stat; |
| 781 | i915_reg_t pp_on; |
| 782 | i915_reg_t pp_off; |
| 783 | i915_reg_t pp_div; |
| 784 | }; |
| 785 | |
| 786 | static void intel_pps_get_registers(struct drm_i915_private *dev_priv, |
| 787 | struct intel_dp *intel_dp, |
| 788 | struct pps_registers *regs) |
| 789 | { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 790 | int pps_idx = 0; |
| 791 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 792 | memset(regs, 0, sizeof(*regs)); |
| 793 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 794 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 795 | pps_idx = bxt_power_sequencer_idx(intel_dp); |
| 796 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 797 | pps_idx = vlv_power_sequencer_pipe(intel_dp); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 798 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 799 | regs->pp_ctrl = PP_CONTROL(pps_idx); |
| 800 | regs->pp_stat = PP_STATUS(pps_idx); |
| 801 | regs->pp_on = PP_ON_DELAYS(pps_idx); |
| 802 | regs->pp_off = PP_OFF_DELAYS(pps_idx); |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 803 | if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 804 | regs->pp_div = PP_DIVISOR(pps_idx); |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 805 | } |
| 806 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 807 | static i915_reg_t |
| 808 | _pp_ctrl_reg(struct intel_dp *intel_dp) |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 809 | { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 810 | struct pps_registers regs; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 811 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 812 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 813 | ®s); |
| 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 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 823 | intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp, |
| 824 | ®s); |
| 825 | |
| 826 | return regs.pp_stat; |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 827 | } |
| 828 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 829 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
| 830 | This function only applicable when panel PM state is not to be tracked */ |
| 831 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, |
| 832 | void *unused) |
| 833 | { |
| 834 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), |
| 835 | edp_notifier); |
| 836 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 837 | struct drm_i915_private *dev_priv = to_i915(dev); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 838 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 839 | if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART) |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 840 | return 0; |
| 841 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 842 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 843 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 844 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 845 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 846 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 847 | u32 pp_div; |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 848 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 849 | pp_ctrl_reg = PP_CONTROL(pipe); |
| 850 | pp_div_reg = PP_DIVISOR(pipe); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 851 | pp_div = I915_READ(pp_div_reg); |
| 852 | pp_div &= PP_REFERENCE_DIVIDER_MASK; |
| 853 | |
| 854 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ |
| 855 | I915_WRITE(pp_div_reg, pp_div | 0x1F); |
| 856 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 857 | msleep(intel_dp->panel_power_cycle_delay); |
| 858 | } |
| 859 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 860 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 861 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 862 | return 0; |
| 863 | } |
| 864 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 865 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 866 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 867 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 868 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 869 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 870 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 871 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 872 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 873 | intel_dp->pps_pipe == INVALID_PIPE) |
| 874 | return false; |
| 875 | |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 876 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 879 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 880 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 881 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 882 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 883 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 884 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 885 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 886 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Ville Syrjälä | 9a42356 | 2014-10-16 21:29:48 +0300 | [diff] [blame] | 887 | intel_dp->pps_pipe == INVALID_PIPE) |
| 888 | return false; |
| 889 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 890 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 893 | static void |
| 894 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 895 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 896 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 897 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 898 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 899 | if (!intel_dp_is_edp(intel_dp)) |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 900 | return; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 901 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 902 | 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] | 903 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 904 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Jani Nikula | bf13e81 | 2013-09-06 07:40:05 +0300 | [diff] [blame] | 905 | I915_READ(_pp_stat_reg(intel_dp)), |
| 906 | I915_READ(_pp_ctrl_reg(intel_dp))); |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 910 | static uint32_t |
| 911 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) |
| 912 | { |
| 913 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 914 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 915 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 916 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 917 | uint32_t status; |
| 918 | bool done; |
| 919 | |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 920 | #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] | 921 | if (has_aux_irq) |
Paulo Zanoni | b18ac46 | 2013-02-18 19:00:24 -0300 | [diff] [blame] | 922 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
Imre Deak | 3598706 | 2013-05-21 20:03:20 +0300 | [diff] [blame] | 923 | msecs_to_jiffies_timeout(10)); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 924 | else |
Imre Deak | 713a6b66 | 2016-06-28 13:37:33 +0300 | [diff] [blame] | 925 | done = wait_for(C, 10) == 0; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 926 | if (!done) |
| 927 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", |
| 928 | has_aux_irq); |
| 929 | #undef C |
| 930 | |
| 931 | return status; |
| 932 | } |
| 933 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 934 | 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] | 935 | { |
| 936 | 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] | 937 | 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] | 938 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 939 | if (index) |
| 940 | return 0; |
| 941 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 942 | /* |
| 943 | * 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] | 944 | * 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] | 945 | */ |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 946 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 950 | { |
| 951 | 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] | 952 | 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] | 953 | |
| 954 | if (index) |
| 955 | return 0; |
| 956 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 957 | /* |
| 958 | * The clock divider is based off the cdclk or PCH rawclk, and would |
| 959 | * like to run at 2MHz. So, take the cdclk or PCH rawclk value and |
| 960 | * divide by 2000 and use that |
| 961 | */ |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 962 | if (intel_dig_port->port == PORT_A) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 963 | return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 964 | else |
| 965 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | 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] | 969 | { |
| 970 | 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] | 971 | 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] | 972 | |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 973 | if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) { |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 974 | /* Workaround for non-ULT HSW */ |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 975 | switch (index) { |
| 976 | case 0: return 63; |
| 977 | case 1: return 72; |
| 978 | default: return 0; |
| 979 | } |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 980 | } |
Ville Syrjälä | a457f54 | 2016-03-02 17:22:17 +0200 | [diff] [blame] | 981 | |
| 982 | return ilk_get_aux_clock_divider(intel_dp, index); |
Rodrigo Vivi | b84a1cf | 2013-07-11 18:44:57 -0300 | [diff] [blame] | 983 | } |
| 984 | |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 985 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
| 986 | { |
| 987 | /* |
| 988 | * SKL doesn't need us to program the AUX clock divider (Hardware will |
| 989 | * derive the clock from CDCLK automatically). We still implement the |
| 990 | * get_aux_clock_divider vfunc to plug-in into the existing code. |
| 991 | */ |
| 992 | return index ? 0 : 1; |
| 993 | } |
| 994 | |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 995 | static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 996 | bool has_aux_irq, |
| 997 | int send_bytes, |
| 998 | uint32_t aux_clock_divider) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 999 | { |
| 1000 | 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] | 1001 | struct drm_i915_private *dev_priv = |
| 1002 | to_i915(intel_dig_port->base.base.dev); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1003 | uint32_t precharge, timeout; |
| 1004 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 1005 | if (IS_GEN6(dev_priv)) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1006 | precharge = 3; |
| 1007 | else |
| 1008 | precharge = 5; |
| 1009 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 1010 | if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A) |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1011 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
| 1012 | else |
| 1013 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; |
| 1014 | |
| 1015 | return DP_AUX_CH_CTL_SEND_BUSY | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1016 | DP_AUX_CH_CTL_DONE | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1017 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1018 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1019 | timeout | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1020 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1021 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 1022 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
Damien Lespiau | 788d443 | 2014-01-20 15:52:31 +0000 | [diff] [blame] | 1023 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1026 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
| 1027 | bool has_aux_irq, |
| 1028 | int send_bytes, |
| 1029 | uint32_t unused) |
| 1030 | { |
| 1031 | return DP_AUX_CH_CTL_SEND_BUSY | |
| 1032 | DP_AUX_CH_CTL_DONE | |
| 1033 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
| 1034 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1035 | DP_AUX_CH_CTL_TIME_OUT_1600us | |
| 1036 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
| 1037 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 1038 | DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) | |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 1039 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); |
| 1040 | } |
| 1041 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1042 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1043 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
Daniel Vetter | bd9f74a | 2014-10-02 09:45:35 +0200 | [diff] [blame] | 1044 | const uint8_t *send, int send_bytes, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1045 | uint8_t *recv, int recv_size) |
| 1046 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1047 | 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] | 1048 | struct drm_i915_private *dev_priv = |
| 1049 | to_i915(intel_dig_port->base.base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1050 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1051 | uint32_t aux_clock_divider; |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1052 | int i, ret, recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1053 | uint32_t status; |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1054 | int try, clock = 0; |
Tvrtko Ursulin | 0031fb9 | 2016-11-04 14:42:44 +0000 | [diff] [blame] | 1055 | bool has_aux_irq = HAS_AUX_IRQ(dev_priv); |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1056 | bool vdd; |
| 1057 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1058 | pps_lock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1059 | |
Ville Syrjälä | 72c3500 | 2014-08-18 22:16:00 +0300 | [diff] [blame] | 1060 | /* |
| 1061 | * We will be called with VDD already enabled for dpcd/edid/oui reads. |
| 1062 | * In such cases we want to leave VDD enabled and it's up to upper layers |
| 1063 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off |
| 1064 | * ourselves. |
| 1065 | */ |
Ville Syrjälä | 1e0560e | 2014-08-19 13:24:25 +0300 | [diff] [blame] | 1066 | vdd = edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1067 | |
| 1068 | /* dp aux is extremely sensitive to irq latency, hence request the |
| 1069 | * lowest possible wakeup latency and so prevent the cpu from going into |
| 1070 | * deep sleep states. |
| 1071 | */ |
| 1072 | pm_qos_update_request(&dev_priv->pm_qos, 0); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1073 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 1074 | intel_dp_check_edp(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1075 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1076 | /* Try to wait for any previous AUX channel activity */ |
| 1077 | for (try = 0; try < 3; try++) { |
Daniel Vetter | ef04f00 | 2012-12-01 21:03:59 +0100 | [diff] [blame] | 1078 | status = I915_READ_NOTRACE(ch_ctl); |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 1079 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 1080 | break; |
| 1081 | msleep(1); |
| 1082 | } |
| 1083 | |
| 1084 | if (try == 3) { |
Mika Kuoppala | 02196c7 | 2015-08-06 16:48:58 +0300 | [diff] [blame] | 1085 | static u32 last_status = -1; |
| 1086 | const u32 status = I915_READ(ch_ctl); |
| 1087 | |
| 1088 | if (status != last_status) { |
| 1089 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 1090 | status); |
| 1091 | last_status = status; |
| 1092 | } |
| 1093 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1094 | ret = -EBUSY; |
| 1095 | goto out; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1098 | /* Only 5 data registers! */ |
| 1099 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { |
| 1100 | ret = -E2BIG; |
| 1101 | goto out; |
| 1102 | } |
| 1103 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 1104 | 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] | 1105 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
| 1106 | has_aux_irq, |
| 1107 | send_bytes, |
| 1108 | aux_clock_divider); |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1109 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1110 | /* Must try at least 3 times according to DP spec */ |
| 1111 | for (try = 0; try < 5; try++) { |
| 1112 | /* Load the send data into the aux channel data registers */ |
| 1113 | for (i = 0; i < send_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1114 | I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2], |
Rodrigo Vivi | a4f1289 | 2014-11-14 08:52:27 -0800 | [diff] [blame] | 1115 | intel_dp_pack_aux(send + i, |
| 1116 | send_bytes - i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1117 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1118 | /* Send the command and wait for it to complete */ |
Damien Lespiau | 5ed12a1 | 2014-01-20 15:52:30 +0000 | [diff] [blame] | 1119 | I915_WRITE(ch_ctl, send_ctl); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1120 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1121 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1122 | |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1123 | /* Clear done status and any errors */ |
| 1124 | I915_WRITE(ch_ctl, |
| 1125 | status | |
| 1126 | DP_AUX_CH_CTL_DONE | |
| 1127 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 1128 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Adam Jackson | d7e96fe | 2011-07-26 15:39:46 -0400 | [diff] [blame] | 1129 | |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1130 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1131 | continue; |
Todd Previte | 74ebf29 | 2015-04-15 08:38:41 -0700 | [diff] [blame] | 1132 | |
| 1133 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 |
| 1134 | * 400us delay required for errors and timeouts |
| 1135 | * Timeout errors from the HW already meet this |
| 1136 | * requirement so skip to next iteration |
| 1137 | */ |
| 1138 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
| 1139 | usleep_range(400, 500); |
| 1140 | continue; |
| 1141 | } |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1142 | if (status & DP_AUX_CH_CTL_DONE) |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1143 | goto done; |
Chris Wilson | bc86625 | 2013-07-21 16:00:03 +0100 | [diff] [blame] | 1144 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1147 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1148 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1149 | ret = -EBUSY; |
| 1150 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Jim Bride | e058c94 | 2015-05-27 10:21:48 -0700 | [diff] [blame] | 1153 | done: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1154 | /* Check for timeout or receive error. |
| 1155 | * Timeouts occur when the sink is not connected |
| 1156 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1157 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1158 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1159 | ret = -EIO; |
| 1160 | goto out; |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1161 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 1162 | |
| 1163 | /* Timeouts occur when the device isn't connected, so they're |
| 1164 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 1165 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Chris Wilson | a5570fe | 2017-02-23 11:51:02 +0000 | [diff] [blame] | 1166 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1167 | ret = -ETIMEDOUT; |
| 1168 | goto out; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | /* Unload any bytes sent back from the other side */ |
| 1172 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 1173 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Rodrigo Vivi | 14e0188 | 2015-12-10 11:12:27 -0800 | [diff] [blame] | 1174 | |
| 1175 | /* |
| 1176 | * By BSpec: "Message sizes of 0 or >20 are not allowed." |
| 1177 | * We have no idea of what happened so we return -EBUSY so |
| 1178 | * drm layer takes care for the necessary retries. |
| 1179 | */ |
| 1180 | if (recv_bytes == 0 || recv_bytes > 20) { |
| 1181 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", |
| 1182 | recv_bytes); |
| 1183 | /* |
| 1184 | * FIXME: This patch was created on top of a series that |
| 1185 | * organize the retries at drm level. There EBUSY should |
| 1186 | * also take care for 1ms wait before retrying. |
| 1187 | * That aux retries re-org is still needed and after that is |
| 1188 | * merged we remove this sleep from here. |
| 1189 | */ |
| 1190 | usleep_range(1000, 1500); |
| 1191 | ret = -EBUSY; |
| 1192 | goto out; |
| 1193 | } |
| 1194 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1195 | if (recv_bytes > recv_size) |
| 1196 | recv_bytes = recv_size; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1197 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 1198 | for (i = 0; i < recv_bytes; i += 4) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1199 | 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] | 1200 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1201 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1202 | ret = recv_bytes; |
| 1203 | out: |
| 1204 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); |
| 1205 | |
Jani Nikula | 884f19e | 2014-03-14 16:51:14 +0200 | [diff] [blame] | 1206 | if (vdd) |
| 1207 | edp_panel_vdd_off(intel_dp, false); |
| 1208 | |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 1209 | pps_unlock(intel_dp); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 1210 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1211 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1214 | #define BARE_ADDRESS_SIZE 3 |
| 1215 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1216 | static ssize_t |
| 1217 | 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] | 1218 | { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1219 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
| 1220 | uint8_t txbuf[20], rxbuf[20]; |
| 1221 | size_t txsize, rxsize; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1222 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1223 | |
Ville Syrjälä | d2d9cbb | 2015-03-19 11:44:06 +0200 | [diff] [blame] | 1224 | txbuf[0] = (msg->request << 4) | |
| 1225 | ((msg->address >> 16) & 0xf); |
| 1226 | txbuf[1] = (msg->address >> 8) & 0xff; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1227 | txbuf[2] = msg->address & 0xff; |
| 1228 | txbuf[3] = msg->size - 1; |
Paulo Zanoni | 46a5ae9 | 2013-09-17 11:14:10 -0300 | [diff] [blame] | 1229 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1230 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
| 1231 | case DP_AUX_NATIVE_WRITE: |
| 1232 | case DP_AUX_I2C_WRITE: |
Ville Syrjälä | c1e74122 | 2015-08-27 17:23:27 +0300 | [diff] [blame] | 1233 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1234 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1235 | rxsize = 2; /* 0 or 1 data bytes */ |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1236 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1237 | if (WARN_ON(txsize > 20)) |
| 1238 | return -E2BIG; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1239 | |
Ville Syrjälä | dd78809 | 2016-07-28 17:55:04 +0300 | [diff] [blame] | 1240 | WARN_ON(!msg->buffer != !msg->size); |
| 1241 | |
Imre Deak | d81a67c | 2016-01-29 14:52:26 +0200 | [diff] [blame] | 1242 | if (msg->buffer) |
| 1243 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1244 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1245 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1246 | if (ret > 0) { |
| 1247 | msg->reply = rxbuf[0] >> 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1248 | |
Jani Nikula | a1ddefd | 2015-03-17 17:18:54 +0200 | [diff] [blame] | 1249 | if (ret > 1) { |
| 1250 | /* Number of bytes written in a short write. */ |
| 1251 | ret = clamp_t(int, rxbuf[1], 0, msg->size); |
| 1252 | } else { |
| 1253 | /* Return payload size. */ |
| 1254 | ret = msg->size; |
| 1255 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1256 | } |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1257 | break; |
| 1258 | |
| 1259 | case DP_AUX_NATIVE_READ: |
| 1260 | case DP_AUX_I2C_READ: |
Jani Nikula | a6c8aff0 | 2014-04-07 12:37:25 +0300 | [diff] [blame] | 1261 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1262 | rxsize = msg->size + 1; |
| 1263 | |
| 1264 | if (WARN_ON(rxsize > 20)) |
| 1265 | return -E2BIG; |
| 1266 | |
| 1267 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
| 1268 | if (ret > 0) { |
| 1269 | msg->reply = rxbuf[0] >> 4; |
| 1270 | /* |
| 1271 | * Assume happy day, and copy the data. The caller is |
| 1272 | * expected to check msg->reply before touching it. |
| 1273 | * |
| 1274 | * Return payload size. |
| 1275 | */ |
| 1276 | ret--; |
| 1277 | memcpy(msg->buffer, rxbuf + 1, ret); |
| 1278 | } |
| 1279 | break; |
| 1280 | |
| 1281 | default: |
| 1282 | ret = -EINVAL; |
| 1283 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1284 | } |
Jani Nikula | f51a44b | 2014-02-11 11:52:05 +0200 | [diff] [blame] | 1285 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1286 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Ville Syrjälä | 8f7ce03 | 2016-10-11 20:52:45 +0300 | [diff] [blame] | 1289 | static enum port intel_aux_port(struct drm_i915_private *dev_priv, |
| 1290 | enum port port) |
| 1291 | { |
| 1292 | const struct ddi_vbt_port_info *info = |
| 1293 | &dev_priv->vbt.ddi_port_info[port]; |
| 1294 | enum port aux_port; |
| 1295 | |
| 1296 | if (!info->alternate_aux_channel) { |
| 1297 | DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n", |
| 1298 | port_name(port), port_name(port)); |
| 1299 | return port; |
| 1300 | } |
| 1301 | |
| 1302 | switch (info->alternate_aux_channel) { |
| 1303 | case DP_AUX_A: |
| 1304 | aux_port = PORT_A; |
| 1305 | break; |
| 1306 | case DP_AUX_B: |
| 1307 | aux_port = PORT_B; |
| 1308 | break; |
| 1309 | case DP_AUX_C: |
| 1310 | aux_port = PORT_C; |
| 1311 | break; |
| 1312 | case DP_AUX_D: |
| 1313 | aux_port = PORT_D; |
| 1314 | break; |
| 1315 | default: |
| 1316 | MISSING_CASE(info->alternate_aux_channel); |
| 1317 | aux_port = PORT_A; |
| 1318 | break; |
| 1319 | } |
| 1320 | |
| 1321 | DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n", |
| 1322 | port_name(aux_port), port_name(port)); |
| 1323 | |
| 1324 | return aux_port; |
| 1325 | } |
| 1326 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1327 | 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] | 1328 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1329 | { |
| 1330 | switch (port) { |
| 1331 | case PORT_B: |
| 1332 | case PORT_C: |
| 1333 | case PORT_D: |
| 1334 | return DP_AUX_CH_CTL(port); |
| 1335 | default: |
| 1336 | MISSING_CASE(port); |
| 1337 | return DP_AUX_CH_CTL(PORT_B); |
| 1338 | } |
| 1339 | } |
| 1340 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1341 | 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] | 1342 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1343 | { |
| 1344 | switch (port) { |
| 1345 | case PORT_B: |
| 1346 | case PORT_C: |
| 1347 | case PORT_D: |
| 1348 | return DP_AUX_CH_DATA(port, index); |
| 1349 | default: |
| 1350 | MISSING_CASE(port); |
| 1351 | return DP_AUX_CH_DATA(PORT_B, index); |
| 1352 | } |
| 1353 | } |
| 1354 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1355 | 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] | 1356 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1357 | { |
| 1358 | switch (port) { |
| 1359 | case PORT_A: |
| 1360 | return DP_AUX_CH_CTL(port); |
| 1361 | case PORT_B: |
| 1362 | case PORT_C: |
| 1363 | case PORT_D: |
| 1364 | return PCH_DP_AUX_CH_CTL(port); |
| 1365 | default: |
| 1366 | MISSING_CASE(port); |
| 1367 | return DP_AUX_CH_CTL(PORT_A); |
| 1368 | } |
| 1369 | } |
| 1370 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1371 | 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] | 1372 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1373 | { |
| 1374 | switch (port) { |
| 1375 | case PORT_A: |
| 1376 | return DP_AUX_CH_DATA(port, index); |
| 1377 | case PORT_B: |
| 1378 | case PORT_C: |
| 1379 | case PORT_D: |
| 1380 | return PCH_DP_AUX_CH_DATA(port, index); |
| 1381 | default: |
| 1382 | MISSING_CASE(port); |
| 1383 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1384 | } |
| 1385 | } |
| 1386 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1387 | 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] | 1388 | enum port port) |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1389 | { |
Ville Syrjälä | da00bdc | 2015-11-11 20:34:13 +0200 | [diff] [blame] | 1390 | switch (port) { |
| 1391 | case PORT_A: |
| 1392 | case PORT_B: |
| 1393 | case PORT_C: |
| 1394 | case PORT_D: |
| 1395 | return DP_AUX_CH_CTL(port); |
| 1396 | default: |
| 1397 | MISSING_CASE(port); |
| 1398 | return DP_AUX_CH_CTL(PORT_A); |
| 1399 | } |
| 1400 | } |
| 1401 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1402 | 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] | 1403 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1404 | { |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1405 | switch (port) { |
| 1406 | case PORT_A: |
| 1407 | case PORT_B: |
| 1408 | case PORT_C: |
| 1409 | case PORT_D: |
| 1410 | return DP_AUX_CH_DATA(port, index); |
| 1411 | default: |
| 1412 | MISSING_CASE(port); |
| 1413 | return DP_AUX_CH_DATA(PORT_A, index); |
| 1414 | } |
| 1415 | } |
| 1416 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1417 | 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] | 1418 | enum port port) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1419 | { |
| 1420 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1421 | return skl_aux_ctl_reg(dev_priv, port); |
| 1422 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1423 | return ilk_aux_ctl_reg(dev_priv, port); |
| 1424 | else |
| 1425 | return g4x_aux_ctl_reg(dev_priv, port); |
| 1426 | } |
| 1427 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1428 | 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] | 1429 | enum port port, int index) |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1430 | { |
| 1431 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 1432 | return skl_aux_data_reg(dev_priv, port, index); |
| 1433 | else if (HAS_PCH_SPLIT(dev_priv)) |
| 1434 | return ilk_aux_data_reg(dev_priv, port, index); |
| 1435 | else |
| 1436 | return g4x_aux_data_reg(dev_priv, port, index); |
| 1437 | } |
| 1438 | |
| 1439 | static void intel_aux_reg_init(struct intel_dp *intel_dp) |
| 1440 | { |
| 1441 | 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] | 1442 | enum port port = intel_aux_port(dev_priv, |
| 1443 | dp_to_dig_port(intel_dp)->port); |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1444 | int i; |
| 1445 | |
| 1446 | intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); |
| 1447 | for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++) |
| 1448 | intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i); |
| 1449 | } |
| 1450 | |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1451 | static void |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1452 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
| 1453 | { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1454 | kfree(intel_dp->aux.name); |
| 1455 | } |
| 1456 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1457 | static void |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 1458 | intel_dp_aux_init(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1459 | { |
Jani Nikula | 33ad662 | 2014-03-14 16:51:16 +0200 | [diff] [blame] | 1460 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 1461 | enum port port = intel_dig_port->port; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1462 | |
Ville Syrjälä | 330e20e | 2015-11-11 20:34:14 +0200 | [diff] [blame] | 1463 | intel_aux_reg_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1464 | drm_dp_aux_init(&intel_dp->aux); |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 1465 | |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 1466 | /* Failure to allocate our preferred name is not critical */ |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 1467 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port)); |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 1468 | intel_dp->aux.transfer = intel_dp_aux_transfer; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Ander Conselvan de Oliveira | e588fa1 | 2015-10-23 13:01:50 +0300 | [diff] [blame] | 1471 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1472 | { |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 1473 | 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] | 1474 | |
Jani Nikula | fc603ca | 2017-10-09 12:29:58 +0300 | [diff] [blame] | 1475 | return max_rate >= 540000; |
Thulasimani,Sivakumar | ed63baa | 2015-08-18 15:30:37 +0530 | [diff] [blame] | 1476 | } |
| 1477 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 1478 | static void |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1479 | intel_dp_set_clock(struct intel_encoder *encoder, |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1480 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1481 | { |
| 1482 | struct drm_device *dev = encoder->base.dev; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1483 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1484 | const struct dp_link_dpll *divisor = NULL; |
| 1485 | int i, count = 0; |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1486 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 1487 | if (IS_G4X(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1488 | divisor = gen4_dpll; |
| 1489 | count = ARRAY_SIZE(gen4_dpll); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1490 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1491 | divisor = pch_dpll; |
| 1492 | count = ARRAY_SIZE(pch_dpll); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1493 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1494 | divisor = chv_dpll; |
| 1495 | count = ARRAY_SIZE(chv_dpll); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 1496 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Chon Ming Lee | 65ce4bf | 2013-09-04 01:30:38 +0800 | [diff] [blame] | 1497 | divisor = vlv_dpll; |
| 1498 | count = ARRAY_SIZE(vlv_dpll); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1499 | } |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1500 | |
| 1501 | if (divisor && count) { |
| 1502 | for (i = 0; i < count; i++) { |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1503 | if (pipe_config->port_clock == divisor[i].clock) { |
Chon Ming Lee | 9dd4ffd | 2013-09-04 01:30:37 +0800 | [diff] [blame] | 1504 | pipe_config->dpll = divisor[i].dpll; |
| 1505 | pipe_config->clock_set = true; |
| 1506 | break; |
| 1507 | } |
| 1508 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1512 | static void snprintf_int_array(char *str, size_t len, |
| 1513 | const int *array, int nelem) |
| 1514 | { |
| 1515 | int i; |
| 1516 | |
| 1517 | str[0] = '\0'; |
| 1518 | |
| 1519 | for (i = 0; i < nelem; i++) { |
Jani Nikula | b2f505b | 2015-05-18 16:01:45 +0300 | [diff] [blame] | 1520 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1521 | if (r >= len) |
| 1522 | return; |
| 1523 | str += r; |
| 1524 | len -= r; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | static void intel_dp_print_rates(struct intel_dp *intel_dp) |
| 1529 | { |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1530 | char str[128]; /* FIXME: too big for stack? */ |
| 1531 | |
| 1532 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 1533 | return; |
| 1534 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 1535 | snprintf_int_array(str, sizeof(str), |
| 1536 | intel_dp->source_rates, intel_dp->num_source_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1537 | DRM_DEBUG_KMS("source rates: %s\n", str); |
| 1538 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 1539 | snprintf_int_array(str, sizeof(str), |
| 1540 | intel_dp->sink_rates, intel_dp->num_sink_rates); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1541 | DRM_DEBUG_KMS("sink rates: %s\n", str); |
| 1542 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1543 | snprintf_int_array(str, sizeof(str), |
| 1544 | intel_dp->common_rates, intel_dp->num_common_rates); |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1545 | DRM_DEBUG_KMS("common rates: %s\n", str); |
Ville Syrjälä | 0336400e | 2015-03-12 17:10:39 +0200 | [diff] [blame] | 1546 | } |
| 1547 | |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1548 | int |
| 1549 | intel_dp_max_link_rate(struct intel_dp *intel_dp) |
| 1550 | { |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1551 | int len; |
| 1552 | |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 1553 | 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] | 1554 | if (WARN_ON(len <= 0)) |
| 1555 | return 162000; |
| 1556 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1557 | return intel_dp->common_rates[len - 1]; |
Ville Syrjälä | 50fec21 | 2015-03-12 17:10:34 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1560 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
| 1561 | { |
Jani Nikula | 8001b75 | 2017-03-28 17:59:03 +0300 | [diff] [blame] | 1562 | int i = intel_dp_rate_index(intel_dp->sink_rates, |
| 1563 | intel_dp->num_sink_rates, rate); |
Jani Nikula | b5c72b2 | 2017-03-28 17:59:02 +0300 | [diff] [blame] | 1564 | |
| 1565 | if (WARN_ON(i < 0)) |
| 1566 | i = 0; |
| 1567 | |
| 1568 | return i; |
Ville Syrjälä | ed4e9c1 | 2015-03-12 17:10:36 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 1571 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
| 1572 | uint8_t *link_bw, uint8_t *rate_select) |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1573 | { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 1574 | /* eDP 1.4 rate select method. */ |
| 1575 | if (intel_dp->use_rate_select) { |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1576 | *link_bw = 0; |
| 1577 | *rate_select = |
| 1578 | intel_dp_rate_select(intel_dp, port_clock); |
| 1579 | } else { |
| 1580 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); |
| 1581 | *rate_select = 0; |
| 1582 | } |
| 1583 | } |
| 1584 | |
Jani Nikula | f580bea | 2016-09-15 16:28:52 +0300 | [diff] [blame] | 1585 | static int intel_dp_compute_bpp(struct intel_dp *intel_dp, |
| 1586 | struct intel_crtc_state *pipe_config) |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1587 | { |
| 1588 | int bpp, bpc; |
| 1589 | |
| 1590 | bpp = pipe_config->pipe_bpp; |
| 1591 | bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports); |
| 1592 | |
| 1593 | if (bpc > 0) |
| 1594 | bpp = min(bpp, 3*bpc); |
| 1595 | |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 1596 | /* For DP Compliance we override the computed bpp for the pipe */ |
| 1597 | if (intel_dp->compliance.test_data.bpc != 0) { |
| 1598 | pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc; |
| 1599 | pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3; |
| 1600 | DRM_DEBUG_KMS("Setting pipe_bpp to %d\n", |
| 1601 | pipe_config->pipe_bpp); |
| 1602 | } |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1603 | return bpp; |
| 1604 | } |
| 1605 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 1606 | static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1, |
| 1607 | struct drm_display_mode *m2) |
| 1608 | { |
| 1609 | bool bres = false; |
| 1610 | |
| 1611 | if (m1 && m2) |
| 1612 | bres = (m1->hdisplay == m2->hdisplay && |
| 1613 | m1->hsync_start == m2->hsync_start && |
| 1614 | m1->hsync_end == m2->hsync_end && |
| 1615 | m1->htotal == m2->htotal && |
| 1616 | m1->vdisplay == m2->vdisplay && |
| 1617 | m1->vsync_start == m2->vsync_start && |
| 1618 | m1->vsync_end == m2->vsync_end && |
| 1619 | m1->vtotal == m2->vtotal); |
| 1620 | return bres; |
| 1621 | } |
| 1622 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1623 | bool |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1624 | intel_dp_compute_config(struct intel_encoder *encoder, |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 1625 | struct intel_crtc_state *pipe_config, |
| 1626 | struct drm_connector_state *conn_state) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1627 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1628 | 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] | 1629 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1630 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1631 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ander Conselvan de Oliveira | 84556d5 | 2015-03-20 16:18:10 +0200 | [diff] [blame] | 1632 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1633 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1634 | struct intel_digital_connector_state *intel_conn_state = |
| 1635 | to_intel_digital_connector_state(conn_state); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1636 | int lane_count, clock; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1637 | int min_lane_count = 1; |
Paulo Zanoni | eeb6324 | 2014-05-06 14:56:50 +0300 | [diff] [blame] | 1638 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
Todd Previte | 06ea66b | 2014-01-20 10:19:39 -0700 | [diff] [blame] | 1639 | /* Conveniently, the link BW constants become indices with a shift...*/ |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1640 | int min_clock = 0; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1641 | int max_clock; |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1642 | int bpp, mode_rate; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1643 | int link_avail, link_clock; |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1644 | int common_len; |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1645 | uint8_t link_bw, rate_select; |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1646 | bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc, |
| 1647 | DP_DPCD_QUIRK_LIMITED_M_N); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1648 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1649 | common_len = intel_dp_common_len_rate_limit(intel_dp, |
Jani Nikula | e6c0c64 | 2017-04-06 16:44:12 +0300 | [diff] [blame] | 1650 | intel_dp->max_link_rate); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1651 | |
| 1652 | /* No common link rates between source and sink */ |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1653 | WARN_ON(common_len <= 0); |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1654 | |
Ville Syrjälä | 94ca719 | 2015-03-13 19:40:31 +0200 | [diff] [blame] | 1655 | max_clock = common_len - 1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1656 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1657 | 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] | 1658 | pipe_config->has_pch_encoder = true; |
| 1659 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1660 | pipe_config->has_drrs = false; |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 1661 | if (port == PORT_A) |
| 1662 | pipe_config->has_audio = false; |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1663 | else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO) |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 1664 | pipe_config->has_audio = intel_dp->has_audio; |
| 1665 | else |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1666 | pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1667 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1668 | if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 1669 | struct drm_display_mode *panel_mode = |
| 1670 | intel_connector->panel.alt_fixed_mode; |
| 1671 | struct drm_display_mode *req_mode = &pipe_config->base.mode; |
| 1672 | |
| 1673 | if (!intel_edp_compare_alt_mode(req_mode, panel_mode)) |
| 1674 | panel_mode = intel_connector->panel.fixed_mode; |
| 1675 | |
| 1676 | drm_mode_debug_printmodeline(panel_mode); |
| 1677 | |
| 1678 | intel_fixed_panel_mode(panel_mode, adjusted_mode); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1679 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 1680 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1681 | int ret; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 1682 | ret = skl_update_scaler_crtc(pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 1683 | if (ret) |
| 1684 | return ret; |
| 1685 | } |
| 1686 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 1687 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1688 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 1689 | conn_state->scaling_mode); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 1690 | else |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 1691 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 1692 | conn_state->scaling_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 1693 | } |
| 1694 | |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 1695 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
Daniel Vetter | 0af78a2 | 2012-05-23 11:30:55 +0200 | [diff] [blame] | 1696 | return false; |
| 1697 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1698 | /* Use values requested by Compliance Test Request */ |
| 1699 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
Jani Nikula | ec990e2 | 2017-04-06 16:44:15 +0300 | [diff] [blame] | 1700 | int index; |
| 1701 | |
Manasi Navare | 140ef13 | 2017-06-08 13:41:03 -0700 | [diff] [blame] | 1702 | /* Validate the compliance test data since max values |
| 1703 | * might have changed due to link train fallback. |
| 1704 | */ |
| 1705 | if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate, |
| 1706 | intel_dp->compliance.test_lane_count)) { |
| 1707 | index = intel_dp_rate_index(intel_dp->common_rates, |
| 1708 | intel_dp->num_common_rates, |
| 1709 | intel_dp->compliance.test_link_rate); |
| 1710 | if (index >= 0) |
| 1711 | min_clock = max_clock = index; |
| 1712 | min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count; |
| 1713 | } |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 1714 | } |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1715 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1716 | "max bw %d pixel clock %iKHz\n", |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1717 | max_lane_count, intel_dp->common_rates[max_clock], |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1718 | adjusted_mode->crtc_clock); |
Daniel Vetter | 083f956 | 2012-04-20 20:23:49 +0200 | [diff] [blame] | 1719 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1720 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
| 1721 | * bpc in between. */ |
Mika Kahola | f9bb705 | 2016-09-09 14:10:56 +0300 | [diff] [blame] | 1722 | bpp = intel_dp_compute_bpp(intel_dp, pipe_config); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1723 | if (intel_dp_is_edp(intel_dp)) { |
Thulasimani,Sivakumar | 22ce562 | 2015-07-31 11:05:27 +0530 | [diff] [blame] | 1724 | |
| 1725 | /* Get bpp from vbt only for panels that dont have bpp in edid */ |
| 1726 | if (intel_connector->base.display_info.bpc == 0 && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 1727 | (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) { |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1728 | 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] | 1729 | dev_priv->vbt.edp.bpp); |
| 1730 | bpp = dev_priv->vbt.edp.bpp; |
Jani Nikula | 56071a2 | 2014-05-06 14:56:52 +0300 | [diff] [blame] | 1731 | } |
| 1732 | |
Jani Nikula | 344c5bb | 2014-09-09 11:25:13 +0300 | [diff] [blame] | 1733 | /* |
| 1734 | * Use the maximum clock and number of lanes the eDP panel |
| 1735 | * advertizes being capable of. The panels are generally |
| 1736 | * designed to support only a single clock and lane |
| 1737 | * configuration, and typically these values correspond to the |
| 1738 | * native resolution of the panel. |
| 1739 | */ |
| 1740 | min_lane_count = max_lane_count; |
| 1741 | min_clock = max_clock; |
Imre Deak | 7984211 | 2013-07-18 17:44:13 +0300 | [diff] [blame] | 1742 | } |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1743 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1744 | for (; bpp >= 6*3; bpp -= 2*3) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1745 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
| 1746 | bpp); |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1747 | |
Dave Airlie | c693099 | 2014-07-14 11:04:39 +1000 | [diff] [blame] | 1748 | for (clock = min_clock; clock <= max_clock; clock++) { |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1749 | for (lane_count = min_lane_count; |
| 1750 | lane_count <= max_lane_count; |
| 1751 | lane_count <<= 1) { |
| 1752 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1753 | link_clock = intel_dp->common_rates[clock]; |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1754 | link_avail = intel_dp_max_data_rate(link_clock, |
| 1755 | lane_count); |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 1756 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1757 | if (mode_rate <= link_avail) { |
| 1758 | goto found; |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | return false; |
| 1765 | |
| 1766 | found: |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1767 | if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) { |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1768 | /* |
| 1769 | * See: |
| 1770 | * CEA-861-E - 5.1 Default Encoding Parameters |
| 1771 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry |
| 1772 | */ |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1773 | pipe_config->limited_color_range = |
Ville Syrjälä | c8127cf0 | 2017-01-11 16:18:35 +0200 | [diff] [blame] | 1774 | bpp != 18 && |
| 1775 | drm_default_rgb_quant_range(adjusted_mode) == |
| 1776 | HDMI_QUANTIZATION_RANGE_LIMITED; |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1777 | } else { |
| 1778 | pipe_config->limited_color_range = |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 1779 | intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 1780 | } |
| 1781 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1782 | pipe_config->lane_count = lane_count; |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 1783 | |
Daniel Vetter | 657445f | 2013-05-04 10:09:18 +0200 | [diff] [blame] | 1784 | pipe_config->pipe_bpp = bpp; |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 1785 | pipe_config->port_clock = intel_dp->common_rates[clock]; |
Daniel Vetter | c486793 | 2012-04-10 10:42:36 +0200 | [diff] [blame] | 1786 | |
Ville Syrjälä | 04a60f9 | 2015-07-06 15:10:06 +0300 | [diff] [blame] | 1787 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
| 1788 | &link_bw, &rate_select); |
| 1789 | |
| 1790 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", |
| 1791 | link_bw, rate_select, pipe_config->lane_count, |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 1792 | pipe_config->port_clock, bpp); |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1793 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
| 1794 | mode_rate, link_avail); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1795 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 1796 | intel_link_compute_m_n(bpp, lane_count, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1797 | adjusted_mode->crtc_clock, |
| 1798 | pipe_config->port_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1799 | &pipe_config->dp_m_n, |
| 1800 | reduce_m_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1801 | |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1802 | if (intel_connector->panel.downclock_mode != NULL && |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 1803 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 1804 | pipe_config->has_drrs = true; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1805 | intel_link_compute_m_n(bpp, lane_count, |
| 1806 | intel_connector->panel.downclock_mode->clock, |
| 1807 | pipe_config->port_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 1808 | &pipe_config->dp_m2_n2, |
| 1809 | reduce_m_n); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 1810 | } |
| 1811 | |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1812 | /* |
| 1813 | * DPLL0 VCO may need to be adjusted to get the correct |
| 1814 | * clock for eDP. This will affect cdclk as well. |
| 1815 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 1816 | 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] | 1817 | int vco; |
| 1818 | |
| 1819 | switch (pipe_config->port_clock / 2) { |
| 1820 | case 108000: |
| 1821 | case 216000: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1822 | vco = 8640000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1823 | break; |
| 1824 | default: |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 1825 | vco = 8100000; |
Ville Syrjälä | 14d41b3 | 2016-05-13 23:41:22 +0300 | [diff] [blame] | 1826 | break; |
| 1827 | } |
| 1828 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 1829 | 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] | 1830 | } |
| 1831 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1832 | if (!HAS_DDI(dev_priv)) |
Ville Syrjälä | 840b32b | 2015-08-11 20:21:46 +0300 | [diff] [blame] | 1833 | intel_dp_set_clock(encoder, pipe_config); |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 1834 | |
Daniel Vetter | 3600836 | 2013-03-27 00:44:59 +0100 | [diff] [blame] | 1835 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1838 | 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] | 1839 | int link_rate, uint8_t lane_count, |
| 1840 | bool link_mst) |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1841 | { |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1842 | intel_dp->link_rate = link_rate; |
| 1843 | intel_dp->lane_count = lane_count; |
| 1844 | intel_dp->link_mst = link_mst; |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1845 | } |
| 1846 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1847 | static void intel_dp_prepare(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 1848 | const struct intel_crtc_state *pipe_config) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1849 | { |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1850 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1851 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1852 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 1853 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | b934223d | 2013-07-21 21:37:05 +0200 | [diff] [blame] | 1854 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1855 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1856 | |
Ander Conselvan de Oliveira | dfa1048 | 2016-09-01 15:08:06 -0700 | [diff] [blame] | 1857 | intel_dp_set_link_params(intel_dp, pipe_config->port_clock, |
| 1858 | pipe_config->lane_count, |
| 1859 | intel_crtc_has_type(pipe_config, |
| 1860 | INTEL_OUTPUT_DP_MST)); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1861 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1862 | /* |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1863 | * There are four kinds of DP registers: |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1864 | * |
| 1865 | * IBX PCH |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1866 | * SNB CPU |
| 1867 | * IVB CPU |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1868 | * CPT PCH |
| 1869 | * |
| 1870 | * IBX PCH and CPU are the same for almost everything, |
| 1871 | * except that the CPU DP PLL is configured in this |
| 1872 | * register |
| 1873 | * |
| 1874 | * CPT PCH is quite different, having many bits moved |
| 1875 | * to the TRANS_DP_CTL register instead. That |
| 1876 | * configuration happens (oddly) in ironlake_pch_enable |
| 1877 | */ |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 1878 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1879 | /* Preserve the BIOS-computed detected bit. This is |
| 1880 | * supposed to be read-only. |
| 1881 | */ |
| 1882 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1883 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1884 | /* Handle DP bits in common between all three register formats */ |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1885 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 1886 | intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1887 | |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1888 | /* Split out the IBX/CPU vs CPT settings */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1889 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1890 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1891 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1892 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1893 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1894 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1895 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
| 1896 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1897 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 1898 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1899 | |
Daniel Vetter | 7c62a16 | 2013-06-01 17:16:20 +0200 | [diff] [blame] | 1900 | intel_dp->DP |= crtc->pipe << 29; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1901 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1902 | u32 trans_dp; |
| 1903 | |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1904 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 1905 | |
| 1906 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 1907 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 1908 | trans_dp |= TRANS_DP_ENH_FRAMING; |
| 1909 | else |
| 1910 | trans_dp &= ~TRANS_DP_ENH_FRAMING; |
| 1911 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1912 | } else { |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 1913 | if (IS_G4X(dev_priv) && pipe_config->limited_color_range) |
Ville Syrjälä | 0f2a2a7 | 2015-07-06 15:10:00 +0300 | [diff] [blame] | 1914 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1915 | |
| 1916 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1917 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
| 1918 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1919 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
| 1920 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
| 1921 | |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1922 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 1923 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
| 1924 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1925 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1926 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 1927 | else if (crtc->pipe == PIPE_B) |
| 1928 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1929 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1932 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
| 1933 | #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] | 1934 | |
Paulo Zanoni | 1a5ef5b | 2013-12-19 14:29:43 -0200 | [diff] [blame] | 1935 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
| 1936 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) |
Keith Packard | 99ea712 | 2011-11-01 19:57:50 -0700 | [diff] [blame] | 1937 | |
Paulo Zanoni | ffd6749d | 2013-12-19 14:29:42 -0200 | [diff] [blame] | 1938 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
| 1939 | #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] | 1940 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1941 | static void intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 1942 | struct intel_dp *intel_dp); |
| 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 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 1954 | intel_pps_verify_state(dev_priv, intel_dp); |
| 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", |
| 2068 | port_name(intel_dig_port->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", |
| 2088 | port_name(intel_dig_port->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ä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2114 | port_name(dp_to_dig_port(intel_dp)->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", |
| 2134 | port_name(intel_dig_port->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ä | 3936fcf | 2014-10-16 21:30:02 +0300 | [diff] [blame] | 2194 | port_name(dp_to_dig_port(intel_dp)->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", |
| 2217 | port_name(dp_to_dig_port(intel_dp)->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", |
| 2221 | port_name(dp_to_dig_port(intel_dp)->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", |
| 2276 | port_name(dp_to_dig_port(intel_dp)->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", |
| 2279 | port_name(dp_to_dig_port(intel_dp)->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", |
| 2431 | port_name(dig_port->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 | |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2487 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2488 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 2489 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 64e1077 | 2015-10-29 21:26:01 +0200 | [diff] [blame] | 2490 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
| 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 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2506 | /* If the sink supports it, try to set the power state appropriately */ |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2507 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2508 | { |
| 2509 | int ret, i; |
| 2510 | |
| 2511 | /* Should have a valid DPCD by this point */ |
| 2512 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 2513 | return; |
| 2514 | |
| 2515 | if (mode != DRM_MODE_DPMS_ON) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2516 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2517 | DP_SET_POWER_D3); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2518 | } else { |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2519 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
| 2520 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2521 | /* |
| 2522 | * When turning on, we need to retry for 1ms to give the sink |
| 2523 | * time to wake up. |
| 2524 | */ |
| 2525 | for (i = 0; i < 3; i++) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 2526 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 2527 | DP_SET_POWER_D0); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2528 | if (ret == 1) |
| 2529 | break; |
| 2530 | msleep(1); |
| 2531 | } |
Imre Deak | 357c0ae | 2016-11-21 21:15:06 +0200 | [diff] [blame] | 2532 | |
| 2533 | if (ret == 1 && lspcon->active) |
| 2534 | lspcon_wait_pcon_mode(lspcon); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2535 | } |
Jani Nikula | f9cac72 | 2014-09-02 16:33:52 +0300 | [diff] [blame] | 2536 | |
| 2537 | if (ret != 1) |
| 2538 | DRM_DEBUG_KMS("failed to %s sink power state\n", |
| 2539 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2542 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
| 2543 | enum pipe *pipe) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2544 | { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2545 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 2546 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2547 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2548 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2549 | u32 tmp; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2550 | bool ret; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2551 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2552 | if (!intel_display_power_get_if_enabled(dev_priv, |
| 2553 | encoder->power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2554 | return false; |
| 2555 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2556 | ret = false; |
| 2557 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 2558 | tmp = I915_READ(intel_dp->output_reg); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2559 | |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2560 | if (!(tmp & DP_PORT_EN)) |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2561 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2562 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2563 | if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2564 | *pipe = PORT_TO_PIPE_CPT(tmp); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2565 | } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2566 | enum pipe p; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2567 | |
Ville Syrjälä | adc289d | 2015-05-05 17:17:30 +0300 | [diff] [blame] | 2568 | for_each_pipe(dev_priv, p) { |
| 2569 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); |
| 2570 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { |
| 2571 | *pipe = p; |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2572 | ret = true; |
| 2573 | |
| 2574 | goto out; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2575 | } |
| 2576 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2577 | |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2578 | 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] | 2579 | i915_mmio_reg_offset(intel_dp->output_reg)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2580 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2581 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); |
| 2582 | } else { |
| 2583 | *pipe = PORT_TO_PIPE(tmp); |
Daniel Vetter | 4a0833e | 2012-10-26 10:58:11 +0200 | [diff] [blame] | 2584 | } |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2585 | |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2586 | ret = true; |
| 2587 | |
| 2588 | out: |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 2589 | intel_display_power_put(dev_priv, encoder->power_domain); |
Imre Deak | 6fa9a5e | 2016-02-12 18:55:18 +0200 | [diff] [blame] | 2590 | |
| 2591 | return ret; |
Daniel Vetter | 19d8fe1 | 2012-07-02 13:26:27 +0200 | [diff] [blame] | 2592 | } |
| 2593 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2594 | static void intel_dp_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2595 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2596 | { |
| 2597 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2598 | u32 tmp, flags = 0; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2599 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2600 | struct drm_i915_private *dev_priv = to_i915(dev); |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2601 | enum port port = dp_to_dig_port(intel_dp)->port; |
| 2602 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2603 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2604 | tmp = I915_READ(intel_dp->output_reg); |
Jani Nikula | 9fcb170 | 2015-05-05 16:32:12 +0300 | [diff] [blame] | 2605 | |
| 2606 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2607 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2608 | if (HAS_PCH_CPT(dev_priv) && port != PORT_A) { |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2609 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
| 2610 | |
| 2611 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2612 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2613 | else |
| 2614 | flags |= DRM_MODE_FLAG_NHSYNC; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2615 | |
Ville Syrjälä | b81e34c | 2015-07-06 15:10:03 +0300 | [diff] [blame] | 2616 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2617 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2618 | else |
| 2619 | flags |= DRM_MODE_FLAG_NVSYNC; |
Ville Syrjälä | 39e5fa8 | 2015-05-05 17:17:29 +0300 | [diff] [blame] | 2620 | } else { |
| 2621 | if (tmp & DP_SYNC_HS_HIGH) |
| 2622 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2623 | else |
| 2624 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2625 | |
| 2626 | if (tmp & DP_SYNC_VS_HIGH) |
| 2627 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2628 | else |
| 2629 | flags |= DRM_MODE_FLAG_NVSYNC; |
Xiong Zhang | 63000ef | 2013-06-28 12:59:06 +0800 | [diff] [blame] | 2630 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2631 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2632 | pipe_config->base.adjusted_mode.flags |= flags; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 2633 | |
Ville Syrjälä | c99f53f | 2016-11-14 19:44:07 +0200 | [diff] [blame] | 2634 | if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235) |
Ville Syrjälä | 8c875fc | 2014-09-12 15:46:29 +0300 | [diff] [blame] | 2635 | pipe_config->limited_color_range = true; |
| 2636 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2637 | pipe_config->lane_count = |
| 2638 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; |
| 2639 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2640 | intel_dp_get_m_n(crtc, pipe_config); |
| 2641 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2642 | if (port == PORT_A) { |
Ville Syrjälä | b377e0d | 2015-10-29 21:25:59 +0200 | [diff] [blame] | 2643 | 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] | 2644 | pipe_config->port_clock = 162000; |
| 2645 | else |
| 2646 | pipe_config->port_clock = 270000; |
| 2647 | } |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 2648 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 2649 | pipe_config->base.adjusted_mode.crtc_clock = |
| 2650 | intel_dotclock_calculate(pipe_config->port_clock, |
| 2651 | &pipe_config->dp_m_n); |
Daniel Vetter | 7f16e5c | 2013-11-04 16:28:47 +0100 | [diff] [blame] | 2652 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 2653 | if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp && |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2654 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2655 | /* |
| 2656 | * This is a big fat ugly hack. |
| 2657 | * |
| 2658 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2659 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2660 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2661 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2662 | * max, not what it tells us to use. |
| 2663 | * |
| 2664 | * Note: This will still be broken if the eDP panel is not lit |
| 2665 | * up by the BIOS, and thus we can't get the mode at module |
| 2666 | * load. |
| 2667 | */ |
| 2668 | 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] | 2669 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2670 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Jani Nikula | c6cd2ee | 2013-10-21 10:52:07 +0300 | [diff] [blame] | 2671 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2674 | static void intel_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2675 | const struct intel_crtc_state *old_crtc_state, |
| 2676 | const struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2677 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2678 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2679 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2680 | if (old_crtc_state->has_audio) |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 2681 | intel_audio_codec_disable(encoder); |
Daniel Vetter | 6cb4983 | 2012-05-20 17:14:50 +0200 | [diff] [blame] | 2682 | |
| 2683 | /* Make sure the panel is off before trying to change the mode. But also |
| 2684 | * ensure that we have vdd while we switch off the panel. */ |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 2685 | intel_edp_panel_vdd_on(intel_dp); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2686 | intel_edp_backlight_off(old_conn_state); |
Jani Nikula | fdbc3b1 | 2013-11-12 17:10:13 +0200 | [diff] [blame] | 2687 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2688 | intel_edp_panel_off(intel_dp); |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | static void g4x_disable_dp(struct intel_encoder *encoder, |
| 2692 | const struct intel_crtc_state *old_crtc_state, |
| 2693 | const struct drm_connector_state *old_conn_state) |
| 2694 | { |
| 2695 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2696 | |
| 2697 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
Daniel Vetter | 3739850 | 2012-09-06 22:15:44 +0200 | [diff] [blame] | 2698 | |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2699 | /* disable the port before the pipe on g4x */ |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 2700 | intel_dp_link_down(intel_dp); |
| 2701 | } |
| 2702 | |
| 2703 | static void ilk_disable_dp(struct intel_encoder *encoder, |
| 2704 | const struct intel_crtc_state *old_crtc_state, |
| 2705 | const struct drm_connector_state *old_conn_state) |
| 2706 | { |
| 2707 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
| 2708 | } |
| 2709 | |
| 2710 | static void vlv_disable_dp(struct intel_encoder *encoder, |
| 2711 | const struct intel_crtc_state *old_crtc_state, |
| 2712 | const struct drm_connector_state *old_conn_state) |
| 2713 | { |
| 2714 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2715 | |
| 2716 | intel_psr_disable(intel_dp, old_crtc_state); |
| 2717 | |
| 2718 | intel_disable_dp(encoder, old_crtc_state, old_conn_state); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2721 | static void ilk_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2722 | const struct intel_crtc_state *old_crtc_state, |
| 2723 | const struct drm_connector_state *old_conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2724 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2725 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Imre Deak | 982a386 | 2013-05-23 19:39:40 +0300 | [diff] [blame] | 2726 | enum port port = dp_to_dig_port(intel_dp)->port; |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2727 | |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2728 | intel_dp_link_down(intel_dp); |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2729 | |
| 2730 | /* Only ilk+ has port A */ |
Ville Syrjälä | 08aff3f | 2014-08-18 22:16:09 +0300 | [diff] [blame] | 2731 | if (port == PORT_A) |
| 2732 | ironlake_edp_pll_off(intel_dp); |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2733 | } |
| 2734 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2735 | static void vlv_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2736 | const struct intel_crtc_state *old_crtc_state, |
| 2737 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 2738 | { |
| 2739 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2740 | |
| 2741 | intel_dp_link_down(intel_dp); |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2742 | } |
| 2743 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2744 | static void chv_post_disable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2745 | const struct intel_crtc_state *old_crtc_state, |
| 2746 | const struct drm_connector_state *old_conn_state) |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2747 | { |
| 2748 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2749 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2750 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2751 | |
| 2752 | intel_dp_link_down(intel_dp); |
| 2753 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2754 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2755 | |
Ville Syrjälä | a8f327f | 2015-07-09 20:14:11 +0300 | [diff] [blame] | 2756 | /* Assert data lane reset */ |
| 2757 | chv_data_lane_soft_reset(encoder, true); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2758 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 2759 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 2760 | } |
| 2761 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2762 | static void |
| 2763 | _intel_dp_set_link_train(struct intel_dp *intel_dp, |
| 2764 | uint32_t *DP, |
| 2765 | uint8_t dp_train_pat) |
| 2766 | { |
| 2767 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2768 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2769 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2770 | enum port port = intel_dig_port->port; |
| 2771 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2772 | if (dp_train_pat & DP_TRAINING_PATTERN_MASK) |
| 2773 | DRM_DEBUG_KMS("Using DP training pattern TPS%d\n", |
| 2774 | dp_train_pat & DP_TRAINING_PATTERN_MASK); |
| 2775 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 2776 | if (HAS_DDI(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2777 | uint32_t temp = I915_READ(DP_TP_CTL(port)); |
| 2778 | |
| 2779 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) |
| 2780 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2781 | else |
| 2782 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; |
| 2783 | |
| 2784 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 2785 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2786 | case DP_TRAINING_PATTERN_DISABLE: |
| 2787 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; |
| 2788 | |
| 2789 | break; |
| 2790 | case DP_TRAINING_PATTERN_1: |
| 2791 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2792 | break; |
| 2793 | case DP_TRAINING_PATTERN_2: |
| 2794 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; |
| 2795 | break; |
| 2796 | case DP_TRAINING_PATTERN_3: |
| 2797 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; |
| 2798 | break; |
| 2799 | } |
| 2800 | I915_WRITE(DP_TP_CTL(port), temp); |
| 2801 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2802 | } else if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 2803 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2804 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 2805 | |
| 2806 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2807 | case DP_TRAINING_PATTERN_DISABLE: |
| 2808 | *DP |= DP_LINK_TRAIN_OFF_CPT; |
| 2809 | break; |
| 2810 | case DP_TRAINING_PATTERN_1: |
| 2811 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; |
| 2812 | break; |
| 2813 | case DP_TRAINING_PATTERN_2: |
| 2814 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2815 | break; |
| 2816 | case DP_TRAINING_PATTERN_3: |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2817 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2818 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; |
| 2819 | break; |
| 2820 | } |
| 2821 | |
| 2822 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2823 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2824 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 2825 | else |
| 2826 | *DP &= ~DP_LINK_TRAIN_MASK; |
| 2827 | |
| 2828 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { |
| 2829 | case DP_TRAINING_PATTERN_DISABLE: |
| 2830 | *DP |= DP_LINK_TRAIN_OFF; |
| 2831 | break; |
| 2832 | case DP_TRAINING_PATTERN_1: |
| 2833 | *DP |= DP_LINK_TRAIN_PAT_1; |
| 2834 | break; |
| 2835 | case DP_TRAINING_PATTERN_2: |
| 2836 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2837 | break; |
| 2838 | case DP_TRAINING_PATTERN_3: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2839 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2840 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; |
| 2841 | } else { |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2842 | DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n"); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2843 | *DP |= DP_LINK_TRAIN_PAT_2; |
| 2844 | } |
| 2845 | break; |
| 2846 | } |
| 2847 | } |
| 2848 | } |
| 2849 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2850 | static void intel_dp_enable_port(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2851 | const struct intel_crtc_state *old_crtc_state) |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2852 | { |
| 2853 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2854 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2855 | |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2856 | /* enable with pattern 1 (as per spec) */ |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2857 | |
Pandiyan, Dhinakaran | 8b0878a | 2016-08-04 13:48:35 -0700 | [diff] [blame] | 2858 | 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] | 2859 | |
| 2860 | /* |
| 2861 | * Magic for VLV/CHV. We _must_ first set up the register |
| 2862 | * without actually enabling the port, and then do another |
| 2863 | * write to enable the port. Otherwise link training will |
| 2864 | * fail when the power sequencer is freshly used for this port. |
| 2865 | */ |
| 2866 | intel_dp->DP |= DP_PORT_EN; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2867 | if (old_crtc_state->has_audio) |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 2868 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Ville Syrjälä | 7b713f5 | 2014-10-16 21:27:35 +0300 | [diff] [blame] | 2869 | |
| 2870 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 2871 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 7b13b58 | 2014-08-18 22:16:08 +0300 | [diff] [blame] | 2872 | } |
| 2873 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2874 | static void intel_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2875 | const struct intel_crtc_state *pipe_config, |
| 2876 | const struct drm_connector_state *conn_state) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2877 | { |
Daniel Vetter | e8cb455 | 2012-07-01 13:05:48 +0200 | [diff] [blame] | 2878 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2879 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2880 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2881 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2882 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2883 | enum pipe pipe = crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2884 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 2885 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
| 2886 | return; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2887 | |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2888 | pps_lock(intel_dp); |
| 2889 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2890 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2891 | vlv_init_panel_power_sequencer(intel_dp); |
| 2892 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2893 | intel_dp_enable_port(intel_dp, pipe_config); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 2894 | |
| 2895 | edp_panel_vdd_on(intel_dp); |
| 2896 | edp_panel_on(intel_dp); |
| 2897 | edp_panel_vdd_off(intel_dp, true); |
| 2898 | |
| 2899 | pps_unlock(intel_dp); |
| 2900 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2901 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2902 | unsigned int lane_mask = 0x0; |
| 2903 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2904 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2905 | lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2906 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 2907 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
| 2908 | lane_mask); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2909 | } |
Ville Syrjälä | 61234fa | 2014-10-16 21:27:34 +0300 | [diff] [blame] | 2910 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2911 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 2912 | intel_dp_start_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2913 | intel_dp_stop_link_train(intel_dp); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2914 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2915 | if (pipe_config->has_audio) { |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2916 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2917 | pipe_name(pipe)); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2918 | intel_audio_codec_enable(encoder, pipe_config, conn_state); |
Jani Nikula | c1dec79 | 2014-10-27 16:26:56 +0200 | [diff] [blame] | 2919 | } |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2920 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2921 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2922 | static void g4x_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2923 | const struct intel_crtc_state *pipe_config, |
| 2924 | const struct drm_connector_state *conn_state) |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 2925 | { |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 2926 | intel_enable_dp(encoder, pipe_config, conn_state); |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2927 | intel_edp_backlight_on(pipe_config, conn_state); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2928 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 2929 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2930 | static void vlv_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 2931 | const struct intel_crtc_state *pipe_config, |
| 2932 | const struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2933 | { |
Jani Nikula | 828f5c6 | 2013-09-05 16:44:45 +0300 | [diff] [blame] | 2934 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 2935 | |
Maarten Lankhorst | b037d58 | 2017-06-12 12:21:13 +0200 | [diff] [blame] | 2936 | intel_edp_backlight_on(pipe_config, conn_state); |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 2937 | intel_psr_enable(intel_dp, pipe_config); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 2940 | static void g4x_pre_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) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2943 | { |
Daniel Vetter | 2bd2ad6 | 2012-09-06 22:15:41 +0200 | [diff] [blame] | 2944 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | d6fbdd1 | 2015-10-29 21:25:58 +0200 | [diff] [blame] | 2945 | enum port port = dp_to_dig_port(intel_dp)->port; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2946 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2947 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 2948 | |
Daniel Vetter | d41f1ef | 2014-04-24 23:54:53 +0200 | [diff] [blame] | 2949 | /* Only ilk+ has port A */ |
Ville Syrjälä | abfce94 | 2015-10-29 21:26:03 +0200 | [diff] [blame] | 2950 | if (port == PORT_A) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 2951 | ironlake_edp_pll_on(intel_dp, pipe_config); |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 2952 | } |
| 2953 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2954 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
| 2955 | { |
| 2956 | 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] | 2957 | 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] | 2958 | enum pipe pipe = intel_dp->pps_pipe; |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 2959 | i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe); |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2960 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2961 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
| 2962 | |
Ville Syrjälä | d158694 | 2017-02-08 19:52:54 +0200 | [diff] [blame] | 2963 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 2964 | return; |
| 2965 | |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 2966 | edp_panel_vdd_off_sync(intel_dp); |
| 2967 | |
| 2968 | /* |
| 2969 | * VLV seems to get confused when multiple power seqeuencers |
| 2970 | * have the same port selected (even if only one has power/vdd |
| 2971 | * enabled). The failure manifests as vlv_wait_port_ready() failing |
| 2972 | * CHV on the other hand doesn't seem to mind having the same port |
| 2973 | * selected in multiple power seqeuencers, but let's clear the |
| 2974 | * port select always when logically disconnecting a power sequencer |
| 2975 | * from a port. |
| 2976 | */ |
| 2977 | DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n", |
| 2978 | pipe_name(pipe), port_name(intel_dig_port->port)); |
| 2979 | I915_WRITE(pp_on_reg, 0); |
| 2980 | POSTING_READ(pp_on_reg); |
| 2981 | |
| 2982 | intel_dp->pps_pipe = INVALID_PIPE; |
| 2983 | } |
| 2984 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2985 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
| 2986 | enum pipe pipe) |
| 2987 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2988 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2989 | struct intel_encoder *encoder; |
| 2990 | |
| 2991 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 2992 | |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 2993 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2994 | struct intel_dp *intel_dp; |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 2995 | enum port port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2996 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 2997 | if (encoder->type != INTEL_OUTPUT_DP && |
| 2998 | encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 2999 | continue; |
| 3000 | |
| 3001 | intel_dp = enc_to_intel_dp(&encoder->base); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 3002 | port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3003 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3004 | WARN(intel_dp->active_pipe == pipe, |
| 3005 | "stealing pipe %c power sequencer from active (e)DP port %c\n", |
| 3006 | pipe_name(pipe), port_name(port)); |
| 3007 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3008 | if (intel_dp->pps_pipe != pipe) |
| 3009 | continue; |
| 3010 | |
| 3011 | 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] | 3012 | pipe_name(pipe), port_name(port)); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3013 | |
| 3014 | /* make sure vdd is off before we steal it */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3015 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp) |
| 3020 | { |
| 3021 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3022 | struct intel_encoder *encoder = &intel_dig_port->base; |
| 3023 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3024 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3025 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3026 | |
| 3027 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 3028 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3029 | WARN_ON(intel_dp->active_pipe != INVALID_PIPE); |
Ville Syrjälä | 093e3f1 | 2014-10-16 21:27:33 +0300 | [diff] [blame] | 3030 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3031 | if (intel_dp->pps_pipe != INVALID_PIPE && |
| 3032 | intel_dp->pps_pipe != crtc->pipe) { |
| 3033 | /* |
| 3034 | * If another power sequencer was being used on this |
| 3035 | * port previously make sure to turn off vdd there while |
| 3036 | * we still have control of it. |
| 3037 | */ |
Ville Syrjälä | 83b8459 | 2014-10-16 21:29:51 +0300 | [diff] [blame] | 3038 | vlv_detach_power_sequencer(intel_dp); |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3039 | } |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3040 | |
| 3041 | /* |
| 3042 | * We may be stealing the power |
| 3043 | * sequencer from another port. |
| 3044 | */ |
| 3045 | vlv_steal_power_sequencer(dev, crtc->pipe); |
| 3046 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3047 | intel_dp->active_pipe = crtc->pipe; |
| 3048 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3049 | if (!intel_dp_is_edp(intel_dp)) |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3050 | return; |
| 3051 | |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3052 | /* now it's all ours */ |
| 3053 | intel_dp->pps_pipe = crtc->pipe; |
| 3054 | |
| 3055 | DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n", |
| 3056 | pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port)); |
| 3057 | |
| 3058 | /* init power sequencer on this pipe and port */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 3059 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 3060 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true); |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 3061 | } |
| 3062 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3063 | static void vlv_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3064 | const struct intel_crtc_state *pipe_config, |
| 3065 | const struct drm_connector_state *conn_state) |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 3066 | { |
Ander Conselvan de Oliveira | 5f68c27 | 2016-04-27 15:44:24 +0300 | [diff] [blame] | 3067 | vlv_phy_pre_encoder_enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3068 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3069 | intel_enable_dp(encoder, pipe_config, conn_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3072 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3073 | const struct intel_crtc_state *pipe_config, |
| 3074 | const struct drm_connector_state *conn_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3075 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3076 | intel_dp_prepare(encoder, pipe_config); |
Daniel Vetter | 8ac33ed | 2014-04-24 23:54:54 +0200 | [diff] [blame] | 3077 | |
Ander Conselvan de Oliveira | 6da2e61 | 2016-04-27 15:44:23 +0300 | [diff] [blame] | 3078 | vlv_phy_pre_pll_enable(encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3081 | static void chv_pre_enable_dp(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3082 | const struct intel_crtc_state *pipe_config, |
| 3083 | const struct drm_connector_state *conn_state) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3084 | { |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3085 | chv_phy_pre_encoder_enable(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3086 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 3087 | intel_enable_dp(encoder, pipe_config, conn_state); |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 3088 | |
| 3089 | /* Second common lane will stay alive on its own now */ |
Ander Conselvan de Oliveira | e7d2a717 | 2016-04-27 15:44:20 +0300 | [diff] [blame] | 3090 | chv_phy_release_cl2_override(encoder); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3091 | } |
| 3092 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3093 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3094 | const struct intel_crtc_state *pipe_config, |
| 3095 | const struct drm_connector_state *conn_state) |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3096 | { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 3097 | intel_dp_prepare(encoder, pipe_config); |
Ville Syrjälä | 625695f | 2014-06-28 02:04:02 +0300 | [diff] [blame] | 3098 | |
Ander Conselvan de Oliveira | 419b1b7 | 2016-04-27 15:44:19 +0300 | [diff] [blame] | 3099 | chv_phy_pre_pll_enable(encoder); |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 3100 | } |
| 3101 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 3102 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 3103 | const struct intel_crtc_state *pipe_config, |
| 3104 | const struct drm_connector_state *conn_state) |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3105 | { |
Ander Conselvan de Oliveira | 204970b | 2016-04-27 15:44:21 +0300 | [diff] [blame] | 3106 | chv_phy_post_pll_disable(encoder); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 3107 | } |
| 3108 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3109 | /* |
| 3110 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 3111 | * link status information |
| 3112 | */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3113 | bool |
Keith Packard | 93f62da | 2011-11-01 19:45:03 -0700 | [diff] [blame] | 3114 | 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] | 3115 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3116 | return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status, |
| 3117 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3120 | static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp) |
| 3121 | { |
| 3122 | uint8_t psr_caps = 0; |
| 3123 | |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3124 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1) |
| 3125 | return false; |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3126 | return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED; |
| 3127 | } |
| 3128 | |
| 3129 | static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) |
| 3130 | { |
| 3131 | uint8_t dprx = 0; |
| 3132 | |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3133 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST, |
| 3134 | &dprx) != 1) |
| 3135 | return false; |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3136 | return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED; |
| 3137 | } |
| 3138 | |
Chris Wilson | a76f73d | 2017-01-14 10:51:13 +0000 | [diff] [blame] | 3139 | static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp) |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3140 | { |
| 3141 | uint8_t alpm_caps = 0; |
| 3142 | |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3143 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, |
| 3144 | &alpm_caps) != 1) |
| 3145 | return false; |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3146 | return alpm_caps & DP_ALPM_CAP; |
| 3147 | } |
| 3148 | |
Paulo Zanoni | 1100244 | 2014-06-13 18:45:41 -0300 | [diff] [blame] | 3149 | /* These are source-specific values. */ |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3150 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3151 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3152 | { |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3153 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3154 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3155 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 3156 | if (IS_GEN9_LP(dev_priv)) |
Vandana Kannan | 9314726 | 2014-11-18 15:45:29 +0530 | [diff] [blame] | 3157 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 3158 | else if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | ffe5111 | 2017-02-23 19:49:01 +0200 | [diff] [blame] | 3159 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3160 | return intel_ddi_dp_voltage_max(encoder); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3161 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3162 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3163 | else if (IS_GEN7(dev_priv) && port == PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3164 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3165 | else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3166 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3167 | else |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3168 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3169 | } |
| 3170 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3171 | uint8_t |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3172 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
| 3173 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3174 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3175 | enum port port = dp_to_dig_port(intel_dp)->port; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3176 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3177 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3178 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 3179 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3180 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3181 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3182 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3183 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3184 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 3185 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
| 3186 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Damien Lespiau | 5a9d1f1 | 2013-12-03 13:56:26 +0000 | [diff] [blame] | 3187 | default: |
| 3188 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
| 3189 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3190 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3191 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3192 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3193 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3194 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3195 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3196 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3197 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3198 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3199 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3200 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Paulo Zanoni | d6c0d72 | 2012-10-15 15:51:34 -0300 | [diff] [blame] | 3201 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3202 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3203 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3204 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3205 | return DP_TRAIN_PRE_EMPH_LEVEL_3; |
| 3206 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3207 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3208 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3209 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3210 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3211 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3212 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3213 | } |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3214 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3215 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3216 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3217 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3218 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3219 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3220 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3221 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3222 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3223 | } |
| 3224 | } else { |
| 3225 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3226 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
| 3227 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3228 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
| 3229 | return DP_TRAIN_PRE_EMPH_LEVEL_2; |
| 3230 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
| 3231 | return DP_TRAIN_PRE_EMPH_LEVEL_1; |
| 3232 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3233 | default: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3234 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3235 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3239 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3240 | { |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3241 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3242 | unsigned long demph_reg_value, preemph_reg_value, |
| 3243 | uniqtranscale_reg_value; |
| 3244 | uint8_t train_set = intel_dp->train_set[0]; |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3245 | |
| 3246 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3247 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3248 | preemph_reg_value = 0x0004000; |
| 3249 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3250 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3251 | demph_reg_value = 0x2B405555; |
| 3252 | uniqtranscale_reg_value = 0x552AB83A; |
| 3253 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3254 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3255 | demph_reg_value = 0x2B404040; |
| 3256 | uniqtranscale_reg_value = 0x5548B83A; |
| 3257 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3258 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3259 | demph_reg_value = 0x2B245555; |
| 3260 | uniqtranscale_reg_value = 0x5560B83A; |
| 3261 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3262 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3263 | demph_reg_value = 0x2B405555; |
| 3264 | uniqtranscale_reg_value = 0x5598DA3A; |
| 3265 | break; |
| 3266 | default: |
| 3267 | return 0; |
| 3268 | } |
| 3269 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3270 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3271 | preemph_reg_value = 0x0002000; |
| 3272 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3273 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3274 | demph_reg_value = 0x2B404040; |
| 3275 | uniqtranscale_reg_value = 0x5552B83A; |
| 3276 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3277 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3278 | demph_reg_value = 0x2B404848; |
| 3279 | uniqtranscale_reg_value = 0x5580B83A; |
| 3280 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3281 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3282 | demph_reg_value = 0x2B404040; |
| 3283 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3284 | break; |
| 3285 | default: |
| 3286 | return 0; |
| 3287 | } |
| 3288 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3289 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3290 | preemph_reg_value = 0x0000000; |
| 3291 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3292 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3293 | demph_reg_value = 0x2B305555; |
| 3294 | uniqtranscale_reg_value = 0x5570B83A; |
| 3295 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3296 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3297 | demph_reg_value = 0x2B2B4040; |
| 3298 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3299 | break; |
| 3300 | default: |
| 3301 | return 0; |
| 3302 | } |
| 3303 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3304 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3305 | preemph_reg_value = 0x0006000; |
| 3306 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3307 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3308 | demph_reg_value = 0x1B405555; |
| 3309 | uniqtranscale_reg_value = 0x55ADDA3A; |
| 3310 | break; |
| 3311 | default: |
| 3312 | return 0; |
| 3313 | } |
| 3314 | break; |
| 3315 | default: |
| 3316 | return 0; |
| 3317 | } |
| 3318 | |
Ander Conselvan de Oliveira | 53d9872 | 2016-04-27 15:44:22 +0300 | [diff] [blame] | 3319 | vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value, |
| 3320 | uniqtranscale_reg_value, 0); |
Pallavi G | e2fa6fb | 2013-04-18 14:44:28 -0700 | [diff] [blame] | 3321 | |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3325 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3326 | { |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3327 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 3328 | u32 deemph_reg_value, margin_reg_value; |
| 3329 | bool uniq_trans_scale = false; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3330 | uint8_t train_set = intel_dp->train_set[0]; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3331 | |
| 3332 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3333 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3334 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3335 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3336 | deemph_reg_value = 128; |
| 3337 | margin_reg_value = 52; |
| 3338 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3339 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3340 | deemph_reg_value = 128; |
| 3341 | margin_reg_value = 77; |
| 3342 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3343 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3344 | deemph_reg_value = 128; |
| 3345 | margin_reg_value = 102; |
| 3346 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3347 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3348 | deemph_reg_value = 128; |
| 3349 | margin_reg_value = 154; |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3350 | uniq_trans_scale = true; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3351 | break; |
| 3352 | default: |
| 3353 | return 0; |
| 3354 | } |
| 3355 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3356 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3357 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3358 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3359 | deemph_reg_value = 85; |
| 3360 | margin_reg_value = 78; |
| 3361 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3362 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3363 | deemph_reg_value = 85; |
| 3364 | margin_reg_value = 116; |
| 3365 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3366 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3367 | deemph_reg_value = 85; |
| 3368 | margin_reg_value = 154; |
| 3369 | break; |
| 3370 | default: |
| 3371 | return 0; |
| 3372 | } |
| 3373 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3374 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3375 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3376 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3377 | deemph_reg_value = 64; |
| 3378 | margin_reg_value = 104; |
| 3379 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3380 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3381 | deemph_reg_value = 64; |
| 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_3: |
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 = 43; |
| 3392 | margin_reg_value = 154; |
| 3393 | break; |
| 3394 | default: |
| 3395 | return 0; |
| 3396 | } |
| 3397 | break; |
| 3398 | default: |
| 3399 | return 0; |
| 3400 | } |
| 3401 | |
Ander Conselvan de Oliveira | b7fa22d | 2016-04-27 15:44:17 +0300 | [diff] [blame] | 3402 | chv_set_phy_signal_level(encoder, deemph_reg_value, |
| 3403 | margin_reg_value, uniq_trans_scale); |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 3404 | |
| 3405 | return 0; |
| 3406 | } |
| 3407 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3408 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3409 | gen4_signal_levels(uint8_t train_set) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3410 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3411 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3412 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3413 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3414 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3415 | default: |
| 3416 | signal_levels |= DP_VOLTAGE_0_4; |
| 3417 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3418 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3419 | signal_levels |= DP_VOLTAGE_0_6; |
| 3420 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3421 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3422 | signal_levels |= DP_VOLTAGE_0_8; |
| 3423 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3424 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3425 | signal_levels |= DP_VOLTAGE_1_2; |
| 3426 | break; |
| 3427 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 3428 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3429 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3430 | default: |
| 3431 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 3432 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3433 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3434 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 3435 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3436 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3437 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 3438 | break; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3439 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3440 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 3441 | break; |
| 3442 | } |
| 3443 | return signal_levels; |
| 3444 | } |
| 3445 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3446 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 3447 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3448 | gen6_edp_signal_levels(uint8_t train_set) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3449 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3450 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3451 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3452 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3453 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3454 | 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] | 3455 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3456 | 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] | 3457 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3458 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 3459 | 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] | 3460 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3461 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 3462 | 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] | 3463 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3464 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 3465 | 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] | 3466 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3467 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 3468 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3469 | "0x%x\n", signal_levels); |
| 3470 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3474 | /* Gen7's DP voltage swing and pre-emphasis control */ |
| 3475 | static uint32_t |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3476 | gen7_edp_signal_levels(uint8_t train_set) |
Keith Packard | 1a2eb46 | 2011-11-16 16:26:07 -0800 | [diff] [blame] | 3477 | { |
| 3478 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 3479 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 3480 | switch (signal_levels) { |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3481 | 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] | 3482 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3483 | 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] | 3484 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3485 | 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] | 3486 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
| 3487 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3488 | 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] | 3489 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3490 | 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] | 3491 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
| 3492 | |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3493 | 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] | 3494 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 3495 | 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] | 3496 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
| 3497 | |
| 3498 | default: |
| 3499 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 3500 | "0x%x\n", signal_levels); |
| 3501 | return EDP_LINK_TRAIN_500MV_0DB_IVB; |
| 3502 | } |
| 3503 | } |
| 3504 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3505 | void |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3506 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3507 | { |
| 3508 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3509 | enum port port = intel_dig_port->port; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3510 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3511 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3512 | uint32_t signal_levels, mask = 0; |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3513 | uint8_t train_set = intel_dp->train_set[0]; |
| 3514 | |
Rodrigo Vivi | d509af6 | 2017-08-29 16:22:24 -0700 | [diff] [blame] | 3515 | if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
| 3516 | signal_levels = bxt_signal_levels(intel_dp); |
| 3517 | } else if (HAS_DDI(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 3518 | signal_levels = ddi_signal_levels(intel_dp); |
Rodrigo Vivi | d509af6 | 2017-08-29 16:22:24 -0700 | [diff] [blame] | 3519 | mask = DDI_BUF_EMP_MASK; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3520 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3521 | signal_levels = chv_signal_levels(intel_dp); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 3522 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3523 | signal_levels = vlv_signal_levels(intel_dp); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3524 | } else if (IS_GEN7(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3525 | signal_levels = gen7_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3526 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3527 | } else if (IS_GEN6(dev_priv) && port == PORT_A) { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3528 | signal_levels = gen6_edp_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3529 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
| 3530 | } else { |
Daniel Vetter | 5829975c | 2015-04-16 11:36:52 +0200 | [diff] [blame] | 3531 | signal_levels = gen4_signal_levels(train_set); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3532 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
| 3533 | } |
| 3534 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 3535 | if (mask) |
| 3536 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); |
| 3537 | |
| 3538 | DRM_DEBUG_KMS("Using vswing level %d\n", |
| 3539 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); |
| 3540 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", |
| 3541 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> |
| 3542 | DP_TRAIN_PRE_EMPHASIS_SHIFT); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3543 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3544 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
Ander Conselvan de Oliveira | b905a91 | 2015-10-23 13:01:47 +0300 | [diff] [blame] | 3545 | |
| 3546 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 3547 | POSTING_READ(intel_dp->output_reg); |
Paulo Zanoni | f0a3424 | 2012-12-06 16:51:50 -0200 | [diff] [blame] | 3548 | } |
| 3549 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3550 | void |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3551 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
| 3552 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3553 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 3554 | 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] | 3555 | struct drm_i915_private *dev_priv = |
| 3556 | to_i915(intel_dig_port->base.base.dev); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3557 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3558 | _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] | 3559 | |
Ander Conselvan de Oliveira | f4eb692 | 2015-10-23 13:01:44 +0300 | [diff] [blame] | 3560 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3561 | POSTING_READ(intel_dp->output_reg); |
Ander Conselvan de Oliveira | e9c176d | 2015-10-23 13:01:45 +0300 | [diff] [blame] | 3562 | } |
| 3563 | |
Ander Conselvan de Oliveira | 94223d0 | 2015-10-23 13:01:48 +0300 | [diff] [blame] | 3564 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3565 | { |
| 3566 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 3567 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3568 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3569 | enum port port = intel_dig_port->port; |
| 3570 | uint32_t val; |
| 3571 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3572 | if (!HAS_DDI(dev_priv)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3573 | return; |
| 3574 | |
| 3575 | val = I915_READ(DP_TP_CTL(port)); |
| 3576 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; |
| 3577 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; |
| 3578 | I915_WRITE(DP_TP_CTL(port), val); |
| 3579 | |
| 3580 | /* |
| 3581 | * On PORT_A we can have only eDP in SST mode. There the only reason |
| 3582 | * we need to set idle transmission mode is to work around a HW issue |
| 3583 | * where we enable the pipe while not in idle link-training mode. |
| 3584 | * In this case there is requirement to wait for a minimum number of |
| 3585 | * idle patterns to be sent. |
| 3586 | */ |
| 3587 | if (port == PORT_A) |
| 3588 | return; |
| 3589 | |
Chris Wilson | a767017 | 2016-06-30 15:33:10 +0100 | [diff] [blame] | 3590 | if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port), |
| 3591 | DP_TP_STATUS_IDLE_DONE, |
| 3592 | DP_TP_STATUS_IDLE_DONE, |
| 3593 | 1)) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 3594 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); |
| 3595 | } |
| 3596 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3597 | static void |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3598 | intel_dp_link_down(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3599 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3600 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3601 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
Imre Deak | bc7d38a | 2013-05-16 14:40:36 +0300 | [diff] [blame] | 3602 | enum port port = intel_dig_port->port; |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 3603 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3604 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3605 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3606 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 3607 | if (WARN_ON(HAS_DDI(dev_priv))) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 3608 | return; |
| 3609 | |
Daniel Vetter | 0c33d8d | 2012-09-06 22:15:43 +0200 | [diff] [blame] | 3610 | 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] | 3611 | return; |
| 3612 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3613 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3614 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3615 | if ((IS_GEN7(dev_priv) && port == PORT_A) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3616 | (HAS_PCH_CPT(dev_priv) && port != PORT_A)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3617 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3618 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3619 | } else { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3620 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | aad3d14 | 2014-06-28 02:04:25 +0300 | [diff] [blame] | 3621 | DP &= ~DP_LINK_TRAIN_MASK_CHV; |
| 3622 | else |
| 3623 | DP &= ~DP_LINK_TRAIN_MASK; |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3624 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 3625 | } |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3626 | I915_WRITE(intel_dp->output_reg, DP); |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 3627 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3628 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3629 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
| 3630 | I915_WRITE(intel_dp->output_reg, DP); |
| 3631 | POSTING_READ(intel_dp->output_reg); |
| 3632 | |
| 3633 | /* |
| 3634 | * HW workaround for IBX, we need to move the port |
| 3635 | * to transcoder A after disabling it to allow the |
| 3636 | * matching HDMI port to be enabled on transcoder A. |
| 3637 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3638 | 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] | 3639 | /* |
| 3640 | * We get CPU/PCH FIFO underruns on the other pipe when |
| 3641 | * doing the workaround. Sweep them under the rug. |
| 3642 | */ |
| 3643 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3644 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); |
| 3645 | |
Ville Syrjälä | 1612c8b | 2015-05-05 17:17:34 +0300 | [diff] [blame] | 3646 | /* always enable with pattern 1 (as per spec) */ |
| 3647 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); |
| 3648 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; |
| 3649 | I915_WRITE(intel_dp->output_reg, DP); |
| 3650 | POSTING_READ(intel_dp->output_reg); |
| 3651 | |
| 3652 | DP &= ~DP_PORT_EN; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3653 | I915_WRITE(intel_dp->output_reg, DP); |
Daniel Vetter | 0ca0968 | 2014-11-24 16:54:11 +0100 | [diff] [blame] | 3654 | POSTING_READ(intel_dp->output_reg); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3655 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3656 | intel_wait_for_vblank_if_active(dev_priv, PIPE_A); |
Ville Syrjälä | 0c241d5 | 2015-10-30 19:23:22 +0200 | [diff] [blame] | 3657 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
| 3658 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 3659 | } |
| 3660 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 3661 | msleep(intel_dp->panel_power_down_delay); |
Ville Syrjälä | 6fec766 | 2015-11-10 16:16:17 +0200 | [diff] [blame] | 3662 | |
| 3663 | intel_dp->DP = DP; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 3664 | |
| 3665 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 3666 | pps_lock(intel_dp); |
| 3667 | intel_dp->active_pipe = INVALID_PIPE; |
| 3668 | pps_unlock(intel_dp); |
| 3669 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
Imre Deak | 24e807e | 2016-10-24 19:33:28 +0300 | [diff] [blame] | 3672 | bool |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3673 | intel_dp_read_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3674 | { |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3675 | if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, |
| 3676 | sizeof(intel_dp->dpcd)) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3677 | return false; /* aux transfer failed */ |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3678 | |
Andy Shevchenko | a8e9815 | 2014-09-01 14:12:01 +0300 | [diff] [blame] | 3679 | 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] | 3680 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3681 | return intel_dp->dpcd[DP_DPCD_REV] != 0; |
| 3682 | } |
| 3683 | |
| 3684 | static bool |
| 3685 | intel_edp_init_dpcd(struct intel_dp *intel_dp) |
| 3686 | { |
| 3687 | struct drm_i915_private *dev_priv = |
| 3688 | to_i915(dp_to_dig_port(intel_dp)->base.base.dev); |
| 3689 | |
| 3690 | /* this function is meant to be called only once */ |
| 3691 | WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0); |
| 3692 | |
| 3693 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3694 | return false; |
| 3695 | |
Jani Nikula | 84c3675 | 2017-05-18 14:10:23 +0300 | [diff] [blame] | 3696 | drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, |
| 3697 | drm_dp_is_branch(intel_dp->dpcd)); |
Imre Deak | 12a47a42 | 2016-10-24 19:33:29 +0300 | [diff] [blame] | 3698 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3699 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 3700 | dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
| 3701 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 3702 | |
| 3703 | /* Check if the panel supports PSR */ |
| 3704 | drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT, |
| 3705 | intel_dp->psr_dpcd, |
| 3706 | sizeof(intel_dp->psr_dpcd)); |
| 3707 | if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) { |
| 3708 | dev_priv->psr.sink_support = true; |
| 3709 | DRM_DEBUG_KMS("Detected EDP PSR Panel.\n"); |
| 3710 | } |
| 3711 | |
| 3712 | if (INTEL_GEN(dev_priv) >= 9 && |
| 3713 | (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) { |
| 3714 | uint8_t frame_sync_cap; |
| 3715 | |
| 3716 | dev_priv->psr.sink_support = true; |
Imre Deak | 9bacd4b | 2017-05-10 12:21:48 +0300 | [diff] [blame] | 3717 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3718 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP, |
| 3719 | &frame_sync_cap) != 1) |
| 3720 | frame_sync_cap = 0; |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3721 | dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false; |
| 3722 | /* PSR2 needs frame sync as well */ |
| 3723 | dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync; |
| 3724 | DRM_DEBUG_KMS("PSR2 %s on sink", |
| 3725 | dev_priv->psr.psr2_support ? "supported" : "not supported"); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3726 | |
| 3727 | if (dev_priv->psr.psr2_support) { |
| 3728 | dev_priv->psr.y_cord_support = |
| 3729 | intel_dp_get_y_cord_status(intel_dp); |
| 3730 | dev_priv->psr.colorimetry_support = |
| 3731 | intel_dp_get_colorimetry_status(intel_dp); |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 3732 | dev_priv->psr.alpm = |
| 3733 | intel_dp_get_alpm_status(intel_dp); |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 3734 | } |
| 3735 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | /* Read the eDP Display control capabilities registers */ |
| 3739 | if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) && |
| 3740 | drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, |
Dan Carpenter | f7170e2 | 2016-10-13 11:55:08 +0300 | [diff] [blame] | 3741 | intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == |
| 3742 | sizeof(intel_dp->edp_dpcd)) |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3743 | DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd), |
| 3744 | intel_dp->edp_dpcd); |
| 3745 | |
| 3746 | /* Intermediate frequency support */ |
| 3747 | if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */ |
| 3748 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
| 3749 | int i; |
| 3750 | |
| 3751 | drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES, |
| 3752 | sink_rates, sizeof(sink_rates)); |
| 3753 | |
| 3754 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
| 3755 | int val = le16_to_cpu(sink_rates[i]); |
| 3756 | |
| 3757 | if (val == 0) |
| 3758 | break; |
| 3759 | |
Dhinakaran Pandiyan | fd81c44 | 2016-11-14 13:50:20 -0800 | [diff] [blame] | 3760 | /* Value read multiplied by 200kHz gives the per-lane |
| 3761 | * link rate in kHz. The source rates are, however, |
| 3762 | * stored in terms of LS_Clk kHz. The full conversion |
| 3763 | * back to symbols is |
| 3764 | * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) |
| 3765 | */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3766 | intel_dp->sink_rates[i] = (val * 200) / 10; |
| 3767 | } |
| 3768 | intel_dp->num_sink_rates = i; |
| 3769 | } |
| 3770 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3771 | if (intel_dp->num_sink_rates) |
| 3772 | intel_dp->use_rate_select = true; |
| 3773 | else |
| 3774 | intel_dp_set_sink_rates(intel_dp); |
| 3775 | |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 3776 | intel_dp_set_common_rates(intel_dp); |
| 3777 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3778 | return true; |
| 3779 | } |
| 3780 | |
| 3781 | |
| 3782 | static bool |
| 3783 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
| 3784 | { |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3785 | u8 sink_count; |
| 3786 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 3787 | if (!intel_dp_read_dpcd(intel_dp)) |
| 3788 | return false; |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3789 | |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3790 | /* Don't clobber cached eDP rates. */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3791 | if (!intel_dp_is_edp(intel_dp)) { |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3792 | intel_dp_set_sink_rates(intel_dp); |
Jani Nikula | 975ee5fca | 2017-04-06 16:44:10 +0300 | [diff] [blame] | 3793 | intel_dp_set_common_rates(intel_dp); |
| 3794 | } |
Jani Nikula | 68f357c | 2017-03-28 17:59:05 +0300 | [diff] [blame] | 3795 | |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3796 | 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] | 3797 | return false; |
| 3798 | |
| 3799 | /* |
| 3800 | * Sink count can change between short pulse hpd hence |
| 3801 | * a member variable in intel_dp will track any changes |
| 3802 | * between short pulse interrupts. |
| 3803 | */ |
Jani Nikula | 27dbefb | 2017-04-06 16:44:17 +0300 | [diff] [blame] | 3804 | intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count); |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3805 | |
| 3806 | /* |
| 3807 | * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that |
| 3808 | * a dongle is present but no display. Unless we require to know |
| 3809 | * if a dongle is present or not, we don't need to update |
| 3810 | * downstream port information. So, an early return here saves |
| 3811 | * time from performing other operations which are not required. |
| 3812 | */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 3813 | if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count) |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 3814 | return false; |
| 3815 | |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 3816 | if (!drm_dp_is_branch(intel_dp->dpcd)) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3817 | return true; /* native DP sink */ |
| 3818 | |
| 3819 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) |
| 3820 | return true; /* no per-port downstream info */ |
| 3821 | |
Lyude | 9f085eb | 2016-04-13 10:58:33 -0400 | [diff] [blame] | 3822 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
| 3823 | intel_dp->downstream_ports, |
| 3824 | DP_MAX_DOWNSTREAM_PORTS) < 0) |
Adam Jackson | edb3924 | 2012-09-18 10:58:49 -0400 | [diff] [blame] | 3825 | return false; /* downstream port status fetch failed */ |
| 3826 | |
| 3827 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3830 | static bool |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3831 | intel_dp_can_mst(struct intel_dp *intel_dp) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3832 | { |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3833 | u8 mstm_cap; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3834 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3835 | if (!i915_modparams.enable_dp_mst) |
Nathan Schulte | 7cc9613 | 2016-03-15 10:14:05 -0500 | [diff] [blame] | 3836 | return false; |
| 3837 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3838 | if (!intel_dp->can_mst) |
| 3839 | return false; |
| 3840 | |
| 3841 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) |
| 3842 | return false; |
| 3843 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3844 | 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] | 3845 | return false; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3846 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3847 | return mstm_cap & DP_MST_CAP; |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | static void |
| 3851 | intel_dp_configure_mst(struct intel_dp *intel_dp) |
| 3852 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3853 | if (!i915_modparams.enable_dp_mst) |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 3854 | return; |
| 3855 | |
| 3856 | if (!intel_dp->can_mst) |
| 3857 | return; |
| 3858 | |
| 3859 | intel_dp->is_mst = intel_dp_can_mst(intel_dp); |
| 3860 | |
| 3861 | if (intel_dp->is_mst) |
| 3862 | DRM_DEBUG_KMS("Sink is MST capable\n"); |
| 3863 | else |
| 3864 | DRM_DEBUG_KMS("Sink is not MST capable\n"); |
| 3865 | |
| 3866 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 3867 | intel_dp->is_mst); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3868 | } |
| 3869 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3870 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp) |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3871 | { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3872 | 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] | 3873 | 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] | 3874 | 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] | 3875 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3876 | int ret = 0; |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3877 | int count = 0; |
| 3878 | int attempts = 10; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3879 | |
| 3880 | 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] | 3881 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3882 | ret = -EIO; |
| 3883 | goto out; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3884 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3885 | |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3886 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3887 | buf & ~DP_TEST_SINK_START) < 0) { |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3888 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3889 | ret = -EIO; |
| 3890 | goto out; |
| 3891 | } |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3892 | |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3893 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3894 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | c629784 | 2015-11-05 10:50:20 -0800 | [diff] [blame] | 3895 | |
| 3896 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 3897 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3898 | ret = -EIO; |
| 3899 | goto out; |
| 3900 | } |
| 3901 | count = buf & DP_TEST_COUNT_MASK; |
| 3902 | } while (--attempts && count); |
| 3903 | |
| 3904 | if (attempts == 0) { |
Rodrigo Vivi | dc5a903 | 2016-01-29 14:44:59 -0800 | [diff] [blame] | 3905 | 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] | 3906 | ret = -ETIMEDOUT; |
| 3907 | } |
| 3908 | |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3909 | out: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3910 | hsw_enable_ips(intel_crtc); |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3911 | return ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp) |
| 3915 | { |
| 3916 | 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] | 3917 | 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] | 3918 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3919 | u8 buf; |
Rodrigo Vivi | e5a1cab | 2015-07-23 16:35:48 -0700 | [diff] [blame] | 3920 | int ret; |
| 3921 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3922 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0) |
| 3923 | return -EIO; |
| 3924 | |
| 3925 | if (!(buf & DP_TEST_CRC_SUPPORTED)) |
| 3926 | return -ENOTTY; |
| 3927 | |
| 3928 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) |
| 3929 | return -EIO; |
| 3930 | |
Rodrigo Vivi | 6d8175d | 2015-11-05 10:50:22 -0800 | [diff] [blame] | 3931 | if (buf & DP_TEST_SINK_START) { |
| 3932 | ret = intel_dp_sink_crc_stop(intel_dp); |
| 3933 | if (ret) |
| 3934 | return ret; |
| 3935 | } |
| 3936 | |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3937 | hsw_disable_ips(intel_crtc); |
| 3938 | |
| 3939 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
| 3940 | buf | DP_TEST_SINK_START) < 0) { |
| 3941 | hsw_enable_ips(intel_crtc); |
| 3942 | return -EIO; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3943 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3944 | |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3945 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3946 | return 0; |
| 3947 | } |
| 3948 | |
| 3949 | int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc) |
| 3950 | { |
| 3951 | 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] | 3952 | 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] | 3953 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 3954 | u8 buf; |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3955 | int count, ret; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3956 | int attempts = 6; |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3957 | |
| 3958 | ret = intel_dp_sink_crc_start(intel_dp); |
| 3959 | if (ret) |
| 3960 | return ret; |
| 3961 | |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3962 | do { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 3963 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3964 | |
Rodrigo Vivi | 1dda5f9 | 2014-10-01 07:32:37 -0700 | [diff] [blame] | 3965 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3966 | DP_TEST_SINK_MISC, &buf) < 0) { |
| 3967 | ret = -EIO; |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3968 | goto stop; |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3969 | } |
Rodrigo Vivi | 621d4c7 | 2015-07-23 16:35:49 -0700 | [diff] [blame] | 3970 | count = buf & DP_TEST_COUNT_MASK; |
Rodrigo Vivi | aabc95d | 2015-07-23 16:35:50 -0700 | [diff] [blame] | 3971 | |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3972 | } while (--attempts && count == 0); |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3973 | |
| 3974 | if (attempts == 0) { |
Rodrigo Vivi | 7e38eef | 2015-11-05 10:50:21 -0800 | [diff] [blame] | 3975 | DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n"); |
| 3976 | ret = -ETIMEDOUT; |
| 3977 | goto stop; |
| 3978 | } |
| 3979 | |
| 3980 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) { |
| 3981 | ret = -EIO; |
| 3982 | goto stop; |
Rodrigo Vivi | ad9dc91 | 2014-09-16 19:18:12 -0400 | [diff] [blame] | 3983 | } |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3984 | |
Rodrigo Vivi | afe0d67 | 2015-07-23 16:35:45 -0700 | [diff] [blame] | 3985 | stop: |
Rodrigo Vivi | 082dcc7 | 2015-07-30 16:26:39 -0700 | [diff] [blame] | 3986 | intel_dp_sink_crc_stop(intel_dp); |
Paulo Zanoni | 4373f0f | 2015-05-25 18:52:29 -0300 | [diff] [blame] | 3987 | return ret; |
Rodrigo Vivi | d2e216d | 2014-01-24 13:36:17 -0200 | [diff] [blame] | 3988 | } |
| 3989 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3990 | static bool |
| 3991 | intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3992 | { |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 3993 | return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 3994 | sink_irq_vector) == 1; |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 3997 | static bool |
| 3998 | intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector) |
| 3999 | { |
Pandiyan, Dhinakaran | e8b2577 | 2017-09-18 15:21:39 -0700 | [diff] [blame] | 4000 | return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI, |
| 4001 | sink_irq_vector, DP_DPRX_ESI_LEN) == |
| 4002 | DP_DPRX_ESI_LEN; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4003 | } |
| 4004 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4005 | 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] | 4006 | { |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4007 | int status = 0; |
Manasi Navare | 140ef13 | 2017-06-08 13:41:03 -0700 | [diff] [blame] | 4008 | int test_link_rate; |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4009 | uint8_t test_lane_count, test_link_bw; |
| 4010 | /* (DP CTS 1.2) |
| 4011 | * 4.3.1.11 |
| 4012 | */ |
| 4013 | /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */ |
| 4014 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT, |
| 4015 | &test_lane_count); |
| 4016 | |
| 4017 | if (status <= 0) { |
| 4018 | DRM_DEBUG_KMS("Lane count read failed\n"); |
| 4019 | return DP_TEST_NAK; |
| 4020 | } |
| 4021 | test_lane_count &= DP_MAX_LANE_COUNT_MASK; |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4022 | |
| 4023 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE, |
| 4024 | &test_link_bw); |
| 4025 | if (status <= 0) { |
| 4026 | DRM_DEBUG_KMS("Link Rate read failed\n"); |
| 4027 | return DP_TEST_NAK; |
| 4028 | } |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4029 | 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] | 4030 | |
| 4031 | /* Validate the requested link rate and lane count */ |
| 4032 | if (!intel_dp_link_params_valid(intel_dp, test_link_rate, |
| 4033 | test_lane_count)) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4034 | return DP_TEST_NAK; |
| 4035 | |
| 4036 | intel_dp->compliance.test_lane_count = test_lane_count; |
| 4037 | intel_dp->compliance.test_link_rate = test_link_rate; |
| 4038 | |
| 4039 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp) |
| 4043 | { |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4044 | uint8_t test_pattern; |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4045 | uint8_t test_misc; |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4046 | __be16 h_width, v_height; |
| 4047 | int status = 0; |
| 4048 | |
| 4049 | /* Read the TEST_PATTERN (DP CTS 3.1.5) */ |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4050 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN, |
| 4051 | &test_pattern); |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4052 | if (status <= 0) { |
| 4053 | DRM_DEBUG_KMS("Test pattern read failed\n"); |
| 4054 | return DP_TEST_NAK; |
| 4055 | } |
| 4056 | if (test_pattern != DP_COLOR_RAMP) |
| 4057 | return DP_TEST_NAK; |
| 4058 | |
| 4059 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI, |
| 4060 | &h_width, 2); |
| 4061 | if (status <= 0) { |
| 4062 | DRM_DEBUG_KMS("H Width read failed\n"); |
| 4063 | return DP_TEST_NAK; |
| 4064 | } |
| 4065 | |
| 4066 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI, |
| 4067 | &v_height, 2); |
| 4068 | if (status <= 0) { |
| 4069 | DRM_DEBUG_KMS("V Height read failed\n"); |
| 4070 | return DP_TEST_NAK; |
| 4071 | } |
| 4072 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4073 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0, |
| 4074 | &test_misc); |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 4075 | if (status <= 0) { |
| 4076 | DRM_DEBUG_KMS("TEST MISC read failed\n"); |
| 4077 | return DP_TEST_NAK; |
| 4078 | } |
| 4079 | if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB) |
| 4080 | return DP_TEST_NAK; |
| 4081 | if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA) |
| 4082 | return DP_TEST_NAK; |
| 4083 | switch (test_misc & DP_TEST_BIT_DEPTH_MASK) { |
| 4084 | case DP_TEST_BIT_DEPTH_6: |
| 4085 | intel_dp->compliance.test_data.bpc = 6; |
| 4086 | break; |
| 4087 | case DP_TEST_BIT_DEPTH_8: |
| 4088 | intel_dp->compliance.test_data.bpc = 8; |
| 4089 | break; |
| 4090 | default: |
| 4091 | return DP_TEST_NAK; |
| 4092 | } |
| 4093 | |
| 4094 | intel_dp->compliance.test_data.video_pattern = test_pattern; |
| 4095 | intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width); |
| 4096 | intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height); |
| 4097 | /* Set test active flag here so userspace doesn't interrupt things */ |
| 4098 | intel_dp->compliance.test_active = 1; |
| 4099 | |
| 4100 | return DP_TEST_ACK; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp) |
| 4104 | { |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4105 | uint8_t test_result = DP_TEST_ACK; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4106 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4107 | struct drm_connector *connector = &intel_connector->base; |
| 4108 | |
| 4109 | if (intel_connector->detect_edid == NULL || |
Daniel Vetter | ac6f2e2 | 2015-05-08 16:15:41 +0200 | [diff] [blame] | 4110 | connector->edid_corrupt || |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4111 | intel_dp->aux.i2c_defer_count > 6) { |
| 4112 | /* Check EDID read for NACKs, DEFERs and corruption |
| 4113 | * (DP CTS 1.2 Core r1.1) |
| 4114 | * 4.2.2.4 : Failed EDID read, I2C_NAK |
| 4115 | * 4.2.2.5 : Failed EDID read, I2C_DEFER |
| 4116 | * 4.2.2.6 : EDID corruption detected |
| 4117 | * Use failsafe mode for all cases |
| 4118 | */ |
| 4119 | if (intel_dp->aux.i2c_nack_count > 0 || |
| 4120 | intel_dp->aux.i2c_defer_count > 0) |
| 4121 | DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n", |
| 4122 | intel_dp->aux.i2c_nack_count, |
| 4123 | intel_dp->aux.i2c_defer_count); |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4124 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4125 | } else { |
Thulasimani,Sivakumar | f79b468e | 2015-08-07 15:14:30 +0530 | [diff] [blame] | 4126 | struct edid *block = intel_connector->detect_edid; |
| 4127 | |
| 4128 | /* We have to write the checksum |
| 4129 | * of the last block read |
| 4130 | */ |
| 4131 | block += intel_connector->detect_edid->extensions; |
| 4132 | |
Jani Nikula | 010b9b3 | 2017-04-06 16:44:16 +0300 | [diff] [blame] | 4133 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM, |
| 4134 | block->checksum) <= 0) |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4135 | DRM_DEBUG_KMS("Failed to write EDID checksum\n"); |
| 4136 | |
| 4137 | test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE; |
Manasi Navare | b48a5ba | 2017-01-20 19:09:28 -0800 | [diff] [blame] | 4138 | intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | /* Set test active flag here so userspace doesn't interrupt things */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4142 | intel_dp->compliance.test_active = 1; |
Todd Previte | 559be30 | 2015-05-04 07:48:20 -0700 | [diff] [blame] | 4143 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4144 | return test_result; |
| 4145 | } |
| 4146 | |
| 4147 | static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp) |
| 4148 | { |
| 4149 | uint8_t test_result = DP_TEST_NAK; |
| 4150 | return test_result; |
| 4151 | } |
| 4152 | |
| 4153 | static void intel_dp_handle_test_request(struct intel_dp *intel_dp) |
| 4154 | { |
| 4155 | uint8_t response = DP_TEST_NAK; |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4156 | uint8_t request = 0; |
| 4157 | int status; |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4158 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4159 | status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4160 | if (status <= 0) { |
| 4161 | DRM_DEBUG_KMS("Could not read test request from sink\n"); |
| 4162 | goto update_status; |
| 4163 | } |
| 4164 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4165 | switch (request) { |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4166 | case DP_TEST_LINK_TRAINING: |
| 4167 | DRM_DEBUG_KMS("LINK_TRAINING test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4168 | response = intel_dp_autotest_link_training(intel_dp); |
| 4169 | break; |
| 4170 | case DP_TEST_LINK_VIDEO_PATTERN: |
| 4171 | DRM_DEBUG_KMS("TEST_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4172 | response = intel_dp_autotest_video_pattern(intel_dp); |
| 4173 | break; |
| 4174 | case DP_TEST_LINK_EDID_READ: |
| 4175 | DRM_DEBUG_KMS("EDID test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4176 | response = intel_dp_autotest_edid(intel_dp); |
| 4177 | break; |
| 4178 | case DP_TEST_LINK_PHY_TEST_PATTERN: |
| 4179 | DRM_DEBUG_KMS("PHY_PATTERN test requested\n"); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4180 | response = intel_dp_autotest_phy_pattern(intel_dp); |
| 4181 | break; |
| 4182 | default: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4183 | DRM_DEBUG_KMS("Invalid test request '%02x'\n", request); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4184 | break; |
| 4185 | } |
| 4186 | |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4187 | if (response & DP_TEST_ACK) |
| 4188 | intel_dp->compliance.test_type = request; |
| 4189 | |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4190 | update_status: |
Jani Nikula | 5ec63bb | 2017-01-20 19:04:06 +0200 | [diff] [blame] | 4191 | status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response); |
Todd Previte | c5d5ab7 | 2015-04-15 08:38:38 -0700 | [diff] [blame] | 4192 | if (status <= 0) |
| 4193 | DRM_DEBUG_KMS("Could not write test response to sink\n"); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4196 | static int |
| 4197 | intel_dp_check_mst_status(struct intel_dp *intel_dp) |
| 4198 | { |
| 4199 | bool bret; |
| 4200 | |
| 4201 | if (intel_dp->is_mst) { |
Pandiyan, Dhinakaran | e8b2577 | 2017-09-18 15:21:39 -0700 | [diff] [blame] | 4202 | u8 esi[DP_DPRX_ESI_LEN] = { 0 }; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4203 | int ret = 0; |
| 4204 | int retry; |
| 4205 | bool handled; |
| 4206 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4207 | go_again: |
| 4208 | if (bret == true) { |
| 4209 | |
| 4210 | /* check link status - esi[10] = 0x200c */ |
Ville Syrjälä | 19e0b4c | 2016-08-05 19:05:42 +0300 | [diff] [blame] | 4211 | if (intel_dp->active_mst_links && |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 4212 | !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4213 | DRM_DEBUG_KMS("channel EQ not ok, retraining\n"); |
| 4214 | intel_dp_start_link_train(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4215 | intel_dp_stop_link_train(intel_dp); |
| 4216 | } |
| 4217 | |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4218 | DRM_DEBUG_KMS("got esi %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4219 | ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); |
| 4220 | |
| 4221 | if (handled) { |
| 4222 | for (retry = 0; retry < 3; retry++) { |
| 4223 | int wret; |
| 4224 | wret = drm_dp_dpcd_write(&intel_dp->aux, |
| 4225 | DP_SINK_COUNT_ESI+1, |
| 4226 | &esi[1], 3); |
| 4227 | if (wret == 3) { |
| 4228 | break; |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); |
| 4233 | if (bret == true) { |
Andy Shevchenko | 6f34cc3 | 2015-01-15 13:45:09 +0200 | [diff] [blame] | 4234 | DRM_DEBUG_KMS("got esi2 %3ph\n", esi); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4235 | goto go_again; |
| 4236 | } |
| 4237 | } else |
| 4238 | ret = 0; |
| 4239 | |
| 4240 | return ret; |
| 4241 | } else { |
| 4242 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4243 | DRM_DEBUG_KMS("failed to get ESI - device may have failed\n"); |
| 4244 | intel_dp->is_mst = false; |
| 4245 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); |
| 4246 | /* send a hotplug event */ |
| 4247 | drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev); |
| 4248 | } |
| 4249 | } |
| 4250 | return -EINVAL; |
| 4251 | } |
| 4252 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4253 | static void |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4254 | intel_dp_retrain_link(struct intel_dp *intel_dp) |
| 4255 | { |
| 4256 | struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; |
| 4257 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 4258 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 4259 | |
| 4260 | /* Suppress underruns caused by re-training */ |
| 4261 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
| 4262 | if (crtc->config->has_pch_encoder) |
| 4263 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4264 | intel_crtc_pch_transcoder(crtc), false); |
| 4265 | |
| 4266 | intel_dp_start_link_train(intel_dp); |
| 4267 | intel_dp_stop_link_train(intel_dp); |
| 4268 | |
| 4269 | /* Keep underrun reporting disabled until things are stable */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4270 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4271 | |
| 4272 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 4273 | if (crtc->config->has_pch_encoder) |
| 4274 | intel_set_pch_fifo_underrun_reporting(dev_priv, |
| 4275 | intel_crtc_pch_transcoder(crtc), true); |
| 4276 | } |
| 4277 | |
| 4278 | static void |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4279 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
| 4280 | { |
| 4281 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
| 4282 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
| 4283 | u8 link_status[DP_LINK_STATUS_SIZE]; |
| 4284 | |
| 4285 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 4286 | |
| 4287 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
| 4288 | DRM_ERROR("Failed to get link status\n"); |
| 4289 | return; |
| 4290 | } |
| 4291 | |
| 4292 | if (!intel_encoder->base.crtc) |
| 4293 | return; |
| 4294 | |
| 4295 | if (!to_intel_crtc(intel_encoder->base.crtc)->active) |
| 4296 | return; |
| 4297 | |
Manasi Navare | 14c562c | 2017-04-06 14:00:12 -0700 | [diff] [blame] | 4298 | /* |
| 4299 | * Validate the cached values of intel_dp->link_rate and |
| 4300 | * intel_dp->lane_count before attempting to retrain. |
| 4301 | */ |
Manasi Navare | 1a92c70 | 2017-06-08 13:41:02 -0700 | [diff] [blame] | 4302 | if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate, |
| 4303 | intel_dp->lane_count)) |
Matthew Auld | d4cb3fd | 2016-10-19 22:29:53 +0100 | [diff] [blame] | 4304 | return; |
| 4305 | |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4306 | /* Retrain if Channel EQ or CR not ok */ |
| 4307 | if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) { |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4308 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
| 4309 | intel_encoder->base.name); |
Ville Syrjälä | bfd02b3 | 2016-10-14 20:02:54 +0300 | [diff] [blame] | 4310 | |
| 4311 | intel_dp_retrain_link(intel_dp); |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4312 | } |
| 4313 | } |
| 4314 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4315 | /* |
| 4316 | * According to DP spec |
| 4317 | * 5.1.2: |
| 4318 | * 1. Read DPCD |
| 4319 | * 2. Configure link according to Receiver Capabilities |
| 4320 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 4321 | * 4. Check link status on receipt of hot-plug interrupt |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4322 | * |
| 4323 | * intel_dp_short_pulse - handles short pulse interrupts |
| 4324 | * when full detection is not required. |
| 4325 | * Returns %true if short pulse is handled and full detection |
| 4326 | * is NOT required and %false otherwise. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4327 | */ |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4328 | static bool |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4329 | intel_dp_short_pulse(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4330 | { |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4331 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4332 | 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] | 4333 | u8 sink_irq_vector = 0; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4334 | u8 old_sink_count = intel_dp->sink_count; |
| 4335 | bool ret; |
Dave Airlie | 5b215bc | 2014-08-05 10:40:20 +1000 | [diff] [blame] | 4336 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4337 | /* |
| 4338 | * Clearing compliance test variables to allow capturing |
| 4339 | * of values for next automated test request. |
| 4340 | */ |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4341 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4342 | |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4343 | /* |
| 4344 | * Now read the DPCD to see if it's actually running |
| 4345 | * If the current value of sink count doesn't match with |
| 4346 | * the value that was stored earlier or dpcd read failed |
| 4347 | * we need to do full detection |
| 4348 | */ |
| 4349 | ret = intel_dp_get_dpcd(intel_dp); |
| 4350 | |
| 4351 | if ((old_sink_count != intel_dp->sink_count) || !ret) { |
| 4352 | /* No need to proceed if we are going to do full detect */ |
| 4353 | return false; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4356 | /* Try to read the source of the interrupt */ |
| 4357 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4358 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4359 | sink_irq_vector != 0) { |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4360 | /* Clear interrupt source */ |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4361 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4362 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4363 | sink_irq_vector); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4364 | |
| 4365 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4366 | intel_dp_handle_test_request(intel_dp); |
Jesse Barnes | a60f0e3 | 2011-10-20 15:09:17 -0700 | [diff] [blame] | 4367 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4368 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4369 | } |
| 4370 | |
Shubhangi Shrivastava | 5c9114d | 2016-03-30 18:05:24 +0530 | [diff] [blame] | 4371 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 4372 | intel_dp_check_link_status(intel_dp); |
| 4373 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Manasi Navare | da15f7c | 2017-01-24 08:16:34 -0800 | [diff] [blame] | 4374 | if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) { |
| 4375 | DRM_DEBUG_KMS("Link Training Compliance Test requested\n"); |
| 4376 | /* Send a Hotplug Uevent to userspace to start modeset */ |
| 4377 | drm_kms_helper_hotplug_event(intel_encoder->base.dev); |
| 4378 | } |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 4379 | |
| 4380 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4381 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4382 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4383 | /* XXX this is probably wrong for multiple downstream ports */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4384 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4385 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4386 | { |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4387 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4388 | uint8_t *dpcd = intel_dp->dpcd; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4389 | uint8_t type; |
| 4390 | |
Imre Deak | e393d0d | 2017-02-22 17:10:52 +0200 | [diff] [blame] | 4391 | if (lspcon->active) |
| 4392 | lspcon_resume(lspcon); |
| 4393 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4394 | if (!intel_dp_get_dpcd(intel_dp)) |
| 4395 | return connector_status_disconnected; |
| 4396 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4397 | if (intel_dp_is_edp(intel_dp)) |
Shubhangi Shrivastava | 1034ce7 | 2016-04-12 12:23:54 +0530 | [diff] [blame] | 4398 | return connector_status_connected; |
| 4399 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4400 | /* if there's no downstream port, we're done */ |
Imre Deak | c726ad0 | 2016-10-24 19:33:24 +0300 | [diff] [blame] | 4401 | if (!drm_dp_is_branch(dpcd)) |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4402 | return connector_status_connected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4403 | |
| 4404 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4405 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 4406 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { |
Jani Nikula | 9d1a103 | 2014-03-14 16:51:15 +0200 | [diff] [blame] | 4407 | |
Shubhangi Shrivastava | 30d9aa4 | 2016-03-30 18:05:25 +0530 | [diff] [blame] | 4408 | return intel_dp->sink_count ? |
| 4409 | connector_status_connected : connector_status_disconnected; |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4410 | } |
| 4411 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4412 | if (intel_dp_can_mst(intel_dp)) |
| 4413 | return connector_status_connected; |
| 4414 | |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4415 | /* If no HPD, poke DDC gently */ |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 4416 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4417 | return connector_status_connected; |
| 4418 | |
| 4419 | /* Well we tried, say unknown for unreliable port types */ |
Jani Nikula | c9ff160 | 2013-09-27 14:48:42 +0300 | [diff] [blame] | 4420 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 4421 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; |
| 4422 | if (type == DP_DS_PORT_TYPE_VGA || |
| 4423 | type == DP_DS_PORT_TYPE_NON_EDID) |
| 4424 | return connector_status_unknown; |
| 4425 | } else { |
| 4426 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
| 4427 | DP_DWN_STRM_PORT_TYPE_MASK; |
| 4428 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || |
| 4429 | type == DP_DWN_STRM_PORT_TYPE_OTHER) |
| 4430 | return connector_status_unknown; |
| 4431 | } |
Adam Jackson | caf9ab2 | 2012-09-18 10:58:50 -0400 | [diff] [blame] | 4432 | |
| 4433 | /* Anything else is out of spec, warn and ignore */ |
| 4434 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 4435 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | static enum drm_connector_status |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4439 | edp_detect(struct intel_dp *intel_dp) |
| 4440 | { |
| 4441 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4442 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4443 | enum drm_connector_status status; |
| 4444 | |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 4445 | status = intel_panel_detect(dev_priv); |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4446 | if (status == connector_status_unknown) |
| 4447 | status = connector_status_connected; |
| 4448 | |
| 4449 | return status; |
| 4450 | } |
| 4451 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4452 | static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4453 | struct intel_digital_port *port) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4454 | { |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4455 | u32 bit; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 4456 | |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4457 | switch (port->port) { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4458 | case PORT_B: |
| 4459 | bit = SDE_PORTB_HOTPLUG; |
| 4460 | break; |
| 4461 | case PORT_C: |
| 4462 | bit = SDE_PORTC_HOTPLUG; |
| 4463 | break; |
| 4464 | case PORT_D: |
| 4465 | bit = SDE_PORTD_HOTPLUG; |
| 4466 | break; |
| 4467 | default: |
| 4468 | MISSING_CASE(port->port); |
| 4469 | return false; |
| 4470 | } |
| 4471 | |
| 4472 | return I915_READ(SDEISR) & bit; |
| 4473 | } |
| 4474 | |
| 4475 | static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4476 | struct intel_digital_port *port) |
| 4477 | { |
| 4478 | u32 bit; |
| 4479 | |
| 4480 | switch (port->port) { |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4481 | case PORT_B: |
| 4482 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 4483 | break; |
| 4484 | case PORT_C: |
| 4485 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 4486 | break; |
| 4487 | case PORT_D: |
| 4488 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 4489 | break; |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4490 | default: |
| 4491 | MISSING_CASE(port->port); |
| 4492 | return false; |
| 4493 | } |
| 4494 | |
| 4495 | return I915_READ(SDEISR) & bit; |
| 4496 | } |
| 4497 | |
| 4498 | static bool spt_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4499 | struct intel_digital_port *port) |
| 4500 | { |
| 4501 | u32 bit; |
| 4502 | |
| 4503 | switch (port->port) { |
| 4504 | case PORT_A: |
| 4505 | bit = SDE_PORTA_HOTPLUG_SPT; |
| 4506 | break; |
Jani Nikula | a78695d | 2015-09-18 15:54:50 +0300 | [diff] [blame] | 4507 | case PORT_E: |
| 4508 | bit = SDE_PORTE_HOTPLUG_SPT; |
| 4509 | break; |
Jani Nikula | 0df53b7 | 2015-08-20 10:47:40 +0300 | [diff] [blame] | 4510 | default: |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4511 | return cpt_digital_port_connected(dev_priv, port); |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4512 | } |
Damien Lespiau | 1b46963 | 2012-12-13 16:09:01 +0000 | [diff] [blame] | 4513 | |
Jani Nikula | b93433c | 2015-08-20 10:47:36 +0300 | [diff] [blame] | 4514 | return I915_READ(SDEISR) & bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4515 | } |
| 4516 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4517 | static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv, |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4518 | struct intel_digital_port *port) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4519 | { |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4520 | u32 bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4521 | |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4522 | switch (port->port) { |
| 4523 | case PORT_B: |
| 4524 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; |
| 4525 | break; |
| 4526 | case PORT_C: |
| 4527 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; |
| 4528 | break; |
| 4529 | case PORT_D: |
| 4530 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; |
| 4531 | break; |
| 4532 | default: |
| 4533 | MISSING_CASE(port->port); |
| 4534 | return false; |
| 4535 | } |
| 4536 | |
| 4537 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 4538 | } |
| 4539 | |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4540 | static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4541 | struct intel_digital_port *port) |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4542 | { |
| 4543 | u32 bit; |
| 4544 | |
| 4545 | switch (port->port) { |
| 4546 | case PORT_B: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4547 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4548 | break; |
| 4549 | case PORT_C: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4550 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4551 | break; |
| 4552 | case PORT_D: |
Ville Syrjälä | 0780cd3 | 2016-02-10 19:59:05 +0200 | [diff] [blame] | 4553 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
Jani Nikula | 9642c81 | 2015-08-20 10:47:41 +0300 | [diff] [blame] | 4554 | break; |
| 4555 | default: |
| 4556 | MISSING_CASE(port->port); |
| 4557 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
Jani Nikula | 1d24598 | 2015-08-20 10:47:37 +0300 | [diff] [blame] | 4560 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
Dave Airlie | 2a592be | 2014-09-01 16:58:12 +1000 | [diff] [blame] | 4561 | } |
| 4562 | |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4563 | static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4564 | struct intel_digital_port *port) |
| 4565 | { |
| 4566 | if (port->port == PORT_A) |
| 4567 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG; |
| 4568 | else |
| 4569 | return ibx_digital_port_connected(dev_priv, port); |
| 4570 | } |
| 4571 | |
| 4572 | static bool snb_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4573 | struct intel_digital_port *port) |
| 4574 | { |
| 4575 | if (port->port == PORT_A) |
| 4576 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG; |
| 4577 | else |
| 4578 | return cpt_digital_port_connected(dev_priv, port); |
| 4579 | } |
| 4580 | |
| 4581 | static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4582 | struct intel_digital_port *port) |
| 4583 | { |
| 4584 | if (port->port == PORT_A) |
| 4585 | return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB; |
| 4586 | else |
| 4587 | return cpt_digital_port_connected(dev_priv, port); |
| 4588 | } |
| 4589 | |
| 4590 | static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4591 | struct intel_digital_port *port) |
| 4592 | { |
| 4593 | if (port->port == PORT_A) |
| 4594 | return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG; |
| 4595 | else |
| 4596 | return cpt_digital_port_connected(dev_priv, port); |
| 4597 | } |
| 4598 | |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4599 | static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv, |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4600 | struct intel_digital_port *intel_dig_port) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4601 | { |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4602 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 4603 | enum port port; |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4604 | u32 bit; |
| 4605 | |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 4606 | port = intel_hpd_pin_to_port(intel_encoder->hpd_pin); |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4607 | switch (port) { |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4608 | case PORT_A: |
| 4609 | bit = BXT_DE_PORT_HP_DDIA; |
| 4610 | break; |
| 4611 | case PORT_B: |
| 4612 | bit = BXT_DE_PORT_HP_DDIB; |
| 4613 | break; |
| 4614 | case PORT_C: |
| 4615 | bit = BXT_DE_PORT_HP_DDIC; |
| 4616 | break; |
| 4617 | default: |
Sonika Jindal | e2ec35a | 2015-09-11 16:58:32 +0530 | [diff] [blame] | 4618 | MISSING_CASE(port); |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4619 | return false; |
| 4620 | } |
| 4621 | |
| 4622 | return I915_READ(GEN8_DE_PORT_ISR) & bit; |
| 4623 | } |
| 4624 | |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4625 | /* |
| 4626 | * intel_digital_port_connected - is the specified port connected? |
| 4627 | * @dev_priv: i915 private structure |
| 4628 | * @port: the port to test |
| 4629 | * |
| 4630 | * Return %true if @port is connected, %false otherwise. |
| 4631 | */ |
Imre Deak | 390b4e0 | 2017-01-27 11:39:19 +0200 | [diff] [blame] | 4632 | bool intel_digital_port_connected(struct drm_i915_private *dev_priv, |
| 4633 | struct intel_digital_port *port) |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4634 | { |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4635 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 4636 | if (IS_GM45(dev_priv)) |
| 4637 | return gm45_digital_port_connected(dev_priv, port); |
| 4638 | else |
| 4639 | return g4x_digital_port_connected(dev_priv, port); |
| 4640 | } |
| 4641 | |
| 4642 | if (IS_GEN5(dev_priv)) |
| 4643 | return ilk_digital_port_connected(dev_priv, port); |
| 4644 | else if (IS_GEN6(dev_priv)) |
| 4645 | return snb_digital_port_connected(dev_priv, port); |
| 4646 | else if (IS_GEN7(dev_priv)) |
| 4647 | return ivb_digital_port_connected(dev_priv, port); |
| 4648 | else if (IS_GEN8(dev_priv)) |
| 4649 | return bdw_digital_port_connected(dev_priv, port); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 4650 | else if (IS_GEN9_LP(dev_priv)) |
Jani Nikula | e464bfd | 2015-08-20 10:47:42 +0300 | [diff] [blame] | 4651 | return bxt_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4652 | else |
Ville Syrjälä | 93e5f0b | 2017-06-15 20:12:52 +0300 | [diff] [blame] | 4653 | return spt_digital_port_connected(dev_priv, port); |
Jani Nikula | 7e66bcf | 2015-08-20 10:47:39 +0300 | [diff] [blame] | 4654 | } |
| 4655 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4656 | static struct edid * |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4657 | intel_dp_get_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4658 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4659 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4660 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4661 | /* use cached edid if we have one */ |
| 4662 | if (intel_connector->edid) { |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4663 | /* invalid edid */ |
| 4664 | if (IS_ERR(intel_connector->edid)) |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4665 | return NULL; |
| 4666 | |
Jani Nikula | 55e9ede | 2013-10-01 10:38:54 +0300 | [diff] [blame] | 4667 | return drm_edid_duplicate(intel_connector->edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4668 | } else |
| 4669 | return drm_get_edid(&intel_connector->base, |
| 4670 | &intel_dp->aux.ddc); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4671 | } |
| 4672 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4673 | static void |
| 4674 | intel_dp_set_edid(struct intel_dp *intel_dp) |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4675 | { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4676 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4677 | struct edid *edid; |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 4678 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4679 | intel_dp_unset_edid(intel_dp); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4680 | edid = intel_dp_get_edid(intel_dp); |
| 4681 | intel_connector->detect_edid = edid; |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4682 | |
Maarten Lankhorst | e6b72c9 | 2017-05-01 15:38:00 +0200 | [diff] [blame] | 4683 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4684 | } |
Jesse Barnes | d6f24d0 | 2012-06-14 15:28:33 -0400 | [diff] [blame] | 4685 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4686 | static void |
| 4687 | intel_dp_unset_edid(struct intel_dp *intel_dp) |
| 4688 | { |
| 4689 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
| 4690 | |
| 4691 | kfree(intel_connector->detect_edid); |
| 4692 | intel_connector->detect_edid = NULL; |
| 4693 | |
| 4694 | intel_dp->has_audio = false; |
| 4695 | } |
| 4696 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4697 | static int |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4698 | intel_dp_long_pulse(struct intel_connector *intel_connector) |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4699 | { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4700 | struct drm_connector *connector = &intel_connector->base; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4701 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Paulo Zanoni | d63885d | 2012-10-26 19:05:49 -0200 | [diff] [blame] | 4702 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4703 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Paulo Zanoni | fa90ece | 2012-10-26 19:05:44 -0200 | [diff] [blame] | 4704 | struct drm_device *dev = connector->dev; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4705 | enum drm_connector_status status; |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4706 | u8 sink_irq_vector = 0; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4707 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4708 | WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex)); |
| 4709 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4710 | intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4711 | |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4712 | /* Can't disconnect eDP, but you can close the lid... */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4713 | if (intel_dp_is_edp(intel_dp)) |
Chris Wilson | d410b56 | 2014-09-02 20:03:59 +0100 | [diff] [blame] | 4714 | status = edp_detect(intel_dp); |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4715 | else if (intel_digital_port_connected(to_i915(dev), |
| 4716 | dp_to_dig_port(intel_dp))) |
| 4717 | status = intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4718 | else |
Ander Conselvan de Oliveira | c555a81 | 2015-11-18 17:19:30 +0200 | [diff] [blame] | 4719 | status = connector_status_disconnected; |
| 4720 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4721 | if (status == connector_status_disconnected) { |
Manasi Navare | c1617ab | 2016-12-09 16:22:50 -0800 | [diff] [blame] | 4722 | memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance)); |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4723 | |
jim.bride@linux.intel.com | 0e505a0 | 2016-04-11 10:11:24 -0700 | [diff] [blame] | 4724 | if (intel_dp->is_mst) { |
| 4725 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 4726 | intel_dp->is_mst, |
| 4727 | intel_dp->mst_mgr.mst_state); |
| 4728 | intel_dp->is_mst = false; |
| 4729 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 4730 | intel_dp->is_mst); |
| 4731 | } |
| 4732 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4733 | goto out; |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4734 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 4735 | |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4736 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4737 | intel_encoder->type = INTEL_OUTPUT_DP; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4738 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4739 | if (intel_dp->reset_link_params) { |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 4740 | /* Initial max link lane count */ |
| 4741 | 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] | 4742 | |
Jani Nikula | 540b0b7f | 2017-04-06 16:44:13 +0300 | [diff] [blame] | 4743 | /* Initial max link rate */ |
| 4744 | intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp); |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 4745 | |
| 4746 | intel_dp->reset_link_params = false; |
| 4747 | } |
Manasi Navare | f482984 | 2016-12-05 16:27:36 -0800 | [diff] [blame] | 4748 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 4749 | intel_dp_print_rates(intel_dp); |
| 4750 | |
Jani Nikula | 84c3675 | 2017-05-18 14:10:23 +0300 | [diff] [blame] | 4751 | drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, |
| 4752 | drm_dp_is_branch(intel_dp->dpcd)); |
Mika Kahola | 0e390a3 | 2016-09-09 14:10:53 +0300 | [diff] [blame] | 4753 | |
Ville Syrjälä | c4e3170 | 2016-07-29 16:51:16 +0300 | [diff] [blame] | 4754 | intel_dp_configure_mst(intel_dp); |
| 4755 | |
| 4756 | if (intel_dp->is_mst) { |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4757 | /* |
| 4758 | * If we are in MST mode then this connector |
| 4759 | * won't appear connected or have anything |
| 4760 | * with EDID on it |
| 4761 | */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4762 | status = connector_status_disconnected; |
| 4763 | goto out; |
Ville Syrjälä | 1a36147 | 2017-04-12 22:30:17 +0300 | [diff] [blame] | 4764 | } else { |
| 4765 | /* |
| 4766 | * If display is now connected check links status, |
| 4767 | * there has been known issues of link loss triggerring |
| 4768 | * long pulse. |
| 4769 | * |
| 4770 | * Some sinks (eg. ASUS PB287Q) seem to perform some |
| 4771 | * weird HPD ping pong during modesets. So we can apparently |
| 4772 | * end up with HPD going low during a modeset, and then |
| 4773 | * going back up soon after. And once that happens we must |
| 4774 | * retrain the link to get a picture. That's in case no |
| 4775 | * userspace component reacted to intermittent HPD dip. |
| 4776 | */ |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4777 | intel_dp_check_link_status(intel_dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4778 | } |
| 4779 | |
Shubhangi Shrivastava | 4df6960 | 2015-10-28 15:30:36 +0530 | [diff] [blame] | 4780 | /* |
| 4781 | * Clearing NACK and defer counts to get their exact values |
| 4782 | * while reading EDID which are required by Compliance tests |
| 4783 | * 4.2.2.4 and 4.2.2.5 |
| 4784 | */ |
| 4785 | intel_dp->aux.i2c_nack_count = 0; |
| 4786 | intel_dp->aux.i2c_defer_count = 0; |
| 4787 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4788 | intel_dp_set_edid(intel_dp); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4789 | if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4790 | status = connector_status_connected; |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4791 | intel_dp->detect_done = true; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4792 | |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4793 | /* Try to read the source of the interrupt */ |
| 4794 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
Ville Syrjälä | 65fbb4e | 2016-07-28 17:50:47 +0300 | [diff] [blame] | 4795 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) && |
| 4796 | sink_irq_vector != 0) { |
Todd Previte | 09b1eb1 | 2015-04-20 15:27:34 -0700 | [diff] [blame] | 4797 | /* Clear interrupt source */ |
| 4798 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 4799 | DP_DEVICE_SERVICE_IRQ_VECTOR, |
| 4800 | sink_irq_vector); |
| 4801 | |
| 4802 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) |
| 4803 | intel_dp_handle_test_request(intel_dp); |
| 4804 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
| 4805 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); |
| 4806 | } |
| 4807 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 4808 | out: |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4809 | if (status != connector_status_connected && !intel_dp->is_mst) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4810 | intel_dp_unset_edid(intel_dp); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4811 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4812 | 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] | 4813 | return status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4814 | } |
| 4815 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4816 | static int |
| 4817 | intel_dp_detect(struct drm_connector *connector, |
| 4818 | struct drm_modeset_acquire_ctx *ctx, |
| 4819 | bool force) |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4820 | { |
| 4821 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 4822 | int status = connector->status; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4823 | |
| 4824 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4825 | connector->base.id, connector->name); |
| 4826 | |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4827 | /* If full detect is not performed yet, do a full detect */ |
| 4828 | if (!intel_dp->detect_done) |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4829 | status = intel_dp_long_pulse(intel_dp->attached_connector); |
Shubhangi Shrivastava | 7d23e3c | 2016-03-30 18:05:23 +0530 | [diff] [blame] | 4830 | |
| 4831 | intel_dp->detect_done = false; |
Shubhangi Shrivastava | f21a219 | 2016-03-30 18:05:22 +0530 | [diff] [blame] | 4832 | |
Ville Syrjälä | 5cb651a | 2016-10-03 10:55:16 +0300 | [diff] [blame] | 4833 | return status; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4836 | static void |
| 4837 | intel_dp_force(struct drm_connector *connector) |
| 4838 | { |
| 4839 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 4840 | 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] | 4841 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4842 | |
| 4843 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 4844 | connector->base.id, connector->name); |
| 4845 | intel_dp_unset_edid(intel_dp); |
| 4846 | |
| 4847 | if (connector->status != connector_status_connected) |
| 4848 | return; |
| 4849 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4850 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4851 | |
| 4852 | intel_dp_set_edid(intel_dp); |
| 4853 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 4854 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4855 | |
| 4856 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4857 | intel_encoder->type = INTEL_OUTPUT_DP; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4858 | } |
| 4859 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4860 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 4861 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4862 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4863 | struct edid *edid; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4864 | |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4865 | edid = intel_connector->detect_edid; |
| 4866 | if (edid) { |
| 4867 | int ret = intel_connector_update_modes(connector, edid); |
| 4868 | if (ret) |
| 4869 | return ret; |
| 4870 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4871 | |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4872 | /* if eDP has no EDID, fall back to fixed mode */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4873 | if (intel_dp_is_edp(intel_attached_dp(connector)) && |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4874 | intel_connector->panel.fixed_mode) { |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4875 | struct drm_display_mode *mode; |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4876 | |
| 4877 | mode = drm_mode_duplicate(connector->dev, |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 4878 | intel_connector->panel.fixed_mode); |
Jani Nikula | f8779fd | 2012-10-19 14:51:48 +0300 | [diff] [blame] | 4879 | if (mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4880 | drm_mode_probed_add(connector, mode); |
| 4881 | return 1; |
| 4882 | } |
| 4883 | } |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4884 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4885 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 4888 | static int |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4889 | intel_dp_connector_register(struct drm_connector *connector) |
| 4890 | { |
| 4891 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 4892 | int ret; |
| 4893 | |
| 4894 | ret = intel_connector_register(connector); |
| 4895 | if (ret) |
| 4896 | return ret; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 4897 | |
| 4898 | i915_debugfs_connector_add(connector); |
| 4899 | |
| 4900 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
| 4901 | intel_dp->aux.name, connector->kdev->kobj.name); |
| 4902 | |
| 4903 | intel_dp->aux.dev = connector->kdev; |
| 4904 | return drm_dp_aux_register(&intel_dp->aux); |
| 4905 | } |
| 4906 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4907 | static void |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 4908 | intel_dp_connector_unregister(struct drm_connector *connector) |
| 4909 | { |
| 4910 | drm_dp_aux_unregister(&intel_attached_dp(connector)->aux); |
| 4911 | intel_connector_unregister(connector); |
| 4912 | } |
| 4913 | |
| 4914 | static void |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 4915 | intel_dp_connector_destroy(struct drm_connector *connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4916 | { |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4917 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4918 | |
Chris Wilson | 10e972d | 2014-09-04 21:43:45 +0100 | [diff] [blame] | 4919 | kfree(intel_connector->detect_edid); |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 4920 | |
Jani Nikula | 9cd300e | 2012-10-19 14:51:52 +0300 | [diff] [blame] | 4921 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
| 4922 | kfree(intel_connector->edid); |
| 4923 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4924 | /* |
| 4925 | * Can't call intel_dp_is_edp() since the encoder may have been |
| 4926 | * destroyed already. |
| 4927 | */ |
Paulo Zanoni | acd8db10 | 2013-06-12 17:27:23 -0300 | [diff] [blame] | 4928 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 4929 | intel_panel_fini(&intel_connector->panel); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 4930 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4931 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 4932 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4933 | } |
| 4934 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 4935 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4936 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4937 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 4938 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4939 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4940 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4941 | if (intel_dp_is_edp(intel_dp)) { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4942 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4943 | /* |
| 4944 | * vdd might still be enabled do to the delayed vdd off. |
| 4945 | * Make sure vdd is actually turned off here. |
| 4946 | */ |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4947 | pps_lock(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 4948 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4949 | pps_unlock(intel_dp); |
| 4950 | |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 4951 | if (intel_dp->edp_notifier.notifier_call) { |
| 4952 | unregister_reboot_notifier(&intel_dp->edp_notifier); |
| 4953 | intel_dp->edp_notifier.notifier_call = NULL; |
| 4954 | } |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 4955 | } |
Chris Wilson | 9968188 | 2016-06-20 09:29:17 +0100 | [diff] [blame] | 4956 | |
| 4957 | intel_dp_aux_fini(intel_dp); |
| 4958 | |
Imre Deak | c8bd0e4 | 2014-12-12 17:57:38 +0200 | [diff] [blame] | 4959 | drm_encoder_cleanup(encoder); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 4960 | kfree(intel_dig_port); |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 4961 | } |
| 4962 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 4963 | void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4964 | { |
| 4965 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 4966 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 4967 | if (!intel_dp_is_edp(intel_dp)) |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4968 | return; |
| 4969 | |
Ville Syrjälä | 951468f | 2014-09-04 14:55:31 +0300 | [diff] [blame] | 4970 | /* |
| 4971 | * vdd might still be enabled do to the delayed vdd off. |
| 4972 | * Make sure vdd is actually turned off here. |
| 4973 | */ |
Ville Syrjälä | afa4e53 | 2014-11-25 15:43:48 +0200 | [diff] [blame] | 4974 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4975 | pps_lock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4976 | edp_panel_vdd_off_sync(intel_dp); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 4977 | pps_unlock(intel_dp); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 4978 | } |
| 4979 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4980 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
| 4981 | { |
| 4982 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 4983 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4984 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4985 | |
| 4986 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 4987 | |
| 4988 | if (!edp_have_panel_vdd(intel_dp)) |
| 4989 | return; |
| 4990 | |
| 4991 | /* |
| 4992 | * The VDD bit needs a power domain reference, so if the bit is |
| 4993 | * already enabled when we boot or resume, grab this reference and |
| 4994 | * schedule a vdd off, so we don't hold on to the reference |
| 4995 | * indefinitely. |
| 4996 | */ |
| 4997 | 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] | 4998 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 4999 | |
| 5000 | edp_panel_vdd_schedule_off(intel_dp); |
| 5001 | } |
| 5002 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5003 | static enum pipe vlv_active_pipe(struct intel_dp *intel_dp) |
| 5004 | { |
| 5005 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); |
| 5006 | |
| 5007 | if ((intel_dp->DP & DP_PORT_EN) == 0) |
| 5008 | return INVALID_PIPE; |
| 5009 | |
| 5010 | if (IS_CHERRYVIEW(dev_priv)) |
| 5011 | return DP_PORT_TO_PIPE_CHV(intel_dp->DP); |
| 5012 | else |
| 5013 | return PORT_TO_PIPE(intel_dp->DP); |
| 5014 | } |
| 5015 | |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 5016 | void intel_dp_encoder_reset(struct drm_encoder *encoder) |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5017 | { |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5018 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5019 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 5020 | struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); |
Ville Syrjälä | 64989ca4 | 2016-05-13 20:53:56 +0300 | [diff] [blame] | 5021 | |
| 5022 | if (!HAS_DDI(dev_priv)) |
| 5023 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5024 | |
Imre Deak | dd75f6d | 2016-11-21 21:15:05 +0200 | [diff] [blame] | 5025 | if (lspcon->active) |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 5026 | lspcon_resume(lspcon); |
| 5027 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5028 | intel_dp->reset_link_params = true; |
| 5029 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5030 | pps_lock(intel_dp); |
| 5031 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5032 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5033 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 5034 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5035 | if (intel_dp_is_edp(intel_dp)) { |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5036 | /* Reinit the power sequencer, in case BIOS did something with it. */ |
| 5037 | intel_dp_pps_init(encoder->dev, intel_dp); |
| 5038 | intel_edp_panel_vdd_sanitize(intel_dp); |
| 5039 | } |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5040 | |
| 5041 | pps_unlock(intel_dp); |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5042 | } |
| 5043 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5044 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
Chris Wilson | beb6060 | 2014-09-02 20:04:00 +0100 | [diff] [blame] | 5045 | .force = intel_dp_force, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5046 | .fill_modes = drm_helper_probe_single_connector_modes, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5047 | .atomic_get_property = intel_digital_connector_atomic_get_property, |
| 5048 | .atomic_set_property = intel_digital_connector_atomic_set_property, |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 5049 | .late_register = intel_dp_connector_register, |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 5050 | .early_unregister = intel_dp_connector_unregister, |
Paulo Zanoni | 73845ad | 2013-06-12 17:27:30 -0300 | [diff] [blame] | 5051 | .destroy = intel_dp_connector_destroy, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 5052 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5053 | .atomic_duplicate_state = intel_digital_connector_duplicate_state, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5054 | }; |
| 5055 | |
| 5056 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 5057 | .detect_ctx = intel_dp_detect, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5058 | .get_modes = intel_dp_get_modes, |
| 5059 | .mode_valid = intel_dp_mode_valid, |
Maarten Lankhorst | 8f647a0 | 2017-05-01 15:38:01 +0200 | [diff] [blame] | 5060 | .atomic_check = intel_digital_connector_atomic_check, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5061 | }; |
| 5062 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5063 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Imre Deak | 6d93c0c | 2014-07-31 14:03:36 +0300 | [diff] [blame] | 5064 | .reset = intel_dp_encoder_reset, |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 5065 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5066 | }; |
| 5067 | |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5068 | enum irqreturn |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5069 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
| 5070 | { |
| 5071 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5072 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5073 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5074 | enum irqreturn ret = IRQ_NONE; |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5075 | |
Takashi Iwai | 2540058 | 2015-11-19 12:09:56 +0100 | [diff] [blame] | 5076 | if (intel_dig_port->base.type != INTEL_OUTPUT_EDP && |
| 5077 | intel_dig_port->base.type != INTEL_OUTPUT_HDMI) |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 5078 | intel_dig_port->base.type = INTEL_OUTPUT_DP; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5079 | |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5080 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
| 5081 | /* |
| 5082 | * vdd off can generate a long pulse on eDP which |
| 5083 | * would require vdd on to handle it, and thus we |
| 5084 | * would end up in an endless cycle of |
| 5085 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." |
| 5086 | */ |
| 5087 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", |
| 5088 | port_name(intel_dig_port->port)); |
Ville Syrjälä | a8b3d52f8 | 2015-02-10 14:11:46 +0200 | [diff] [blame] | 5089 | return IRQ_HANDLED; |
Ville Syrjälä | 7a7f84c | 2014-10-16 20:46:10 +0300 | [diff] [blame] | 5090 | } |
| 5091 | |
Ville Syrjälä | 26fbb77 | 2014-08-11 18:37:37 +0300 | [diff] [blame] | 5092 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
| 5093 | port_name(intel_dig_port->port), |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5094 | long_hpd ? "long" : "short"); |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5095 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5096 | if (long_hpd) { |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 5097 | intel_dp->reset_link_params = true; |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5098 | intel_dp->detect_done = false; |
| 5099 | return IRQ_NONE; |
| 5100 | } |
| 5101 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5102 | intel_display_power_get(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5103 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5104 | if (intel_dp->is_mst) { |
| 5105 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) { |
| 5106 | /* |
| 5107 | * If we were in MST mode, and device is not |
| 5108 | * there, get out of MST mode |
| 5109 | */ |
| 5110 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", |
| 5111 | intel_dp->is_mst, intel_dp->mst_mgr.mst_state); |
| 5112 | intel_dp->is_mst = false; |
| 5113 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, |
| 5114 | intel_dp->is_mst); |
| 5115 | intel_dp->detect_done = false; |
| 5116 | goto put_power; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5117 | } |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5118 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5119 | |
Ville Syrjälä | 27d4efc | 2016-10-03 10:55:15 +0300 | [diff] [blame] | 5120 | if (!intel_dp->is_mst) { |
| 5121 | if (!intel_dp_short_pulse(intel_dp)) { |
| 5122 | intel_dp->detect_done = false; |
| 5123 | goto put_power; |
Shubhangi Shrivastava | 39ff747 | 2016-03-30 18:05:26 +0530 | [diff] [blame] | 5124 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5125 | } |
Daniel Vetter | b2c5c18 | 2015-01-23 06:00:31 +0100 | [diff] [blame] | 5126 | |
| 5127 | ret = IRQ_HANDLED; |
| 5128 | |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5129 | put_power: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5130 | intel_display_power_put(dev_priv, intel_dp->aux_power_domain); |
Imre Deak | 1c767b3 | 2014-08-18 14:42:42 +0300 | [diff] [blame] | 5131 | |
| 5132 | return ret; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 5133 | } |
| 5134 | |
Rodrigo Vivi | 477ec32 | 2015-08-06 15:51:39 +0800 | [diff] [blame] | 5135 | /* check the VBT to see whether the eDP is on another port */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 5136 | 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] | 5137 | { |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5138 | /* |
| 5139 | * eDP not supported on g4x. so bail out early just |
| 5140 | * for a bit extra safety in case the VBT is bonkers. |
| 5141 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5142 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | 53ce81a | 2015-09-11 21:04:38 +0300 | [diff] [blame] | 5143 | return false; |
| 5144 | |
Imre Deak | a98d9c1 | 2016-12-21 12:17:24 +0200 | [diff] [blame] | 5145 | if (INTEL_GEN(dev_priv) < 9 && port == PORT_A) |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 5146 | return true; |
| 5147 | |
Jani Nikula | 951d9ef | 2016-03-16 12:43:31 +0200 | [diff] [blame] | 5148 | return intel_bios_is_port_edp(dev_priv, port); |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 5149 | } |
| 5150 | |
Maarten Lankhorst | 200819a | 2017-04-10 12:51:10 +0200 | [diff] [blame] | 5151 | static void |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5152 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 5153 | { |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5154 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
| 5155 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 5156 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 5157 | intel_attach_broadcast_rgb_property(connector); |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5158 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5159 | if (intel_dp_is_edp(intel_dp)) { |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5160 | u32 allowed_scalers; |
| 5161 | |
| 5162 | allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN); |
| 5163 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 5164 | allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER); |
| 5165 | |
| 5166 | drm_connector_attach_scaling_mode_property(connector, allowed_scalers); |
| 5167 | |
Maarten Lankhorst | eead06d | 2017-05-01 15:37:55 +0200 | [diff] [blame] | 5168 | connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT; |
Maarten Lankhorst | 8b45330 | 2017-05-01 15:37:56 +0200 | [diff] [blame] | 5169 | |
Yuly Novikov | 53b4183 | 2012-10-26 12:04:00 +0300 | [diff] [blame] | 5170 | } |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 5171 | } |
| 5172 | |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5173 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
| 5174 | { |
Abhay Kumar | d28d473 | 2016-01-22 17:39:04 -0800 | [diff] [blame] | 5175 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
Imre Deak | dada1a9 | 2014-01-29 13:25:41 +0200 | [diff] [blame] | 5176 | intel_dp->last_power_on = jiffies; |
| 5177 | intel_dp->last_backlight_off = jiffies; |
| 5178 | } |
| 5179 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5180 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5181 | intel_pps_readout_hw_state(struct drm_i915_private *dev_priv, |
| 5182 | struct intel_dp *intel_dp, struct edp_power_seq *seq) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5183 | { |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5184 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5185 | struct pps_registers regs; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5186 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5187 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5188 | |
| 5189 | /* Workaround: Need to write PP_CONTROL with the unlock key as |
| 5190 | * the very first thing. */ |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5191 | pp_ctl = ironlake_get_pp_control(intel_dp); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5192 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5193 | pp_on = I915_READ(regs.pp_on); |
| 5194 | pp_off = I915_READ(regs.pp_off); |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5195 | if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5196 | I915_WRITE(regs.pp_ctrl, pp_ctl); |
| 5197 | pp_div = I915_READ(regs.pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5198 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5199 | |
| 5200 | /* Pull timing values out of registers */ |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5201 | seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 5202 | PANEL_POWER_UP_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5203 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5204 | seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 5205 | PANEL_LIGHT_ON_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5206 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5207 | seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 5208 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5209 | |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5210 | seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 5211 | PANEL_POWER_DOWN_DELAY_SHIFT; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5212 | |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5213 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) { |
Manasi Navare | 12c8ca9 | 2017-06-26 12:21:45 -0700 | [diff] [blame] | 5214 | seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> |
| 5215 | BXT_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5216 | } else { |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5217 | seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5218 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5219 | } |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | static void |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5223 | intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq) |
| 5224 | { |
| 5225 | DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 5226 | state_name, |
| 5227 | seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12); |
| 5228 | } |
| 5229 | |
| 5230 | static void |
| 5231 | intel_pps_verify_state(struct drm_i915_private *dev_priv, |
| 5232 | struct intel_dp *intel_dp) |
| 5233 | { |
| 5234 | struct edp_power_seq hw; |
| 5235 | struct edp_power_seq *sw = &intel_dp->pps_delays; |
| 5236 | |
| 5237 | intel_pps_readout_hw_state(dev_priv, intel_dp, &hw); |
| 5238 | |
| 5239 | if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 || |
| 5240 | hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) { |
| 5241 | DRM_ERROR("PPS state mismatch\n"); |
| 5242 | intel_pps_dump_state("sw", sw); |
| 5243 | intel_pps_dump_state("hw", &hw); |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | static void |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5248 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, |
| 5249 | struct intel_dp *intel_dp) |
| 5250 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5251 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 5464861 | 2016-06-16 16:37:22 +0300 | [diff] [blame] | 5252 | struct edp_power_seq cur, vbt, spec, |
| 5253 | *final = &intel_dp->pps_delays; |
| 5254 | |
| 5255 | lockdep_assert_held(&dev_priv->pps_mutex); |
| 5256 | |
| 5257 | /* already initialized? */ |
| 5258 | if (final->t11_t12 != 0) |
| 5259 | return; |
| 5260 | |
| 5261 | intel_pps_readout_hw_state(dev_priv, intel_dp, &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5262 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5263 | intel_pps_dump_state("cur", &cur); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5264 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 5265 | vbt = dev_priv->vbt.edp.pps; |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 5266 | /* On Toshiba Satellite P50-C-18C system the VBT T12 delay |
| 5267 | * of 500ms appears to be too short. Ocassionally the panel |
| 5268 | * just fails to power back on. Increasing the delay to 800ms |
| 5269 | * seems sufficient to avoid this problem. |
| 5270 | */ |
| 5271 | if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) { |
Manasi Navare | c02b8fb | 2017-10-03 16:37:25 -0700 | [diff] [blame] | 5272 | vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10); |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 5273 | DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n", |
| 5274 | vbt.t11_t12); |
| 5275 | } |
Manasi Navare | 770a17a | 2017-06-26 12:21:44 -0700 | [diff] [blame] | 5276 | /* T11_T12 delay is special and actually in units of 100ms, but zero |
| 5277 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5278 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5279 | * too. */ |
| 5280 | vbt.t11_t12 += 100 * 10; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5281 | |
| 5282 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of |
| 5283 | * our hw here, which are all in 100usec. */ |
| 5284 | spec.t1_t3 = 210 * 10; |
| 5285 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ |
| 5286 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ |
| 5287 | spec.t10 = 500 * 10; |
| 5288 | /* This one is special and actually in units of 100ms, but zero |
| 5289 | * based in the hw (so we need to add 100 ms). But the sw vbt |
| 5290 | * table multiplies it with 1000 to make it in units of 100usec, |
| 5291 | * too. */ |
| 5292 | spec.t11_t12 = (510 + 100) * 10; |
| 5293 | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5294 | intel_pps_dump_state("vbt", &vbt); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5295 | |
| 5296 | /* Use the max of the register settings and vbt. If both are |
| 5297 | * unset, fall back to the spec limits. */ |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5298 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5299 | spec.field : \ |
| 5300 | max(cur.field, vbt.field)) |
| 5301 | assign_final(t1_t3); |
| 5302 | assign_final(t8); |
| 5303 | assign_final(t9); |
| 5304 | assign_final(t10); |
| 5305 | assign_final(t11_t12); |
| 5306 | #undef assign_final |
| 5307 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5308 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5309 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 5310 | intel_dp->backlight_on_delay = get_delay(t8); |
| 5311 | intel_dp->backlight_off_delay = get_delay(t9); |
| 5312 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 5313 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 5314 | #undef get_delay |
| 5315 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5316 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 5317 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 5318 | intel_dp->panel_power_cycle_delay); |
| 5319 | |
| 5320 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 5321 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5322 | |
| 5323 | /* |
| 5324 | * We override the HW backlight delays to 1 because we do manual waits |
| 5325 | * on them. For T8, even BSpec recommends doing it. For T9, if we |
| 5326 | * don't do this, we'll end up waiting for the backlight off delay |
| 5327 | * twice: once when we do the manual sleep, and once when we disable |
| 5328 | * the panel and wait for the PP_STATUS bit to become zero. |
| 5329 | */ |
| 5330 | final->t8 = 1; |
| 5331 | final->t9 = 1; |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | static void |
| 5335 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5336 | struct intel_dp *intel_dp, |
| 5337 | bool force_disable_vdd) |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5338 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5339 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5340 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 5341 | int div = dev_priv->rawclk_freq / 1000; |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5342 | struct pps_registers regs; |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5343 | enum port port = dp_to_dig_port(intel_dp)->port; |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5344 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5345 | |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 5346 | lockdep_assert_held(&dev_priv->pps_mutex); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5347 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5348 | intel_pps_get_registers(dev_priv, intel_dp, ®s); |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5349 | |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5350 | /* |
| 5351 | * On some VLV machines the BIOS can leave the VDD |
| 5352 | * enabled even on power seqeuencers which aren't |
| 5353 | * hooked up to any port. This would mess up the |
| 5354 | * power domain tracking the first time we pick |
| 5355 | * one of these power sequencers for use since |
| 5356 | * edp_panel_vdd_on() would notice that the VDD was |
| 5357 | * already on and therefore wouldn't grab the power |
| 5358 | * domain reference. Disable VDD first to avoid this. |
| 5359 | * This also avoids spuriously turning the VDD on as |
| 5360 | * soon as the new power seqeuencer gets initialized. |
| 5361 | */ |
| 5362 | if (force_disable_vdd) { |
| 5363 | u32 pp = ironlake_get_pp_control(intel_dp); |
| 5364 | |
| 5365 | WARN(pp & PANEL_POWER_ON, "Panel power already on\n"); |
| 5366 | |
| 5367 | if (pp & EDP_FORCE_VDD) |
| 5368 | DRM_DEBUG_KMS("VDD already on, disabling first\n"); |
| 5369 | |
| 5370 | pp &= ~EDP_FORCE_VDD; |
| 5371 | |
| 5372 | I915_WRITE(regs.pp_ctrl, pp); |
| 5373 | } |
| 5374 | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5375 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
Imre Deak | de9c1b6 | 2016-06-16 20:01:46 +0300 | [diff] [blame] | 5376 | (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT); |
| 5377 | pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) | |
Jani Nikula | f30d26e | 2013-01-16 10:53:40 +0200 | [diff] [blame] | 5378 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5379 | /* Compute the divisor for the pp clock, simply match the Bspec |
| 5380 | * formula. */ |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5381 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) { |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5382 | pp_div = I915_READ(regs.pp_ctrl); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5383 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; |
Manasi Navare | 12c8ca9 | 2017-06-26 12:21:45 -0700 | [diff] [blame] | 5384 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5385 | << BXT_POWER_CYCLE_DELAY_SHIFT); |
| 5386 | } else { |
| 5387 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 5388 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) |
| 5389 | << PANEL_POWER_CYCLE_DELAY_SHIFT); |
| 5390 | } |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5391 | |
| 5392 | /* Haswell doesn't have any port selection bits for the panel |
| 5393 | * power sequencer any more. */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5394 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | ad933b5 | 2014-08-18 22:15:56 +0300 | [diff] [blame] | 5395 | port_sel = PANEL_PORT_SELECT_VLV(port); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5396 | } 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] | 5397 | if (port == PORT_A) |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5398 | port_sel = PANEL_PORT_SELECT_DPA; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5399 | else |
Jani Nikula | a24c144 | 2013-09-05 16:44:46 +0300 | [diff] [blame] | 5400 | port_sel = PANEL_PORT_SELECT_DPD; |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5401 | } |
| 5402 | |
Jesse Barnes | 453c542 | 2013-03-28 09:55:41 -0700 | [diff] [blame] | 5403 | pp_on |= port_sel; |
| 5404 | |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5405 | I915_WRITE(regs.pp_on, pp_on); |
| 5406 | I915_WRITE(regs.pp_off, pp_off); |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5407 | if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5408 | I915_WRITE(regs.pp_ctrl, pp_div); |
Vandana Kannan | b0a08be | 2015-06-18 11:00:55 +0530 | [diff] [blame] | 5409 | else |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5410 | I915_WRITE(regs.pp_div, pp_div); |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5411 | |
Daniel Vetter | 67a5456 | 2012-10-20 20:57:45 +0200 | [diff] [blame] | 5412 | 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] | 5413 | I915_READ(regs.pp_on), |
| 5414 | I915_READ(regs.pp_off), |
Rodrigo Vivi | 938361e | 2017-06-02 13:06:44 -0700 | [diff] [blame] | 5415 | (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ? |
Imre Deak | 8e8232d | 2016-06-16 16:37:21 +0300 | [diff] [blame] | 5416 | (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) : |
| 5417 | I915_READ(regs.pp_div)); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 5418 | } |
| 5419 | |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5420 | static void intel_dp_pps_init(struct drm_device *dev, |
| 5421 | struct intel_dp *intel_dp) |
| 5422 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5423 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5424 | |
| 5425 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5426 | vlv_initial_power_sequencer_setup(intel_dp); |
| 5427 | } else { |
| 5428 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
Ville Syrjälä | 5d5ab2d | 2016-12-20 18:51:17 +0200 | [diff] [blame] | 5429 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5430 | } |
| 5431 | } |
| 5432 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5433 | /** |
| 5434 | * 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] | 5435 | * @dev_priv: i915 device |
Maarten Lankhorst | e896402 | 2016-08-25 11:07:02 +0200 | [diff] [blame] | 5436 | * @crtc_state: a pointer to the active intel_crtc_state |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5437 | * @refresh_rate: RR to be programmed |
| 5438 | * |
| 5439 | * This function gets called when refresh rate (RR) has to be changed from |
| 5440 | * one frequency to another. Switches can be between high and low RR |
| 5441 | * supported by the panel or to any other RR based on media playback (in |
| 5442 | * this case, RR value needs to be passed from user space). |
| 5443 | * |
| 5444 | * The caller of this function needs to take a lock on dev_priv->drrs. |
| 5445 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5446 | 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] | 5447 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5448 | int refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5449 | { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5450 | struct intel_encoder *encoder; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5451 | struct intel_digital_port *dig_port = NULL; |
| 5452 | struct intel_dp *intel_dp = dev_priv->drrs.dp; |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5453 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5454 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5455 | |
| 5456 | if (refresh_rate <= 0) { |
| 5457 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); |
| 5458 | return; |
| 5459 | } |
| 5460 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5461 | if (intel_dp == NULL) { |
| 5462 | DRM_DEBUG_KMS("DRRS not supported.\n"); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5463 | return; |
| 5464 | } |
| 5465 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5466 | dig_port = dp_to_dig_port(intel_dp); |
| 5467 | encoder = &dig_port->base; |
Ander Conselvan de Oliveira | 723f9aa | 2015-03-20 16:18:18 +0200 | [diff] [blame] | 5468 | intel_crtc = to_intel_crtc(encoder->base.crtc); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5469 | |
| 5470 | if (!intel_crtc) { |
| 5471 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); |
| 5472 | return; |
| 5473 | } |
| 5474 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5475 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5476 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
| 5477 | return; |
| 5478 | } |
| 5479 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5480 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
| 5481 | refresh_rate) |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5482 | index = DRRS_LOW_RR; |
| 5483 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5484 | if (index == dev_priv->drrs.refresh_rate_type) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5485 | DRM_DEBUG_KMS( |
| 5486 | "DRRS requested for previously set RR...ignoring\n"); |
| 5487 | return; |
| 5488 | } |
| 5489 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5490 | if (!crtc_state->base.active) { |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5491 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); |
| 5492 | return; |
| 5493 | } |
| 5494 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5495 | if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) { |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5496 | switch (index) { |
| 5497 | case DRRS_HIGH_RR: |
| 5498 | intel_dp_set_m_n(intel_crtc, M1_N1); |
| 5499 | break; |
| 5500 | case DRRS_LOW_RR: |
| 5501 | intel_dp_set_m_n(intel_crtc, M2_N2); |
| 5502 | break; |
| 5503 | case DRRS_MAX_RR: |
| 5504 | default: |
| 5505 | DRM_ERROR("Unsupported refreshrate type\n"); |
| 5506 | } |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5507 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 5508 | i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5509 | u32 val; |
Vandana Kannan | a4c30b1 | 2015-02-13 15:33:00 +0530 | [diff] [blame] | 5510 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 5511 | val = I915_READ(reg); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5512 | if (index > DRRS_HIGH_RR) { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5513 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5514 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5515 | else |
| 5516 | val |= PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5517 | } else { |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5518 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Vandana Kannan | 6fa7aec | 2015-02-13 15:33:01 +0530 | [diff] [blame] | 5519 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
| 5520 | else |
| 5521 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5522 | } |
| 5523 | I915_WRITE(reg, val); |
| 5524 | } |
| 5525 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5526 | dev_priv->drrs.refresh_rate_type = index; |
| 5527 | |
| 5528 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); |
| 5529 | } |
| 5530 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5531 | /** |
| 5532 | * intel_edp_drrs_enable - init drrs struct if supported |
| 5533 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5534 | * @crtc_state: A pointer to the active crtc state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5535 | * |
| 5536 | * Initializes frontbuffer_bits and drrs.dp |
| 5537 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5538 | void intel_edp_drrs_enable(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5539 | const struct intel_crtc_state *crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5540 | { |
| 5541 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5542 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5543 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5544 | if (!crtc_state->has_drrs) { |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5545 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); |
| 5546 | return; |
| 5547 | } |
| 5548 | |
Radhakrishna Sripada | da83ef8 | 2017-09-14 11:16:41 -0700 | [diff] [blame] | 5549 | if (dev_priv->psr.enabled) { |
| 5550 | DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n"); |
| 5551 | return; |
| 5552 | } |
| 5553 | |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5554 | mutex_lock(&dev_priv->drrs.mutex); |
| 5555 | if (WARN_ON(dev_priv->drrs.dp)) { |
| 5556 | DRM_ERROR("DRRS already enabled\n"); |
| 5557 | goto unlock; |
| 5558 | } |
| 5559 | |
| 5560 | dev_priv->drrs.busy_frontbuffer_bits = 0; |
| 5561 | |
| 5562 | dev_priv->drrs.dp = intel_dp; |
| 5563 | |
| 5564 | unlock: |
| 5565 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5566 | } |
| 5567 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5568 | /** |
| 5569 | * intel_edp_drrs_disable - Disable DRRS |
| 5570 | * @intel_dp: DP struct |
Maarten Lankhorst | 5423adf | 2016-08-31 11:01:36 +0200 | [diff] [blame] | 5571 | * @old_crtc_state: Pointer to old crtc_state. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5572 | * |
| 5573 | */ |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5574 | void intel_edp_drrs_disable(struct intel_dp *intel_dp, |
Ville Syrjälä | 5f88a9c | 2017-08-18 16:49:58 +0300 | [diff] [blame] | 5575 | const struct intel_crtc_state *old_crtc_state) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5576 | { |
| 5577 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5578 | struct drm_i915_private *dev_priv = to_i915(dev); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5579 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5580 | if (!old_crtc_state->has_drrs) |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5581 | return; |
| 5582 | |
| 5583 | mutex_lock(&dev_priv->drrs.mutex); |
| 5584 | if (!dev_priv->drrs.dp) { |
| 5585 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5586 | return; |
| 5587 | } |
| 5588 | |
| 5589 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5590 | intel_dp_set_drrs_state(dev_priv, old_crtc_state, |
| 5591 | intel_dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 5592 | |
| 5593 | dev_priv->drrs.dp = NULL; |
| 5594 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5595 | |
| 5596 | cancel_delayed_work_sync(&dev_priv->drrs.work); |
| 5597 | } |
| 5598 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5599 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
| 5600 | { |
| 5601 | struct drm_i915_private *dev_priv = |
| 5602 | container_of(work, typeof(*dev_priv), drrs.work.work); |
| 5603 | struct intel_dp *intel_dp; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5604 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5605 | mutex_lock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5606 | |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5607 | intel_dp = dev_priv->drrs.dp; |
| 5608 | |
| 5609 | if (!intel_dp) |
| 5610 | goto unlock; |
| 5611 | |
| 5612 | /* |
| 5613 | * The delayed work can race with an invalidate hence we need to |
| 5614 | * recheck. |
| 5615 | */ |
| 5616 | |
| 5617 | if (dev_priv->drrs.busy_frontbuffer_bits) |
| 5618 | goto unlock; |
| 5619 | |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5620 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) { |
| 5621 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 5622 | |
| 5623 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5624 | intel_dp->attached_connector->panel.downclock_mode->vrefresh); |
| 5625 | } |
Vandana Kannan | 4e9ac94 | 2015-01-22 15:14:45 +0530 | [diff] [blame] | 5626 | |
| 5627 | unlock: |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5628 | mutex_unlock(&dev_priv->drrs.mutex); |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5629 | } |
| 5630 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5631 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5632 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5633 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5634 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5635 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5636 | * This function gets called everytime rendering on the given planes start. |
| 5637 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5638 | * |
| 5639 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5640 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5641 | void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv, |
| 5642 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5643 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5644 | struct drm_crtc *crtc; |
| 5645 | enum pipe pipe; |
| 5646 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5647 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5648 | return; |
| 5649 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5650 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5651 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5652 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5653 | if (!dev_priv->drrs.dp) { |
| 5654 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5655 | return; |
| 5656 | } |
| 5657 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5658 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5659 | pipe = to_intel_crtc(crtc)->pipe; |
| 5660 | |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5661 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 5662 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; |
| 5663 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5664 | /* invalidate means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5665 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5666 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5667 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5668 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5669 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5670 | } |
| 5671 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5672 | /** |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5673 | * intel_edp_drrs_flush - Restart Idleness DRRS |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5674 | * @dev_priv: i915 device |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5675 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 5676 | * |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5677 | * This function gets called every time rendering on the given planes has |
| 5678 | * completed or flip on a crtc is completed. So DRRS should be upclocked |
| 5679 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, |
| 5680 | * if no other planes are dirty. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5681 | * |
| 5682 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. |
| 5683 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5684 | void intel_edp_drrs_flush(struct drm_i915_private *dev_priv, |
| 5685 | unsigned int frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5686 | { |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5687 | struct drm_crtc *crtc; |
| 5688 | enum pipe pipe; |
| 5689 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5690 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5691 | return; |
| 5692 | |
Daniel Vetter | 88f933a | 2015-04-09 16:44:16 +0200 | [diff] [blame] | 5693 | cancel_delayed_work(&dev_priv->drrs.work); |
Ramalingam C | 3954e73 | 2015-03-03 12:11:46 +0530 | [diff] [blame] | 5694 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5695 | mutex_lock(&dev_priv->drrs.mutex); |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5696 | if (!dev_priv->drrs.dp) { |
| 5697 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5698 | return; |
| 5699 | } |
| 5700 | |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5701 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
| 5702 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5703 | |
| 5704 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5705 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 5706 | |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5707 | /* flush means busy screen hence upclock */ |
Daniel Vetter | c1d038c | 2015-06-18 10:30:25 +0200 | [diff] [blame] | 5708 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
Maarten Lankhorst | 85cb48a | 2016-08-09 17:04:13 +0200 | [diff] [blame] | 5709 | intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config, |
| 5710 | dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh); |
Ramalingam C | 0ddfd20 | 2015-06-15 20:50:05 +0530 | [diff] [blame] | 5711 | |
| 5712 | /* |
| 5713 | * flush also means no more activity hence schedule downclock, if all |
| 5714 | * other fbs are quiescent too |
| 5715 | */ |
| 5716 | if (!dev_priv->drrs.busy_frontbuffer_bits) |
Vandana Kannan | a93fad0 | 2015-01-10 02:25:59 +0530 | [diff] [blame] | 5717 | schedule_delayed_work(&dev_priv->drrs.work, |
| 5718 | msecs_to_jiffies(1000)); |
| 5719 | mutex_unlock(&dev_priv->drrs.mutex); |
| 5720 | } |
| 5721 | |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5722 | /** |
| 5723 | * DOC: Display Refresh Rate Switching (DRRS) |
| 5724 | * |
| 5725 | * Display Refresh Rate Switching (DRRS) is a power conservation feature |
| 5726 | * which enables swtching between low and high refresh rates, |
| 5727 | * dynamically, based on the usage scenario. This feature is applicable |
| 5728 | * for internal panels. |
| 5729 | * |
| 5730 | * Indication that the panel supports DRRS is given by the panel EDID, which |
| 5731 | * would list multiple refresh rates for one resolution. |
| 5732 | * |
| 5733 | * DRRS is of 2 types - static and seamless. |
| 5734 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset |
| 5735 | * (may appear as a blink on screen) and is used in dock-undock scenario. |
| 5736 | * Seamless DRRS involves changing RR without any visual effect to the user |
| 5737 | * and can be used during normal system usage. This is done by programming |
| 5738 | * certain registers. |
| 5739 | * |
| 5740 | * Support for static/seamless DRRS may be indicated in the VBT based on |
| 5741 | * inputs from the panel spec. |
| 5742 | * |
| 5743 | * DRRS saves power by switching to low RR based on usage scenarios. |
| 5744 | * |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 5745 | * The implementation is based on frontbuffer tracking implementation. When |
| 5746 | * there is a disturbance on the screen triggered by user activity or a periodic |
| 5747 | * system activity, DRRS is disabled (RR is changed to high RR). When there is |
| 5748 | * no movement on screen, after a timeout of 1 second, a switch to low RR is |
| 5749 | * made. |
| 5750 | * |
| 5751 | * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate() |
| 5752 | * and intel_edp_drrs_flush() are called. |
Vandana Kannan | b33a281 | 2015-02-13 15:33:03 +0530 | [diff] [blame] | 5753 | * |
| 5754 | * DRRS can be further extended to support other internal panels and also |
| 5755 | * the scenario of video playback wherein RR is set based on the rate |
| 5756 | * requested by userspace. |
| 5757 | */ |
| 5758 | |
| 5759 | /** |
| 5760 | * intel_dp_drrs_init - Init basic DRRS work and mutex. |
| 5761 | * @intel_connector: eDP connector |
| 5762 | * @fixed_mode: preferred mode of panel |
| 5763 | * |
| 5764 | * This function is called only once at driver load to initialize basic |
| 5765 | * DRRS stuff. |
| 5766 | * |
| 5767 | * Returns: |
| 5768 | * Downclock mode if panel supports it, else return NULL. |
| 5769 | * DRRS support is determined by the presence of downclock mode (apart |
| 5770 | * from VBT setting). |
| 5771 | */ |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5772 | static struct drm_display_mode * |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5773 | intel_dp_drrs_init(struct intel_connector *intel_connector, |
| 5774 | struct drm_display_mode *fixed_mode) |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5775 | { |
| 5776 | struct drm_connector *connector = &intel_connector->base; |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5777 | struct drm_device *dev = connector->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5778 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5779 | struct drm_display_mode *downclock_mode = NULL; |
| 5780 | |
Daniel Vetter | 9da7d69 | 2015-04-09 16:44:15 +0200 | [diff] [blame] | 5781 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
| 5782 | mutex_init(&dev_priv->drrs.mutex); |
| 5783 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 5784 | if (INTEL_GEN(dev_priv) <= 6) { |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5785 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); |
| 5786 | return NULL; |
| 5787 | } |
| 5788 | |
| 5789 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5790 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5791 | return NULL; |
| 5792 | } |
| 5793 | |
| 5794 | downclock_mode = intel_find_panel_downclock |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 5795 | (dev_priv, fixed_mode, connector); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5796 | |
| 5797 | if (!downclock_mode) { |
Ramalingam C | a1d2634 | 2015-02-23 17:38:33 +0530 | [diff] [blame] | 5798 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5799 | return NULL; |
| 5800 | } |
| 5801 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5802 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
Pradeep Bhat | 439d7ac | 2014-04-05 12:13:28 +0530 | [diff] [blame] | 5803 | |
Vandana Kannan | 96178ee | 2015-01-10 02:25:56 +0530 | [diff] [blame] | 5804 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
Damien Lespiau | 4079b8d | 2014-08-05 10:39:42 +0100 | [diff] [blame] | 5805 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5806 | return downclock_mode; |
| 5807 | } |
| 5808 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5809 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 5810 | struct intel_connector *intel_connector) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5811 | { |
| 5812 | struct drm_connector *connector = &intel_connector->base; |
| 5813 | 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] | 5814 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5815 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5816 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5817 | struct drm_display_mode *fixed_mode = NULL; |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5818 | struct drm_display_mode *alt_fixed_mode = NULL; |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5819 | struct drm_display_mode *downclock_mode = NULL; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5820 | bool has_dpcd; |
| 5821 | struct drm_display_mode *scan; |
| 5822 | struct edid *edid; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5823 | enum pipe pipe = INVALID_PIPE; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5824 | |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 5825 | if (!intel_dp_is_edp(intel_dp)) |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5826 | return true; |
| 5827 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 5828 | /* |
| 5829 | * On IBX/CPT we may get here with LVDS already registered. Since the |
| 5830 | * driver uses the only internal power sequencer available for both |
| 5831 | * eDP and LVDS bail out early in this case to prevent interfering |
| 5832 | * with an already powered-on LVDS power sequencer. |
| 5833 | */ |
| 5834 | if (intel_get_lvds_encoder(dev)) { |
| 5835 | WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))); |
| 5836 | DRM_INFO("LVDS was detected, not registering eDP\n"); |
| 5837 | |
| 5838 | return false; |
| 5839 | } |
| 5840 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5841 | pps_lock(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5842 | |
| 5843 | intel_dp_init_panel_power_timestamps(intel_dp); |
Imre Deak | 335f752 | 2016-08-10 14:07:32 +0300 | [diff] [blame] | 5844 | intel_dp_pps_init(dev, intel_dp); |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5845 | intel_edp_panel_vdd_sanitize(intel_dp); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5846 | |
Ville Syrjälä | 49e6bc5 | 2014-10-28 16:15:52 +0200 | [diff] [blame] | 5847 | pps_unlock(intel_dp); |
Paulo Zanoni | 6363521 | 2014-04-22 19:55:42 -0300 | [diff] [blame] | 5848 | |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5849 | /* Cache DPCD and EDID for edp. */ |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5850 | has_dpcd = intel_edp_init_dpcd(intel_dp); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5851 | |
Ville Syrjälä | fe5a66f | 2016-07-29 16:52:39 +0300 | [diff] [blame] | 5852 | if (!has_dpcd) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5853 | /* if this fails, presume the device is a ghost */ |
| 5854 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5855 | goto out_vdd_off; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5856 | } |
| 5857 | |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5858 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 0b99836 | 2014-03-14 16:51:17 +0200 | [diff] [blame] | 5859 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5860 | if (edid) { |
| 5861 | if (drm_add_edid_modes(connector, edid)) { |
| 5862 | drm_mode_connector_update_edid_property(connector, |
| 5863 | edid); |
| 5864 | drm_edid_to_eld(connector, edid); |
| 5865 | } else { |
| 5866 | kfree(edid); |
| 5867 | edid = ERR_PTR(-EINVAL); |
| 5868 | } |
| 5869 | } else { |
| 5870 | edid = ERR_PTR(-ENOENT); |
| 5871 | } |
| 5872 | intel_connector->edid = edid; |
| 5873 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5874 | /* prefer fixed mode from EDID if available, save an alt mode also */ |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5875 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 5876 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 5877 | fixed_mode = drm_mode_duplicate(dev, scan); |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5878 | downclock_mode = intel_dp_drrs_init( |
Pradeep Bhat | 4f9db5b | 2014-04-05 12:12:31 +0530 | [diff] [blame] | 5879 | intel_connector, fixed_mode); |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5880 | } else if (!alt_fixed_mode) { |
| 5881 | alt_fixed_mode = drm_mode_duplicate(dev, scan); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | /* fallback to VBT if available for eDP */ |
| 5886 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { |
| 5887 | fixed_mode = drm_mode_duplicate(dev, |
| 5888 | dev_priv->vbt.lfp_lvds_vbt_mode); |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5889 | if (fixed_mode) { |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5890 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; |
Ville Syrjälä | df45724 | 2016-05-31 12:08:34 +0300 | [diff] [blame] | 5891 | connector->display_info.width_mm = fixed_mode->width_mm; |
| 5892 | connector->display_info.height_mm = fixed_mode->height_mm; |
| 5893 | } |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5894 | } |
Daniel Vetter | 060c877 | 2014-03-21 23:22:35 +0100 | [diff] [blame] | 5895 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5896 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5897 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5898 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
| 5899 | register_reboot_notifier(&intel_dp->edp_notifier); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5900 | |
| 5901 | /* |
| 5902 | * Figure out the current pipe for the initial backlight setup. |
| 5903 | * If the current pipe isn't valid, try the PPS pipe, and if that |
| 5904 | * fails just assume pipe A. |
| 5905 | */ |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 5906 | pipe = vlv_active_pipe(intel_dp); |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5907 | |
| 5908 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5909 | pipe = intel_dp->pps_pipe; |
| 5910 | |
| 5911 | if (pipe != PIPE_A && pipe != PIPE_B) |
| 5912 | pipe = PIPE_A; |
| 5913 | |
| 5914 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", |
| 5915 | pipe_name(pipe)); |
Clint Taylor | 01527b3 | 2014-07-07 13:01:46 -0700 | [diff] [blame] | 5916 | } |
| 5917 | |
Jim Bride | dc911f5 | 2017-08-09 12:48:53 -0700 | [diff] [blame] | 5918 | intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode, |
| 5919 | downclock_mode); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 5920 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 5921 | intel_panel_setup_backlight(connector, pipe); |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5922 | |
| 5923 | return true; |
Imre Deak | b4d06ed | 2016-06-21 11:51:49 +0300 | [diff] [blame] | 5924 | |
| 5925 | out_vdd_off: |
| 5926 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 5927 | /* |
| 5928 | * vdd might still be enabled do to the delayed vdd off. |
| 5929 | * Make sure vdd is actually turned off here. |
| 5930 | */ |
| 5931 | pps_lock(intel_dp); |
| 5932 | edp_panel_vdd_off_sync(intel_dp); |
| 5933 | pps_unlock(intel_dp); |
| 5934 | |
| 5935 | return false; |
Paulo Zanoni | ed92f0b | 2013-06-12 17:27:24 -0300 | [diff] [blame] | 5936 | } |
| 5937 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5938 | /* Set up the hotplug pin and aux power domain. */ |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5939 | static void |
| 5940 | intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port) |
| 5941 | { |
| 5942 | struct intel_encoder *encoder = &intel_dig_port->base; |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5943 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5944 | |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 5945 | encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port); |
| 5946 | |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5947 | switch (intel_dig_port->port) { |
| 5948 | case PORT_A: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5949 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5950 | break; |
| 5951 | case PORT_B: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5952 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5953 | break; |
| 5954 | case PORT_C: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5955 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5956 | break; |
| 5957 | case PORT_D: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5958 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5959 | break; |
| 5960 | case PORT_E: |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 5961 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5962 | intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D; |
Ander Conselvan de Oliveira | b71953a | 2017-02-03 16:03:14 +0200 | [diff] [blame] | 5963 | break; |
| 5964 | default: |
| 5965 | MISSING_CASE(intel_dig_port->port); |
| 5966 | } |
| 5967 | } |
| 5968 | |
Manasi Navare | 9301397 | 2017-04-06 16:44:19 +0300 | [diff] [blame] | 5969 | static void intel_dp_modeset_retry_work_fn(struct work_struct *work) |
| 5970 | { |
| 5971 | struct intel_connector *intel_connector; |
| 5972 | struct drm_connector *connector; |
| 5973 | |
| 5974 | intel_connector = container_of(work, typeof(*intel_connector), |
| 5975 | modeset_retry_work); |
| 5976 | connector = &intel_connector->base; |
| 5977 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, |
| 5978 | connector->name); |
| 5979 | |
| 5980 | /* Grab the locks before changing connector property*/ |
| 5981 | mutex_lock(&connector->dev->mode_config.mutex); |
| 5982 | /* Set connector link status to BAD and send a Uevent to notify |
| 5983 | * userspace to do a modeset. |
| 5984 | */ |
| 5985 | drm_mode_connector_set_link_status_property(connector, |
| 5986 | DRM_MODE_LINK_STATUS_BAD); |
| 5987 | mutex_unlock(&connector->dev->mode_config.mutex); |
| 5988 | /* Send Hotplug uevent so userspace can reprobe */ |
| 5989 | drm_kms_helper_hotplug_event(connector->dev); |
| 5990 | } |
| 5991 | |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 5992 | bool |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5993 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
| 5994 | struct intel_connector *intel_connector) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5995 | { |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 5996 | struct drm_connector *connector = &intel_connector->base; |
| 5997 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
| 5998 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 5999 | struct drm_device *dev = intel_encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6000 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 6001 | enum port port = intel_dig_port->port; |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6002 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6003 | |
Manasi Navare | 9301397 | 2017-04-06 16:44:19 +0300 | [diff] [blame] | 6004 | /* Initialize the work for modeset in case of link train failure */ |
| 6005 | INIT_WORK(&intel_connector->modeset_retry_work, |
| 6006 | intel_dp_modeset_retry_work_fn); |
| 6007 | |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6008 | if (WARN(intel_dig_port->max_lanes < 1, |
| 6009 | "Not enough lanes (%d) for DP on port %c\n", |
| 6010 | intel_dig_port->max_lanes, port_name(port))) |
| 6011 | return false; |
| 6012 | |
Jani Nikula | 55cfc58 | 2017-03-28 17:59:04 +0300 | [diff] [blame] | 6013 | intel_dp_set_source_rates(intel_dp); |
| 6014 | |
Manasi Navare | d7e8ef0 | 2017-02-07 16:54:11 -0800 | [diff] [blame] | 6015 | intel_dp->reset_link_params = true; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 6016 | intel_dp->pps_pipe = INVALID_PIPE; |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6017 | intel_dp->active_pipe = INVALID_PIPE; |
Ville Syrjälä | a4a5d2f | 2014-09-04 14:54:20 +0300 | [diff] [blame] | 6018 | |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6019 | /* intel_dp vfuncs */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6020 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b6b5e38 | 2014-01-20 16:00:59 +0000 | [diff] [blame] | 6021 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6022 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6023 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 6024 | else if (HAS_PCH_SPLIT(dev_priv)) |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6025 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; |
| 6026 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 6027 | intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider; |
Damien Lespiau | ec5b01d | 2014-01-21 13:35:39 +0000 | [diff] [blame] | 6028 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 6029 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | b9ca5fa | 2014-01-20 16:01:00 +0000 | [diff] [blame] | 6030 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; |
| 6031 | else |
Ville Syrjälä | 6ffb1be | 2016-03-02 17:22:14 +0200 | [diff] [blame] | 6032 | intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl; |
Damien Lespiau | 153b110 | 2014-01-21 13:37:15 +0000 | [diff] [blame] | 6033 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6034 | if (HAS_DDI(dev_priv)) |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 6035 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; |
| 6036 | |
Daniel Vetter | 0767935 | 2012-09-06 22:15:42 +0200 | [diff] [blame] | 6037 | /* Preserve the current hw state. */ |
| 6038 | intel_dp->DP = I915_READ(intel_dp->output_reg); |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 6039 | intel_dp->attached_connector = intel_connector; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 6040 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 6041 | if (intel_dp_is_port_edp(dev_priv, port)) |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 6042 | type = DRM_MODE_CONNECTOR_eDP; |
Ville Syrjälä | 3b32a35 | 2013-11-01 18:22:41 +0200 | [diff] [blame] | 6043 | else |
| 6044 | type = DRM_MODE_CONNECTOR_DisplayPort; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6045 | |
Ville Syrjälä | 9f2bdb0 | 2016-12-14 20:00:23 +0200 | [diff] [blame] | 6046 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 6047 | intel_dp->active_pipe = vlv_active_pipe(intel_dp); |
| 6048 | |
Imre Deak | f7d2490 | 2013-05-08 13:14:05 +0300 | [diff] [blame] | 6049 | /* |
| 6050 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but |
| 6051 | * for DP the encoder type can be set by the caller to |
| 6052 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. |
| 6053 | */ |
| 6054 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 6055 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 6056 | |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6057 | /* eDP only on port B and/or C on vlv/chv */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6058 | if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6059 | intel_dp_is_edp(intel_dp) && |
| 6060 | port != PORT_B && port != PORT_C)) |
Ville Syrjälä | c17ed5b | 2014-10-16 21:27:27 +0300 | [diff] [blame] | 6061 | return false; |
| 6062 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 6063 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
| 6064 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", |
| 6065 | port_name(port)); |
| 6066 | |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 6067 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6068 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 6069 | |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6070 | connector->interlace_allowed = true; |
| 6071 | connector->doublescan_allowed = 0; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 6072 | |
Ander Conselvan de Oliveira | 5432fca | 2017-02-22 08:34:26 +0200 | [diff] [blame] | 6073 | intel_dp_init_connector_port_info(intel_dig_port); |
| 6074 | |
Mika Kahola | b633958 | 2016-09-09 14:10:52 +0300 | [diff] [blame] | 6075 | intel_dp_aux_init(intel_dp); |
Chris Wilson | 7a418e3 | 2016-06-24 14:00:14 +0100 | [diff] [blame] | 6076 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 6077 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 6078 | edp_panel_vdd_work); |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 6079 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6080 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6081 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6082 | if (HAS_DDI(dev_priv)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 6083 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 6084 | else |
| 6085 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
| 6086 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6087 | /* init MST on ports that can support it */ |
Jani Nikula | 1853a9d | 2017-08-18 12:30:20 +0300 | [diff] [blame] | 6088 | if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) && |
Jani Nikula | 0c9b371 | 2015-05-18 17:10:01 +0300 | [diff] [blame] | 6089 | (port == PORT_B || port == PORT_C || port == PORT_D)) |
| 6090 | intel_dp_mst_encoder_init(intel_dig_port, |
| 6091 | intel_connector->base.base.id); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6092 | |
Ville Syrjälä | 36b5f42 | 2014-10-16 21:27:30 +0300 | [diff] [blame] | 6093 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6094 | intel_dp_aux_fini(intel_dp); |
| 6095 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
| 6096 | goto fail; |
Paulo Zanoni | b2f246a | 2013-06-12 17:27:26 -0300 | [diff] [blame] | 6097 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 6098 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 6099 | intel_dp_add_properties(intel_dp, connector); |
| 6100 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6101 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 6102 | * 0xd. Failure to do so will result in spurious interrupts being |
| 6103 | * generated on the port when a cable is not attached. |
| 6104 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6105 | if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6106 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 6107 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 6108 | } |
Paulo Zanoni | 16c2553 | 2013-06-12 17:27:25 -0300 | [diff] [blame] | 6109 | |
| 6110 | return true; |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6111 | |
| 6112 | fail: |
Ville Syrjälä | a121f4e | 2015-11-11 20:34:11 +0200 | [diff] [blame] | 6113 | drm_connector_cleanup(connector); |
| 6114 | |
| 6115 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 6116 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6117 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6118 | bool intel_dp_init(struct drm_i915_private *dev_priv, |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6119 | i915_reg_t output_reg, |
| 6120 | enum port port) |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6121 | { |
| 6122 | struct intel_digital_port *intel_dig_port; |
| 6123 | struct intel_encoder *intel_encoder; |
| 6124 | struct drm_encoder *encoder; |
| 6125 | struct intel_connector *intel_connector; |
| 6126 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 6127 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6128 | if (!intel_dig_port) |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6129 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6130 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6131 | intel_connector = intel_connector_alloc(); |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6132 | if (!intel_connector) |
| 6133 | goto err_connector_alloc; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6134 | |
| 6135 | intel_encoder = &intel_dig_port->base; |
| 6136 | encoder = &intel_encoder->base; |
| 6137 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 6138 | if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, |
| 6139 | &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, |
| 6140 | "DP %c", port_name(port))) |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6141 | goto err_encoder_init; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6142 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 6143 | intel_encoder->compute_config = intel_dp_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 6144 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 6145 | intel_encoder->get_config = intel_dp_get_config; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 6146 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6147 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 9197c88 | 2014-04-09 13:29:05 +0300 | [diff] [blame] | 6148 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
Chon Ming Lee | e4a1d84 | 2014-04-09 13:28:20 +0300 | [diff] [blame] | 6149 | intel_encoder->pre_enable = chv_pre_enable_dp; |
| 6150 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6151 | intel_encoder->disable = vlv_disable_dp; |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 6152 | intel_encoder->post_disable = chv_post_disable_dp; |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6153 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6154 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6155 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6156 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
| 6157 | intel_encoder->enable = vlv_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6158 | intel_encoder->disable = vlv_disable_dp; |
Ville Syrjälä | 49277c3 | 2014-03-31 18:21:26 +0300 | [diff] [blame] | 6159 | intel_encoder->post_disable = vlv_post_disable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6160 | } else if (INTEL_GEN(dev_priv) >= 5) { |
| 6161 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6162 | intel_encoder->enable = g4x_enable_dp; |
| 6163 | intel_encoder->disable = ilk_disable_dp; |
| 6164 | intel_encoder->post_disable = ilk_post_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6165 | } else { |
Jani Nikula | ecff4f3 | 2013-09-06 07:38:29 +0300 | [diff] [blame] | 6166 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
| 6167 | intel_encoder->enable = g4x_enable_dp; |
Ville Syrjälä | 1a8ff60 | 2017-09-20 18:12:51 +0300 | [diff] [blame] | 6168 | intel_encoder->disable = g4x_disable_dp; |
Jani Nikula | ab1f90f | 2013-07-30 12:20:30 +0300 | [diff] [blame] | 6169 | } |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6170 | |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 6171 | intel_dig_port->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6172 | intel_dig_port->dp.output_reg = output_reg; |
Ville Syrjälä | ccb1a83 | 2015-12-08 19:59:38 +0200 | [diff] [blame] | 6173 | intel_dig_port->max_lanes = 4; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6174 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 6175 | intel_encoder->type = INTEL_OUTPUT_DP; |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6176 | intel_encoder->power_domain = intel_port_to_power_domain(port); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6177 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 882ec38 | 2014-04-28 14:07:43 +0300 | [diff] [blame] | 6178 | if (port == PORT_D) |
| 6179 | intel_encoder->crtc_mask = 1 << 2; |
| 6180 | else |
| 6181 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
| 6182 | } else { |
| 6183 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 6184 | } |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 6185 | intel_encoder->cloneable = 0; |
Pandiyan, Dhinakaran | 03cdc1d | 2016-09-19 18:24:38 -0700 | [diff] [blame] | 6186 | intel_encoder->port = port; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6187 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6188 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6189 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 6190 | |
Ville Syrjälä | 385e4de | 2017-08-18 16:49:55 +0300 | [diff] [blame] | 6191 | if (port != PORT_A) |
| 6192 | intel_infoframe_init(intel_dig_port); |
| 6193 | |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6194 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
| 6195 | goto err_init_connector; |
| 6196 | |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6197 | return true; |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6198 | |
| 6199 | err_init_connector: |
| 6200 | drm_encoder_cleanup(encoder); |
Sudip Mukherjee | 893da0c | 2015-10-08 19:28:00 +0530 | [diff] [blame] | 6201 | err_encoder_init: |
Sudip Mukherjee | 11aee0f | 2015-10-08 19:27:59 +0530 | [diff] [blame] | 6202 | kfree(intel_connector); |
| 6203 | err_connector_alloc: |
| 6204 | kfree(intel_dig_port); |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 6205 | return false; |
Paulo Zanoni | f0fec3f | 2012-10-26 19:05:48 -0200 | [diff] [blame] | 6206 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6207 | |
| 6208 | void intel_dp_mst_suspend(struct drm_device *dev) |
| 6209 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6210 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6211 | int i; |
| 6212 | |
| 6213 | /* disable MST */ |
| 6214 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6215 | 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] | 6216 | |
| 6217 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6218 | continue; |
| 6219 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6220 | if (intel_dig_port->dp.is_mst) |
| 6221 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | void intel_dp_mst_resume(struct drm_device *dev) |
| 6226 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6227 | struct drm_i915_private *dev_priv = to_i915(dev); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6228 | int i; |
| 6229 | |
| 6230 | for (i = 0; i < I915_MAX_PORTS; i++) { |
Jani Nikula | 5fcece8 | 2015-05-27 15:03:42 +0300 | [diff] [blame] | 6231 | 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] | 6232 | int ret; |
| 6233 | |
| 6234 | if (!intel_dig_port || !intel_dig_port->dp.can_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6235 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6236 | |
Ville Syrjälä | 5aa5696 | 2016-06-22 21:57:00 +0300 | [diff] [blame] | 6237 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); |
| 6238 | if (ret) |
| 6239 | intel_dp_check_mst_status(&intel_dig_port->dp); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6240 | } |
| 6241 | } |