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