Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2014 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 |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 24 | /** |
| 25 | * DOC: Panel Self Refresh (PSR/SRD) |
| 26 | * |
| 27 | * Since Haswell Display controller supports Panel Self-Refresh on display |
| 28 | * panels witch have a remote frame buffer (RFB) implemented according to PSR |
| 29 | * spec in eDP1.3. PSR feature allows the display to go to lower standby states |
| 30 | * when system is idle but display is on as it eliminates display refresh |
| 31 | * request to DDR memory completely as long as the frame buffer for that |
| 32 | * display is unchanged. |
| 33 | * |
| 34 | * Panel Self Refresh must be supported by both Hardware (source) and |
| 35 | * Panel (sink). |
| 36 | * |
| 37 | * PSR saves power by caching the framebuffer in the panel RFB, which allows us |
| 38 | * to power down the link and memory controller. For DSI panels the same idea |
| 39 | * is called "manual mode". |
| 40 | * |
| 41 | * The implementation uses the hardware-based PSR support which automatically |
| 42 | * enters/exits self-refresh mode. The hardware takes care of sending the |
| 43 | * required DP aux message and could even retrain the link (that part isn't |
| 44 | * enabled yet though). The hardware also keeps track of any frontbuffer |
| 45 | * changes to know when to exit self-refresh mode again. Unfortunately that |
| 46 | * part doesn't work too well, hence why the i915 PSR support uses the |
| 47 | * software frontbuffer tracking to make sure it doesn't miss a screen |
| 48 | * update. For this integration intel_psr_invalidate() and intel_psr_flush() |
| 49 | * get called by the frontbuffer tracking code. Note that because of locking |
| 50 | * issues the self-refresh re-enable code is done from a work queue, which |
| 51 | * must be correctly synchronized/cancelled when shutting down the pipe." |
| 52 | */ |
| 53 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 54 | #include <drm/drmP.h> |
| 55 | |
| 56 | #include "intel_drv.h" |
| 57 | #include "i915_drv.h" |
| 58 | |
| 59 | static bool is_edp_psr(struct intel_dp *intel_dp) |
| 60 | { |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 61 | if (!intel_dp_is_edp(intel_dp)) |
| 62 | return false; |
| 63 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 64 | return intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED; |
| 65 | } |
| 66 | |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 67 | static bool vlv_is_psr_active_on_pipe(struct drm_device *dev, int pipe) |
| 68 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 69 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 70 | uint32_t val; |
| 71 | |
| 72 | val = I915_READ(VLV_PSRSTAT(pipe)) & |
| 73 | VLV_EDP_PSR_CURR_STATE_MASK; |
| 74 | return (val == VLV_EDP_PSR_ACTIVE_NORFB_UP) || |
| 75 | (val == VLV_EDP_PSR_ACTIVE_SF_UPDATE); |
| 76 | } |
| 77 | |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 78 | static void vlv_psr_setup_vsc(struct intel_dp *intel_dp, |
| 79 | const struct intel_crtc_state *crtc_state) |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 80 | { |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 81 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 82 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 83 | uint32_t val; |
| 84 | |
| 85 | /* VLV auto-generate VSC package as per EDP 1.3 spec, Table 3.10 */ |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 86 | val = I915_READ(VLV_VSCSDP(crtc->pipe)); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 87 | val &= ~VLV_EDP_PSR_SDP_FREQ_MASK; |
| 88 | val |= VLV_EDP_PSR_SDP_FREQ_EVFRAME; |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 89 | I915_WRITE(VLV_VSCSDP(crtc->pipe), val); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Rodrigo Vivi | 2ce4df8 | 2017-09-07 16:00:35 -0700 | [diff] [blame] | 92 | static void hsw_psr_setup_vsc(struct intel_dp *intel_dp, |
| 93 | const struct intel_crtc_state *crtc_state) |
Sonika Jindal | 474d1ec | 2015-04-02 11:02:44 +0530 | [diff] [blame] | 94 | { |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 95 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 96 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
| 97 | struct edp_vsc_psr psr_vsc; |
Sonika Jindal | 474d1ec | 2015-04-02 11:02:44 +0530 | [diff] [blame] | 98 | |
Rodrigo Vivi | 2ce4df8 | 2017-09-07 16:00:35 -0700 | [diff] [blame] | 99 | if (dev_priv->psr.psr2_support) { |
| 100 | /* Prepare VSC Header for SU as per EDP 1.4 spec, Table 6.11 */ |
| 101 | memset(&psr_vsc, 0, sizeof(psr_vsc)); |
| 102 | psr_vsc.sdp_header.HB0 = 0; |
| 103 | psr_vsc.sdp_header.HB1 = 0x7; |
| 104 | if (dev_priv->psr.colorimetry_support && |
| 105 | dev_priv->psr.y_cord_support) { |
| 106 | psr_vsc.sdp_header.HB2 = 0x5; |
| 107 | psr_vsc.sdp_header.HB3 = 0x13; |
| 108 | } else if (dev_priv->psr.y_cord_support) { |
| 109 | psr_vsc.sdp_header.HB2 = 0x4; |
| 110 | psr_vsc.sdp_header.HB3 = 0xe; |
| 111 | } else { |
| 112 | psr_vsc.sdp_header.HB2 = 0x3; |
| 113 | psr_vsc.sdp_header.HB3 = 0xc; |
| 114 | } |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 115 | } else { |
Rodrigo Vivi | 2ce4df8 | 2017-09-07 16:00:35 -0700 | [diff] [blame] | 116 | /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */ |
| 117 | memset(&psr_vsc, 0, sizeof(psr_vsc)); |
| 118 | psr_vsc.sdp_header.HB0 = 0; |
| 119 | psr_vsc.sdp_header.HB1 = 0x7; |
| 120 | psr_vsc.sdp_header.HB2 = 0x2; |
| 121 | psr_vsc.sdp_header.HB3 = 0x8; |
Nagaraju, Vathsala | 97da2ef | 2017-01-02 17:00:55 +0530 | [diff] [blame] | 122 | } |
| 123 | |
Ville Syrjälä | 1d77653 | 2017-10-13 22:40:51 +0300 | [diff] [blame] | 124 | intel_dig_port->write_infoframe(&intel_dig_port->base.base, crtc_state, |
| 125 | DP_SDP_VSC, &psr_vsc, sizeof(psr_vsc)); |
Sonika Jindal | 474d1ec | 2015-04-02 11:02:44 +0530 | [diff] [blame] | 126 | } |
| 127 | |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 128 | static void vlv_psr_enable_sink(struct intel_dp *intel_dp) |
| 129 | { |
| 130 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, |
Durgadoss R | 670b90d | 2015-03-27 17:21:32 +0530 | [diff] [blame] | 131 | DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 134 | static i915_reg_t psr_aux_ctl_reg(struct drm_i915_private *dev_priv, |
| 135 | enum port port) |
Ville Syrjälä | 1f38089 | 2015-11-11 20:34:16 +0200 | [diff] [blame] | 136 | { |
| 137 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 138 | return DP_AUX_CH_CTL(port); |
| 139 | else |
| 140 | return EDP_PSR_AUX_CTL; |
| 141 | } |
| 142 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 143 | static i915_reg_t psr_aux_data_reg(struct drm_i915_private *dev_priv, |
| 144 | enum port port, int index) |
Ville Syrjälä | 1f38089 | 2015-11-11 20:34:16 +0200 | [diff] [blame] | 145 | { |
| 146 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 147 | return DP_AUX_CH_DATA(port, index); |
| 148 | else |
| 149 | return EDP_PSR_AUX_DATA(index); |
| 150 | } |
| 151 | |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 152 | static void hsw_psr_enable_sink(struct intel_dp *intel_dp) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 153 | { |
| 154 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 155 | struct drm_device *dev = dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 156 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 157 | uint32_t aux_clock_divider; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 158 | i915_reg_t aux_ctl_reg; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 159 | static const uint8_t aux_msg[] = { |
| 160 | [0] = DP_AUX_NATIVE_WRITE << 4, |
| 161 | [1] = DP_SET_POWER >> 8, |
| 162 | [2] = DP_SET_POWER & 0xff, |
| 163 | [3] = 1 - 1, |
| 164 | [4] = DP_SET_POWER_D0, |
| 165 | }; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 166 | enum port port = dig_port->base.port; |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 167 | u32 aux_ctl; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 168 | int i; |
| 169 | |
| 170 | BUILD_BUG_ON(sizeof(aux_msg) > 20); |
| 171 | |
| 172 | aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0); |
| 173 | |
Sonika Jindal | 474d1ec | 2015-04-02 11:02:44 +0530 | [diff] [blame] | 174 | /* Enable AUX frame sync at sink */ |
| 175 | if (dev_priv->psr.aux_frame_sync) |
| 176 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 177 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF, |
| 178 | DP_AUX_FRAME_SYNC_ENABLE); |
Nagaraju, Vathsala | 340c93c | 2017-01-02 17:00:58 +0530 | [diff] [blame] | 179 | /* Enable ALPM at sink for psr2 */ |
| 180 | if (dev_priv->psr.psr2_support && dev_priv->psr.alpm) |
| 181 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 182 | DP_RECEIVER_ALPM_CONFIG, |
| 183 | DP_ALPM_ENABLE); |
Daniel Vetter | 6f32ea7 | 2016-05-18 18:47:14 +0200 | [diff] [blame] | 184 | if (dev_priv->psr.link_standby) |
| 185 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, |
| 186 | DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE); |
| 187 | else |
| 188 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, |
| 189 | DP_PSR_ENABLE); |
| 190 | |
Ville Syrjälä | 1f38089 | 2015-11-11 20:34:16 +0200 | [diff] [blame] | 191 | aux_ctl_reg = psr_aux_ctl_reg(dev_priv, port); |
Sonika Jindal | e3d9984 | 2015-01-22 14:30:54 +0530 | [diff] [blame] | 192 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 193 | /* Setup AUX registers */ |
| 194 | for (i = 0; i < sizeof(aux_msg); i += 4) |
Ville Syrjälä | 1f38089 | 2015-11-11 20:34:16 +0200 | [diff] [blame] | 195 | I915_WRITE(psr_aux_data_reg(dev_priv, port, i >> 2), |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 196 | intel_dp_pack_aux(&aux_msg[i], sizeof(aux_msg) - i)); |
| 197 | |
Daniel Vetter | d4dcbdc | 2016-05-18 18:47:15 +0200 | [diff] [blame] | 198 | aux_ctl = intel_dp->get_aux_send_ctl(intel_dp, 0, sizeof(aux_msg), |
| 199 | aux_clock_divider); |
| 200 | I915_WRITE(aux_ctl_reg, aux_ctl); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 203 | static void vlv_psr_enable_source(struct intel_dp *intel_dp, |
| 204 | const struct intel_crtc_state *crtc_state) |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 205 | { |
| 206 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 207 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
| 208 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 209 | |
Rodrigo Vivi | 0d0c279 | 2017-09-12 11:30:59 -0700 | [diff] [blame] | 210 | /* Transition from PSR_state 0 (disabled) to PSR_state 1 (inactive) */ |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 211 | I915_WRITE(VLV_PSRCTL(crtc->pipe), |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 212 | VLV_EDP_PSR_MODE_SW_TIMER | |
| 213 | VLV_EDP_PSR_SRC_TRANSMITTER_STATE | |
| 214 | VLV_EDP_PSR_ENABLE); |
| 215 | } |
| 216 | |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 217 | static void vlv_psr_activate(struct intel_dp *intel_dp) |
| 218 | { |
| 219 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 220 | struct drm_device *dev = dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 221 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 222 | struct drm_crtc *crtc = dig_port->base.base.crtc; |
| 223 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
| 224 | |
Rodrigo Vivi | 0d0c279 | 2017-09-12 11:30:59 -0700 | [diff] [blame] | 225 | /* |
| 226 | * Let's do the transition from PSR_state 1 (inactive) to |
| 227 | * PSR_state 2 (transition to active - static frame transmission). |
| 228 | * Then Hardware is responsible for the transition to |
| 229 | * PSR_state 3 (active - no Remote Frame Buffer (RFB) update). |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 230 | */ |
| 231 | I915_WRITE(VLV_PSRCTL(pipe), I915_READ(VLV_PSRCTL(pipe)) | |
| 232 | VLV_EDP_PSR_ACTIVE_ENTRY); |
| 233 | } |
| 234 | |
Rodrigo Vivi | ed63d24 | 2017-09-07 16:00:33 -0700 | [diff] [blame] | 235 | static void hsw_activate_psr1(struct intel_dp *intel_dp) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 236 | { |
| 237 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 238 | struct drm_device *dev = dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 239 | struct drm_i915_private *dev_priv = to_i915(dev); |
Sonika Jindal | 474d1ec | 2015-04-02 11:02:44 +0530 | [diff] [blame] | 240 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 241 | uint32_t max_sleep_time = 0x1f; |
Rodrigo Vivi | 40918e0 | 2016-09-07 17:42:31 -0700 | [diff] [blame] | 242 | /* |
| 243 | * Let's respect VBT in case VBT asks a higher idle_frame value. |
| 244 | * Let's use 6 as the minimum to cover all known cases including |
| 245 | * the off-by-one issue that HW has in some cases. Also there are |
| 246 | * cases where sink should be able to train |
| 247 | * with the 5 or 6 idle patterns. |
Rodrigo Vivi | d44b4dc | 2014-11-14 08:52:31 -0800 | [diff] [blame] | 248 | */ |
Rodrigo Vivi | 40918e0 | 2016-09-07 17:42:31 -0700 | [diff] [blame] | 249 | uint32_t idle_frames = max(6, dev_priv->vbt.psr.idle_frames); |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 250 | uint32_t val = EDP_PSR_ENABLE; |
| 251 | |
| 252 | val |= max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT; |
| 253 | val |= idle_frames << EDP_PSR_IDLE_FRAME_SHIFT; |
Rodrigo Vivi | 7370c68 | 2015-12-11 16:31:31 -0800 | [diff] [blame] | 254 | |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 255 | if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 7370c68 | 2015-12-11 16:31:31 -0800 | [diff] [blame] | 256 | val |= EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 257 | |
Rodrigo Vivi | 60e5ffe | 2016-02-01 12:02:07 -0800 | [diff] [blame] | 258 | if (dev_priv->psr.link_standby) |
| 259 | val |= EDP_PSR_LINK_STANDBY; |
| 260 | |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 261 | if (dev_priv->vbt.psr.tp1_wakeup_time > 5) |
| 262 | val |= EDP_PSR_TP1_TIME_2500us; |
| 263 | else if (dev_priv->vbt.psr.tp1_wakeup_time > 1) |
| 264 | val |= EDP_PSR_TP1_TIME_500us; |
| 265 | else if (dev_priv->vbt.psr.tp1_wakeup_time > 0) |
| 266 | val |= EDP_PSR_TP1_TIME_100us; |
| 267 | else |
| 268 | val |= EDP_PSR_TP1_TIME_0us; |
Sonika Jindal | 474d1ec | 2015-04-02 11:02:44 +0530 | [diff] [blame] | 269 | |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 270 | if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 5) |
| 271 | val |= EDP_PSR_TP2_TP3_TIME_2500us; |
| 272 | else if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 1) |
| 273 | val |= EDP_PSR_TP2_TP3_TIME_500us; |
| 274 | else if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 0) |
| 275 | val |= EDP_PSR_TP2_TP3_TIME_100us; |
| 276 | else |
| 277 | val |= EDP_PSR_TP2_TP3_TIME_0us; |
| 278 | |
| 279 | if (intel_dp_source_supports_hbr2(intel_dp) && |
| 280 | drm_dp_tps3_supported(intel_dp->dpcd)) |
| 281 | val |= EDP_PSR_TP1_TP3_SEL; |
| 282 | else |
| 283 | val |= EDP_PSR_TP1_TP2_SEL; |
| 284 | |
Jim Bride | 912d641 | 2017-08-08 14:51:34 -0700 | [diff] [blame] | 285 | val |= I915_READ(EDP_PSR_CTL) & EDP_PSR_RESTORE_PSR_ACTIVE_CTX_MASK; |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 286 | I915_WRITE(EDP_PSR_CTL, val); |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 287 | } |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 288 | |
Rodrigo Vivi | ed63d24 | 2017-09-07 16:00:33 -0700 | [diff] [blame] | 289 | static void hsw_activate_psr2(struct intel_dp *intel_dp) |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 290 | { |
| 291 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 292 | struct drm_device *dev = dig_port->base.base.dev; |
| 293 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 294 | /* |
| 295 | * Let's respect VBT in case VBT asks a higher idle_frame value. |
| 296 | * Let's use 6 as the minimum to cover all known cases including |
| 297 | * the off-by-one issue that HW has in some cases. Also there are |
| 298 | * cases where sink should be able to train |
| 299 | * with the 5 or 6 idle patterns. |
| 300 | */ |
| 301 | uint32_t idle_frames = max(6, dev_priv->vbt.psr.idle_frames); |
| 302 | uint32_t val; |
vathsala nagaraju | 977da08 | 2017-09-26 15:29:13 +0530 | [diff] [blame] | 303 | uint8_t sink_latency; |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 304 | |
| 305 | val = idle_frames << EDP_PSR_IDLE_FRAME_SHIFT; |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 306 | |
| 307 | /* FIXME: selective update is probably totally broken because it doesn't |
| 308 | * mesh at all with our frontbuffer tracking. And the hw alone isn't |
| 309 | * good enough. */ |
Nagaraju, Vathsala | 6433226 | 2017-01-13 06:01:24 +0530 | [diff] [blame] | 310 | val |= EDP_PSR2_ENABLE | |
vathsala nagaraju | 977da08 | 2017-09-26 15:29:13 +0530 | [diff] [blame] | 311 | EDP_SU_TRACK_ENABLE; |
| 312 | |
| 313 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
| 314 | DP_SYNCHRONIZATION_LATENCY_IN_SINK, |
| 315 | &sink_latency) == 1) { |
| 316 | sink_latency &= DP_MAX_RESYNC_FRAME_COUNT_MASK; |
| 317 | } else { |
| 318 | sink_latency = 0; |
| 319 | } |
| 320 | val |= EDP_PSR2_FRAME_BEFORE_SU(sink_latency + 1); |
Daniel Vetter | 50db139 | 2016-05-18 18:47:11 +0200 | [diff] [blame] | 321 | |
| 322 | if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 5) |
| 323 | val |= EDP_PSR2_TP2_TIME_2500; |
| 324 | else if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 1) |
| 325 | val |= EDP_PSR2_TP2_TIME_500; |
| 326 | else if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 0) |
| 327 | val |= EDP_PSR2_TP2_TIME_100; |
| 328 | else |
| 329 | val |= EDP_PSR2_TP2_TIME_50; |
| 330 | |
| 331 | I915_WRITE(EDP_PSR2_CTL, val); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Rodrigo Vivi | ed63d24 | 2017-09-07 16:00:33 -0700 | [diff] [blame] | 334 | static void hsw_psr_activate(struct intel_dp *intel_dp) |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 335 | { |
| 336 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 337 | struct drm_device *dev = dig_port->base.base.dev; |
| 338 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 339 | |
Rodrigo Vivi | ed63d24 | 2017-09-07 16:00:33 -0700 | [diff] [blame] | 340 | /* On HSW+ after we enable PSR on source it will activate it |
| 341 | * as soon as it match configure idle_frame count. So |
| 342 | * we just actually enable it here on activation time. |
| 343 | */ |
| 344 | |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 345 | /* psr1 and psr2 are mutually exclusive.*/ |
| 346 | if (dev_priv->psr.psr2_support) |
Rodrigo Vivi | ed63d24 | 2017-09-07 16:00:33 -0700 | [diff] [blame] | 347 | hsw_activate_psr2(intel_dp); |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 348 | else |
Rodrigo Vivi | ed63d24 | 2017-09-07 16:00:33 -0700 | [diff] [blame] | 349 | hsw_activate_psr1(intel_dp); |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 350 | } |
| 351 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 352 | void intel_psr_compute_config(struct intel_dp *intel_dp, |
| 353 | struct intel_crtc_state *crtc_state) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 354 | { |
| 355 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 356 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); |
Ville Syrjälä | dfd2e9a | 2016-05-18 11:34:38 +0300 | [diff] [blame] | 357 | const struct drm_display_mode *adjusted_mode = |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 358 | &crtc_state->base.adjusted_mode; |
Ville Syrjälä | dfd2e9a | 2016-05-18 11:34:38 +0300 | [diff] [blame] | 359 | int psr_setup_time; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 360 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 361 | if (!HAS_PSR(dev_priv)) |
| 362 | return; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 363 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 364 | if (!is_edp_psr(intel_dp)) |
| 365 | return; |
| 366 | |
| 367 | if (!i915_modparams.enable_psr) { |
| 368 | DRM_DEBUG_KMS("PSR disable by flag\n"); |
| 369 | return; |
| 370 | } |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 371 | |
Rodrigo Vivi | dc9b5a0 | 2016-02-01 12:02:06 -0800 | [diff] [blame] | 372 | /* |
| 373 | * HSW spec explicitly says PSR is tied to port A. |
| 374 | * BDW+ platforms with DDI implementation of PSR have different |
| 375 | * PSR registers per transcoder and we only implement transcoder EDP |
| 376 | * ones. Since by Display design transcoder EDP is tied to port A |
| 377 | * we can safely escape based on the port A. |
| 378 | */ |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 379 | if (HAS_DDI(dev_priv) && dig_port->base.port != PORT_A) { |
Rodrigo Vivi | dc9b5a0 | 2016-02-01 12:02:06 -0800 | [diff] [blame] | 380 | DRM_DEBUG_KMS("PSR condition failed: Port not supported\n"); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 381 | return; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 384 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Rodrigo Vivi | 65f61b4 | 2016-02-01 12:02:08 -0800 | [diff] [blame] | 385 | !dev_priv->psr.link_standby) { |
| 386 | DRM_ERROR("PSR condition failed: Link off requested but not supported on this platform\n"); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 387 | return; |
Rodrigo Vivi | 65f61b4 | 2016-02-01 12:02:08 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 390 | if (IS_HASWELL(dev_priv) && |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 391 | I915_READ(HSW_STEREO_3D_CTL(crtc_state->cpu_transcoder)) & |
Rodrigo Vivi | c8e68b7 | 2015-01-12 10:14:29 -0800 | [diff] [blame] | 392 | S3D_ENABLE) { |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 393 | DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n"); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 394 | return; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 397 | if (IS_HASWELL(dev_priv) && |
Ville Syrjälä | dfd2e9a | 2016-05-18 11:34:38 +0300 | [diff] [blame] | 398 | adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 399 | DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n"); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 400 | return; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Ville Syrjälä | dfd2e9a | 2016-05-18 11:34:38 +0300 | [diff] [blame] | 403 | psr_setup_time = drm_dp_psr_setup_time(intel_dp->psr_dpcd); |
| 404 | if (psr_setup_time < 0) { |
| 405 | DRM_DEBUG_KMS("PSR condition failed: Invalid PSR setup time (0x%02x)\n", |
| 406 | intel_dp->psr_dpcd[1]); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 407 | return; |
Ville Syrjälä | dfd2e9a | 2016-05-18 11:34:38 +0300 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | if (intel_usecs_to_scanlines(adjusted_mode, psr_setup_time) > |
| 411 | adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vdisplay - 1) { |
| 412 | DRM_DEBUG_KMS("PSR condition failed: PSR setup time (%d us) too long\n", |
| 413 | psr_setup_time); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 414 | return; |
| 415 | } |
| 416 | |
| 417 | /* |
| 418 | * FIXME psr2_support is messed up. It's both computed |
| 419 | * dynamically during PSR enable, and extracted from sink |
| 420 | * caps during eDP detection. |
| 421 | */ |
| 422 | if (!dev_priv->psr.psr2_support) { |
| 423 | crtc_state->has_psr = true; |
| 424 | return; |
Ville Syrjälä | dfd2e9a | 2016-05-18 11:34:38 +0300 | [diff] [blame] | 425 | } |
| 426 | |
Nagaraju, Vathsala | acf45d1 | 2017-01-10 12:32:26 +0530 | [diff] [blame] | 427 | /* PSR2 is restricted to work with panel resolutions upto 3200x2000 */ |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 428 | if (adjusted_mode->crtc_hdisplay > 3200 || |
| 429 | adjusted_mode->crtc_vdisplay > 2000) { |
| 430 | DRM_DEBUG_KMS("PSR2 disabled, panel resolution too big\n"); |
| 431 | return; |
Nagaraju, Vathsala | acf45d1 | 2017-01-10 12:32:26 +0530 | [diff] [blame] | 432 | } |
| 433 | |
Nagaraju, Vathsala | 18b9bf3 | 2017-01-12 03:58:30 +0530 | [diff] [blame] | 434 | /* |
| 435 | * FIXME:enable psr2 only for y-cordinate psr2 panels |
| 436 | * After gtc implementation , remove this restriction. |
| 437 | */ |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 438 | if (!dev_priv->psr.y_cord_support) { |
Nagaraju, Vathsala | 18b9bf3 | 2017-01-12 03:58:30 +0530 | [diff] [blame] | 439 | DRM_DEBUG_KMS("PSR2 disabled, panel does not support Y coordinate\n"); |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 440 | return; |
Nagaraju, Vathsala | 18b9bf3 | 2017-01-12 03:58:30 +0530 | [diff] [blame] | 441 | } |
| 442 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 443 | crtc_state->has_psr = true; |
| 444 | crtc_state->has_psr2 = true; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 447 | static void intel_psr_activate(struct intel_dp *intel_dp) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 448 | { |
| 449 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 450 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 451 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 452 | |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 453 | if (dev_priv->psr.psr2_support) |
| 454 | WARN_ON(I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE); |
| 455 | else |
| 456 | WARN_ON(I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 457 | WARN_ON(dev_priv->psr.active); |
| 458 | lockdep_assert_held(&dev_priv->psr.lock); |
| 459 | |
Rodrigo Vivi | e3702ac | 2017-09-07 16:00:34 -0700 | [diff] [blame] | 460 | dev_priv->psr.activate(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 461 | dev_priv->psr.active = true; |
| 462 | } |
| 463 | |
Rodrigo Vivi | 4d1fa22 | 2017-09-07 16:00:36 -0700 | [diff] [blame] | 464 | static void hsw_psr_enable_source(struct intel_dp *intel_dp, |
| 465 | const struct intel_crtc_state *crtc_state) |
| 466 | { |
| 467 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 468 | struct drm_device *dev = dig_port->base.base.dev; |
| 469 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 470 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 471 | u32 chicken; |
| 472 | |
| 473 | if (dev_priv->psr.psr2_support) { |
| 474 | chicken = PSR2_VSC_ENABLE_PROG_HEADER; |
| 475 | if (dev_priv->psr.y_cord_support) |
| 476 | chicken |= PSR2_ADD_VERTICAL_LINE_COUNT; |
| 477 | I915_WRITE(CHICKEN_TRANS(cpu_transcoder), chicken); |
| 478 | |
| 479 | I915_WRITE(EDP_PSR_DEBUG_CTL, |
| 480 | EDP_PSR_DEBUG_MASK_MEMUP | |
| 481 | EDP_PSR_DEBUG_MASK_HPD | |
| 482 | EDP_PSR_DEBUG_MASK_LPSP | |
| 483 | EDP_PSR_DEBUG_MASK_MAX_SLEEP | |
| 484 | EDP_PSR_DEBUG_MASK_DISP_REG_WRITE); |
| 485 | } else { |
| 486 | /* |
| 487 | * Per Spec: Avoid continuous PSR exit by masking MEMUP |
| 488 | * and HPD. also mask LPSP to avoid dependency on other |
| 489 | * drivers that might block runtime_pm besides |
| 490 | * preventing other hw tracking issues now we can rely |
| 491 | * on frontbuffer tracking. |
| 492 | */ |
| 493 | I915_WRITE(EDP_PSR_DEBUG_CTL, |
| 494 | EDP_PSR_DEBUG_MASK_MEMUP | |
| 495 | EDP_PSR_DEBUG_MASK_HPD | |
| 496 | EDP_PSR_DEBUG_MASK_LPSP); |
| 497 | } |
| 498 | } |
| 499 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 500 | /** |
| 501 | * intel_psr_enable - Enable PSR |
| 502 | * @intel_dp: Intel DP |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 503 | * @crtc_state: new CRTC state |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 504 | * |
| 505 | * This function can only be called after the pipe is fully trained and enabled. |
| 506 | */ |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 507 | void intel_psr_enable(struct intel_dp *intel_dp, |
| 508 | const struct intel_crtc_state *crtc_state) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 509 | { |
| 510 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 511 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 512 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 513 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 514 | if (!crtc_state->has_psr) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 515 | return; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 516 | |
Radhakrishna Sripada | da83ef8 | 2017-09-14 11:16:41 -0700 | [diff] [blame] | 517 | WARN_ON(dev_priv->drrs.dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 518 | mutex_lock(&dev_priv->psr.lock); |
| 519 | if (dev_priv->psr.enabled) { |
| 520 | DRM_DEBUG_KMS("PSR already in use\n"); |
| 521 | goto unlock; |
| 522 | } |
| 523 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 524 | dev_priv->psr.psr2_support = crtc_state->has_psr2; |
| 525 | dev_priv->psr.source_ok = true; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 526 | |
| 527 | dev_priv->psr.busy_frontbuffer_bits = 0; |
| 528 | |
Rodrigo Vivi | 2a5db87 | 2017-09-07 16:00:39 -0700 | [diff] [blame] | 529 | dev_priv->psr.setup_vsc(intel_dp, crtc_state); |
Rodrigo Vivi | 49ad316 | 2017-09-07 16:00:40 -0700 | [diff] [blame] | 530 | dev_priv->psr.enable_sink(intel_dp); |
Rodrigo Vivi | d0d5e0d | 2017-09-07 16:00:41 -0700 | [diff] [blame] | 531 | dev_priv->psr.enable_source(intel_dp, crtc_state); |
Rodrigo Vivi | 29d1efe | 2017-09-07 16:00:38 -0700 | [diff] [blame] | 532 | dev_priv->psr.enabled = intel_dp; |
| 533 | |
| 534 | if (INTEL_GEN(dev_priv) >= 9) { |
| 535 | intel_psr_activate(intel_dp); |
| 536 | } else { |
| 537 | /* |
| 538 | * FIXME: Activation should happen immediately since this |
| 539 | * function is just called after pipe is fully trained and |
| 540 | * enabled. |
| 541 | * However on some platforms we face issues when first |
| 542 | * activation follows a modeset so quickly. |
| 543 | * - On VLV/CHV we get bank screen on first activation |
| 544 | * - On HSW/BDW we get a recoverable frozen screen until |
| 545 | * next exit-activate sequence. |
| 546 | */ |
Rodrigo Vivi | d0ac896 | 2015-11-11 11:37:07 -0800 | [diff] [blame] | 547 | schedule_delayed_work(&dev_priv->psr.work, |
| 548 | msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5)); |
Rodrigo Vivi | 29d1efe | 2017-09-07 16:00:38 -0700 | [diff] [blame] | 549 | } |
Rodrigo Vivi | d0ac896 | 2015-11-11 11:37:07 -0800 | [diff] [blame] | 550 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 551 | unlock: |
| 552 | mutex_unlock(&dev_priv->psr.lock); |
| 553 | } |
| 554 | |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 555 | static void vlv_psr_disable(struct intel_dp *intel_dp, |
| 556 | const struct intel_crtc_state *old_crtc_state) |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 557 | { |
| 558 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 559 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 560 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 561 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 562 | uint32_t val; |
| 563 | |
| 564 | if (dev_priv->psr.active) { |
Rodrigo Vivi | 0d0c279 | 2017-09-12 11:30:59 -0700 | [diff] [blame] | 565 | /* Put VLV PSR back to PSR_state 0 (disabled). */ |
Chris Wilson | eb0241c | 2016-06-30 15:33:26 +0100 | [diff] [blame] | 566 | if (intel_wait_for_register(dev_priv, |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 567 | VLV_PSRSTAT(crtc->pipe), |
Chris Wilson | eb0241c | 2016-06-30 15:33:26 +0100 | [diff] [blame] | 568 | VLV_EDP_PSR_IN_TRANS, |
| 569 | 0, |
| 570 | 1)) |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 571 | WARN(1, "PSR transition took longer than expected\n"); |
| 572 | |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 573 | val = I915_READ(VLV_PSRCTL(crtc->pipe)); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 574 | val &= ~VLV_EDP_PSR_ACTIVE_ENTRY; |
| 575 | val &= ~VLV_EDP_PSR_ENABLE; |
| 576 | val &= ~VLV_EDP_PSR_MODE_MASK; |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 577 | I915_WRITE(VLV_PSRCTL(crtc->pipe), val); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 578 | |
| 579 | dev_priv->psr.active = false; |
| 580 | } else { |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 581 | WARN_ON(vlv_is_psr_active_on_pipe(dev, crtc->pipe)); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 585 | static void hsw_psr_disable(struct intel_dp *intel_dp, |
| 586 | const struct intel_crtc_state *old_crtc_state) |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 587 | { |
| 588 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 589 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 590 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 591 | |
| 592 | if (dev_priv->psr.active) { |
Dhinakaran Pandiyan | 14c6547 | 2017-12-19 20:35:20 -0800 | [diff] [blame] | 593 | i915_reg_t psr_status; |
Chris Wilson | 77affa3 | 2017-01-16 13:06:22 +0000 | [diff] [blame] | 594 | u32 psr_status_mask; |
| 595 | |
Nagaraju, Vathsala | f40c484 | 2017-01-11 20:44:33 +0530 | [diff] [blame] | 596 | if (dev_priv->psr.aux_frame_sync) |
| 597 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 598 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF, |
| 599 | 0); |
| 600 | |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 601 | if (dev_priv->psr.psr2_support) { |
Dhinakaran Pandiyan | 14c6547 | 2017-12-19 20:35:20 -0800 | [diff] [blame] | 602 | psr_status = EDP_PSR2_STATUS_CTL; |
Chris Wilson | 77affa3 | 2017-01-16 13:06:22 +0000 | [diff] [blame] | 603 | psr_status_mask = EDP_PSR2_STATUS_STATE_MASK; |
| 604 | |
Dhinakaran Pandiyan | 14c6547 | 2017-12-19 20:35:20 -0800 | [diff] [blame] | 605 | I915_WRITE(EDP_PSR2_CTL, |
| 606 | I915_READ(EDP_PSR2_CTL) & |
Chris Wilson | 77affa3 | 2017-01-16 13:06:22 +0000 | [diff] [blame] | 607 | ~(EDP_PSR2_ENABLE | EDP_SU_TRACK_ENABLE)); |
| 608 | |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 609 | } else { |
Dhinakaran Pandiyan | 14c6547 | 2017-12-19 20:35:20 -0800 | [diff] [blame] | 610 | psr_status = EDP_PSR_STATUS_CTL; |
Chris Wilson | 77affa3 | 2017-01-16 13:06:22 +0000 | [diff] [blame] | 611 | psr_status_mask = EDP_PSR_STATUS_STATE_MASK; |
| 612 | |
Dhinakaran Pandiyan | 14c6547 | 2017-12-19 20:35:20 -0800 | [diff] [blame] | 613 | I915_WRITE(EDP_PSR_CTL, |
| 614 | I915_READ(EDP_PSR_CTL) & ~EDP_PSR_ENABLE); |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 615 | } |
Chris Wilson | 77affa3 | 2017-01-16 13:06:22 +0000 | [diff] [blame] | 616 | |
| 617 | /* Wait till PSR is idle */ |
| 618 | if (intel_wait_for_register(dev_priv, |
Dhinakaran Pandiyan | 14c6547 | 2017-12-19 20:35:20 -0800 | [diff] [blame] | 619 | psr_status, psr_status_mask, 0, |
Chris Wilson | 77affa3 | 2017-01-16 13:06:22 +0000 | [diff] [blame] | 620 | 2000)) |
| 621 | DRM_ERROR("Timed out waiting for PSR Idle State\n"); |
| 622 | |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 623 | dev_priv->psr.active = false; |
| 624 | } else { |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 625 | if (dev_priv->psr.psr2_support) |
| 626 | WARN_ON(I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE); |
| 627 | else |
| 628 | WARN_ON(I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE); |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 632 | /** |
| 633 | * intel_psr_disable - Disable PSR |
| 634 | * @intel_dp: Intel DP |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 635 | * @old_crtc_state: old CRTC state |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 636 | * |
| 637 | * This function needs to be called before disabling pipe. |
| 638 | */ |
Ville Syrjälä | d2419ff | 2017-08-18 16:49:56 +0300 | [diff] [blame] | 639 | void intel_psr_disable(struct intel_dp *intel_dp, |
| 640 | const struct intel_crtc_state *old_crtc_state) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 641 | { |
| 642 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 643 | struct drm_device *dev = intel_dig_port->base.base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 644 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 645 | |
Ville Syrjälä | 4d90f2d | 2017-10-12 16:02:01 +0300 | [diff] [blame] | 646 | if (!old_crtc_state->has_psr) |
Rodrigo Vivi | 0f328da | 2017-09-07 16:00:31 -0700 | [diff] [blame] | 647 | return; |
| 648 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 649 | mutex_lock(&dev_priv->psr.lock); |
| 650 | if (!dev_priv->psr.enabled) { |
| 651 | mutex_unlock(&dev_priv->psr.lock); |
| 652 | return; |
| 653 | } |
| 654 | |
Rodrigo Vivi | 424644c | 2017-09-07 16:00:32 -0700 | [diff] [blame] | 655 | dev_priv->psr.disable_source(intel_dp, old_crtc_state); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 656 | |
Rodrigo Vivi | b6e4d53 | 2015-11-23 14:19:32 -0800 | [diff] [blame] | 657 | /* Disable PSR on Sink */ |
| 658 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, 0); |
| 659 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 660 | dev_priv->psr.enabled = NULL; |
| 661 | mutex_unlock(&dev_priv->psr.lock); |
| 662 | |
| 663 | cancel_delayed_work_sync(&dev_priv->psr.work); |
| 664 | } |
| 665 | |
| 666 | static void intel_psr_work(struct work_struct *work) |
| 667 | { |
| 668 | struct drm_i915_private *dev_priv = |
| 669 | container_of(work, typeof(*dev_priv), psr.work.work); |
| 670 | struct intel_dp *intel_dp = dev_priv->psr.enabled; |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 671 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 672 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 673 | |
| 674 | /* We have to make sure PSR is ready for re-enable |
| 675 | * otherwise it keeps disabled until next full enable/disable cycle. |
| 676 | * PSR might take some time to get fully disabled |
| 677 | * and be ready for re-enable. |
| 678 | */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 679 | if (HAS_DDI(dev_priv)) { |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 680 | if (dev_priv->psr.psr2_support) { |
| 681 | if (intel_wait_for_register(dev_priv, |
| 682 | EDP_PSR2_STATUS_CTL, |
| 683 | EDP_PSR2_STATUS_STATE_MASK, |
| 684 | 0, |
| 685 | 50)) { |
| 686 | DRM_ERROR("Timed out waiting for PSR2 Idle for re-enable\n"); |
| 687 | return; |
| 688 | } |
| 689 | } else { |
| 690 | if (intel_wait_for_register(dev_priv, |
| 691 | EDP_PSR_STATUS_CTL, |
| 692 | EDP_PSR_STATUS_STATE_MASK, |
| 693 | 0, |
| 694 | 50)) { |
| 695 | DRM_ERROR("Timed out waiting for PSR Idle for re-enable\n"); |
| 696 | return; |
| 697 | } |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 698 | } |
| 699 | } else { |
Chris Wilson | 12bb631 | 2016-06-30 15:33:28 +0100 | [diff] [blame] | 700 | if (intel_wait_for_register(dev_priv, |
| 701 | VLV_PSRSTAT(pipe), |
| 702 | VLV_EDP_PSR_IN_TRANS, |
| 703 | 0, |
| 704 | 1)) { |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 705 | DRM_ERROR("Timed out waiting for PSR Idle for re-enable\n"); |
| 706 | return; |
| 707 | } |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 708 | } |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 709 | mutex_lock(&dev_priv->psr.lock); |
| 710 | intel_dp = dev_priv->psr.enabled; |
| 711 | |
| 712 | if (!intel_dp) |
| 713 | goto unlock; |
| 714 | |
| 715 | /* |
| 716 | * The delayed work can race with an invalidate hence we need to |
| 717 | * recheck. Since psr_flush first clears this and then reschedules we |
| 718 | * won't ever miss a flush when bailing out here. |
| 719 | */ |
| 720 | if (dev_priv->psr.busy_frontbuffer_bits) |
| 721 | goto unlock; |
| 722 | |
Rodrigo Vivi | e2bbc34 | 2014-11-19 07:37:00 -0800 | [diff] [blame] | 723 | intel_psr_activate(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 724 | unlock: |
| 725 | mutex_unlock(&dev_priv->psr.lock); |
| 726 | } |
| 727 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 728 | static void intel_psr_exit(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 729 | { |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 730 | struct intel_dp *intel_dp = dev_priv->psr.enabled; |
| 731 | struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc; |
| 732 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
| 733 | u32 val; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 734 | |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 735 | if (!dev_priv->psr.active) |
| 736 | return; |
| 737 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 738 | if (HAS_DDI(dev_priv)) { |
Nagaraju, Vathsala | f40c484 | 2017-01-11 20:44:33 +0530 | [diff] [blame] | 739 | if (dev_priv->psr.aux_frame_sync) |
| 740 | drm_dp_dpcd_writeb(&intel_dp->aux, |
| 741 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF, |
| 742 | 0); |
Nagaraju, Vathsala | 3fcb0ca | 2017-01-12 23:30:59 +0530 | [diff] [blame] | 743 | if (dev_priv->psr.psr2_support) { |
| 744 | val = I915_READ(EDP_PSR2_CTL); |
| 745 | WARN_ON(!(val & EDP_PSR2_ENABLE)); |
| 746 | I915_WRITE(EDP_PSR2_CTL, val & ~EDP_PSR2_ENABLE); |
| 747 | } else { |
| 748 | val = I915_READ(EDP_PSR_CTL); |
| 749 | WARN_ON(!(val & EDP_PSR_ENABLE)); |
| 750 | I915_WRITE(EDP_PSR_CTL, val & ~EDP_PSR_ENABLE); |
| 751 | } |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 752 | } else { |
| 753 | val = I915_READ(VLV_PSRCTL(pipe)); |
| 754 | |
Rodrigo Vivi | 0d0c279 | 2017-09-12 11:30:59 -0700 | [diff] [blame] | 755 | /* |
| 756 | * Here we do the transition drirectly from |
| 757 | * PSR_state 3 (active - no Remote Frame Buffer (RFB) update) to |
| 758 | * PSR_state 5 (exit). |
| 759 | * PSR State 4 (active with single frame update) can be skipped. |
| 760 | * On PSR_state 5 (exit) Hardware is responsible to transition |
| 761 | * back to PSR_state 1 (inactive). |
| 762 | * Now we are at Same state after vlv_psr_enable_source. |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 763 | */ |
| 764 | val &= ~VLV_EDP_PSR_ACTIVE_ENTRY; |
| 765 | I915_WRITE(VLV_PSRCTL(pipe), val); |
| 766 | |
Rodrigo Vivi | 0d0c279 | 2017-09-12 11:30:59 -0700 | [diff] [blame] | 767 | /* |
| 768 | * Send AUX wake up - Spec says after transitioning to PSR |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 769 | * active we have to send AUX wake up by writing 01h in DPCD |
| 770 | * 600h of sink device. |
| 771 | * XXX: This might slow down the transition, but without this |
| 772 | * HW doesn't complete the transition to PSR_state 1 and we |
| 773 | * never get the screen updated. |
| 774 | */ |
| 775 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
| 776 | DP_SET_POWER_D0); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 779 | dev_priv->psr.active = false; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 782 | /** |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 783 | * intel_psr_single_frame_update - Single Frame Update |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 784 | * @dev_priv: i915 device |
Daniel Vetter | 20c8838 | 2015-06-18 10:30:27 +0200 | [diff] [blame] | 785 | * @frontbuffer_bits: frontbuffer plane tracking bits |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 786 | * |
| 787 | * Some platforms support a single frame update feature that is used to |
| 788 | * send and update only one frame on Remote Frame Buffer. |
| 789 | * So far it is only implemented for Valleyview and Cherryview because |
| 790 | * hardware requires this to be done before a page flip. |
| 791 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 792 | void intel_psr_single_frame_update(struct drm_i915_private *dev_priv, |
Daniel Vetter | 20c8838 | 2015-06-18 10:30:27 +0200 | [diff] [blame] | 793 | unsigned frontbuffer_bits) |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 794 | { |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 795 | struct drm_crtc *crtc; |
| 796 | enum pipe pipe; |
| 797 | u32 val; |
| 798 | |
Rodrigo Vivi | 0f328da | 2017-09-07 16:00:31 -0700 | [diff] [blame] | 799 | if (!HAS_PSR(dev_priv)) |
| 800 | return; |
| 801 | |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 802 | /* |
| 803 | * Single frame update is already supported on BDW+ but it requires |
| 804 | * many W/A and it isn't really needed. |
| 805 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 806 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 807 | return; |
| 808 | |
| 809 | mutex_lock(&dev_priv->psr.lock); |
| 810 | if (!dev_priv->psr.enabled) { |
| 811 | mutex_unlock(&dev_priv->psr.lock); |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc; |
| 816 | pipe = to_intel_crtc(crtc)->pipe; |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 817 | |
Daniel Vetter | 20c8838 | 2015-06-18 10:30:27 +0200 | [diff] [blame] | 818 | if (frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)) { |
| 819 | val = I915_READ(VLV_PSRCTL(pipe)); |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 820 | |
Daniel Vetter | 20c8838 | 2015-06-18 10:30:27 +0200 | [diff] [blame] | 821 | /* |
| 822 | * We need to set this bit before writing registers for a flip. |
| 823 | * This bit will be self-clear when it gets to the PSR active state. |
| 824 | */ |
| 825 | I915_WRITE(VLV_PSRCTL(pipe), val | VLV_EDP_PSR_SINGLE_FRAME_UPDATE); |
| 826 | } |
Rodrigo Vivi | c7240c3 | 2015-04-10 11:15:10 -0700 | [diff] [blame] | 827 | mutex_unlock(&dev_priv->psr.lock); |
| 828 | } |
| 829 | |
| 830 | /** |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 831 | * intel_psr_invalidate - Invalidade PSR |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 832 | * @dev_priv: i915 device |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 833 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 834 | * |
| 835 | * Since the hardware frontbuffer tracking has gaps we need to integrate |
| 836 | * with the software frontbuffer tracking. This function gets called every |
| 837 | * time frontbuffer rendering starts and a buffer gets dirtied. PSR must be |
| 838 | * disabled if the frontbuffer mask contains a buffer relevant to PSR. |
| 839 | * |
| 840 | * Dirty frontbuffers relevant to PSR are tracked in busy_frontbuffer_bits." |
| 841 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 842 | void intel_psr_invalidate(struct drm_i915_private *dev_priv, |
Daniel Vetter | 20c8838 | 2015-06-18 10:30:27 +0200 | [diff] [blame] | 843 | unsigned frontbuffer_bits) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 844 | { |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 845 | struct drm_crtc *crtc; |
| 846 | enum pipe pipe; |
| 847 | |
Rodrigo Vivi | 0f328da | 2017-09-07 16:00:31 -0700 | [diff] [blame] | 848 | if (!HAS_PSR(dev_priv)) |
| 849 | return; |
| 850 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 851 | mutex_lock(&dev_priv->psr.lock); |
| 852 | if (!dev_priv->psr.enabled) { |
| 853 | mutex_unlock(&dev_priv->psr.lock); |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc; |
| 858 | pipe = to_intel_crtc(crtc)->pipe; |
| 859 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 860 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 861 | dev_priv->psr.busy_frontbuffer_bits |= frontbuffer_bits; |
Daniel Vetter | ec76d62 | 2015-06-18 10:30:26 +0200 | [diff] [blame] | 862 | |
| 863 | if (frontbuffer_bits) |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 864 | intel_psr_exit(dev_priv); |
Daniel Vetter | ec76d62 | 2015-06-18 10:30:26 +0200 | [diff] [blame] | 865 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 866 | mutex_unlock(&dev_priv->psr.lock); |
| 867 | } |
| 868 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 869 | /** |
| 870 | * intel_psr_flush - Flush PSR |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 871 | * @dev_priv: i915 device |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 872 | * @frontbuffer_bits: frontbuffer plane tracking bits |
Rodrigo Vivi | 169de13 | 2015-07-08 16:21:31 -0700 | [diff] [blame] | 873 | * @origin: which operation caused the flush |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 874 | * |
| 875 | * Since the hardware frontbuffer tracking has gaps we need to integrate |
| 876 | * with the software frontbuffer tracking. This function gets called every |
| 877 | * time frontbuffer rendering has completed and flushed out to memory. PSR |
| 878 | * can be enabled again if no other frontbuffer relevant to PSR is dirty. |
| 879 | * |
| 880 | * Dirty frontbuffers relevant to PSR are tracked in busy_frontbuffer_bits. |
| 881 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 882 | void intel_psr_flush(struct drm_i915_private *dev_priv, |
Rodrigo Vivi | 169de13 | 2015-07-08 16:21:31 -0700 | [diff] [blame] | 883 | unsigned frontbuffer_bits, enum fb_op_origin origin) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 884 | { |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 885 | struct drm_crtc *crtc; |
| 886 | enum pipe pipe; |
| 887 | |
Rodrigo Vivi | 0f328da | 2017-09-07 16:00:31 -0700 | [diff] [blame] | 888 | if (!HAS_PSR(dev_priv)) |
| 889 | return; |
| 890 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 891 | mutex_lock(&dev_priv->psr.lock); |
| 892 | if (!dev_priv->psr.enabled) { |
| 893 | mutex_unlock(&dev_priv->psr.lock); |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc; |
| 898 | pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | ec76d62 | 2015-06-18 10:30:26 +0200 | [diff] [blame] | 899 | |
| 900 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 901 | dev_priv->psr.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 902 | |
Rodrigo Vivi | 921ec28 | 2015-11-18 11:21:12 -0800 | [diff] [blame] | 903 | /* By definition flush = invalidate + flush */ |
| 904 | if (frontbuffer_bits) |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 905 | intel_psr_exit(dev_priv); |
Rodrigo Vivi | 995d304 | 2014-11-19 07:37:47 -0800 | [diff] [blame] | 906 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 907 | if (!dev_priv->psr.active && !dev_priv->psr.busy_frontbuffer_bits) |
Rodrigo Vivi | d0ac896 | 2015-11-11 11:37:07 -0800 | [diff] [blame] | 908 | if (!work_busy(&dev_priv->psr.work.work)) |
| 909 | schedule_delayed_work(&dev_priv->psr.work, |
Rodrigo Vivi | 20bb97f | 2015-11-11 11:37:08 -0800 | [diff] [blame] | 910 | msecs_to_jiffies(100)); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 911 | mutex_unlock(&dev_priv->psr.lock); |
| 912 | } |
| 913 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 914 | /** |
| 915 | * intel_psr_init - Init basic PSR work and mutex. |
Ander Conselvan de Oliveira | 93de056 | 2016-11-29 13:48:47 +0200 | [diff] [blame] | 916 | * @dev_priv: i915 device private |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 917 | * |
| 918 | * This function is called only once at driver load to initialize basic |
| 919 | * PSR stuff. |
| 920 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 921 | void intel_psr_init(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 922 | { |
Rodrigo Vivi | 0f328da | 2017-09-07 16:00:31 -0700 | [diff] [blame] | 923 | if (!HAS_PSR(dev_priv)) |
| 924 | return; |
| 925 | |
Ville Syrjälä | 443a389 | 2015-11-11 20:34:15 +0200 | [diff] [blame] | 926 | dev_priv->psr_mmio_base = IS_HASWELL(dev_priv) ? |
| 927 | HSW_EDP_PSR_BASE : BDW_EDP_PSR_BASE; |
| 928 | |
Paulo Zanoni | 2ee7dc4 | 2016-12-13 18:57:44 -0200 | [diff] [blame] | 929 | /* Per platform default: all disabled. */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 930 | if (i915_modparams.enable_psr == -1) |
| 931 | i915_modparams.enable_psr = 0; |
Rodrigo Vivi | d94d6e8 | 2016-02-12 04:08:11 -0800 | [diff] [blame] | 932 | |
Rodrigo Vivi | 65f61b4 | 2016-02-01 12:02:08 -0800 | [diff] [blame] | 933 | /* Set link_standby x link_off defaults */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 934 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 60e5ffe | 2016-02-01 12:02:07 -0800 | [diff] [blame] | 935 | /* HSW and BDW require workarounds that we don't implement. */ |
| 936 | dev_priv->psr.link_standby = false; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 937 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 60e5ffe | 2016-02-01 12:02:07 -0800 | [diff] [blame] | 938 | /* On VLV and CHV only standby mode is supported. */ |
| 939 | dev_priv->psr.link_standby = true; |
| 940 | else |
| 941 | /* For new platforms let's respect VBT back again */ |
| 942 | dev_priv->psr.link_standby = dev_priv->vbt.psr.full_link; |
| 943 | |
Rodrigo Vivi | 65f61b4 | 2016-02-01 12:02:08 -0800 | [diff] [blame] | 944 | /* Override link_standby x link_off defaults */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 945 | if (i915_modparams.enable_psr == 2 && !dev_priv->psr.link_standby) { |
Rodrigo Vivi | 65f61b4 | 2016-02-01 12:02:08 -0800 | [diff] [blame] | 946 | DRM_DEBUG_KMS("PSR: Forcing link standby\n"); |
| 947 | dev_priv->psr.link_standby = true; |
| 948 | } |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 949 | if (i915_modparams.enable_psr == 3 && dev_priv->psr.link_standby) { |
Rodrigo Vivi | 65f61b4 | 2016-02-01 12:02:08 -0800 | [diff] [blame] | 950 | DRM_DEBUG_KMS("PSR: Forcing main link off\n"); |
| 951 | dev_priv->psr.link_standby = false; |
| 952 | } |
| 953 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 954 | INIT_DELAYED_WORK(&dev_priv->psr.work, intel_psr_work); |
| 955 | mutex_init(&dev_priv->psr.lock); |
Rodrigo Vivi | 424644c | 2017-09-07 16:00:32 -0700 | [diff] [blame] | 956 | |
| 957 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Rodrigo Vivi | d0d5e0d | 2017-09-07 16:00:41 -0700 | [diff] [blame] | 958 | dev_priv->psr.enable_source = vlv_psr_enable_source; |
Rodrigo Vivi | 424644c | 2017-09-07 16:00:32 -0700 | [diff] [blame] | 959 | dev_priv->psr.disable_source = vlv_psr_disable; |
Rodrigo Vivi | 49ad316 | 2017-09-07 16:00:40 -0700 | [diff] [blame] | 960 | dev_priv->psr.enable_sink = vlv_psr_enable_sink; |
Rodrigo Vivi | e3702ac | 2017-09-07 16:00:34 -0700 | [diff] [blame] | 961 | dev_priv->psr.activate = vlv_psr_activate; |
Rodrigo Vivi | 2a5db87 | 2017-09-07 16:00:39 -0700 | [diff] [blame] | 962 | dev_priv->psr.setup_vsc = vlv_psr_setup_vsc; |
Rodrigo Vivi | 424644c | 2017-09-07 16:00:32 -0700 | [diff] [blame] | 963 | } else { |
Rodrigo Vivi | d0d5e0d | 2017-09-07 16:00:41 -0700 | [diff] [blame] | 964 | dev_priv->psr.enable_source = hsw_psr_enable_source; |
Rodrigo Vivi | 424644c | 2017-09-07 16:00:32 -0700 | [diff] [blame] | 965 | dev_priv->psr.disable_source = hsw_psr_disable; |
Rodrigo Vivi | 49ad316 | 2017-09-07 16:00:40 -0700 | [diff] [blame] | 966 | dev_priv->psr.enable_sink = hsw_psr_enable_sink; |
Rodrigo Vivi | e3702ac | 2017-09-07 16:00:34 -0700 | [diff] [blame] | 967 | dev_priv->psr.activate = hsw_psr_activate; |
Rodrigo Vivi | 2a5db87 | 2017-09-07 16:00:39 -0700 | [diff] [blame] | 968 | dev_priv->psr.setup_vsc = hsw_psr_setup_vsc; |
Rodrigo Vivi | 424644c | 2017-09-07 16:00:32 -0700 | [diff] [blame] | 969 | } |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 970 | } |